<?xl version="0.1" encoding="UTF-8" ?>


<Define> ^setup-metadata ()
<Arguments>
	^meta-data
</Arguments>
<Sequence> ()

<Define> ^bib ^'bib </Define>
<Define> ^md () </Define>
<Define> ^ns-env (NewEnvironment ()) </Define>

<For dec="meta-data">
	<Define> ^e (car meta-data) </Define>
	<Define> ^q (GE e 0) </Define>
	<Define> ^type (GE e 1) </Define>
	<Define> ^data (GE e 2) </Define>
	<Define> ^namespace
		<RegSwitch> ^q
		<Case rex=".+:">
			(CutString pattern 0 (- (StringLength pattern) 1))
		</Case>
		<Case rex=".">
			^""
		</Case>
		</RegSwitch>
	</Define>
	<If> (= (EA ns-env namespace 0) 0)
	<Then>
	(SetEA ns-env namespace 1)
	<Switch>
	<Case> (= namespace "gb")
		<set> ^bib
		(SetAttribute bib "xmlns:gb"
			"xlp://isjhp1.nichibun.ac.jp:8080/gb_metadata")
		</set>
	</Case>
	<Case> (= namespace "dc")
		<set> ^bib
		(SetAttribute bib "xmlns:dc"
			"http://purl.org/dec/elements/1.1/")
		</set>
	</Case>
	<Case> 1
		<set> ^bib
		(SetAttribute bib (+ "xmlns:" namespace) "unknown")
		</set>
	</Case>
	</Switch>
	</Then>
	</If>
	<set> ^q ([Cast type="symbol"] q) </set>
	<set> ^q (SetAttribute q "data" data) </set>
	<set> ^q (SetAttribute q "type" type) </set>
	<set> ^md (cons (List q) md) </set>
</For>

<Define> ^time <GetXLTime format="W3C-DTF"/> </Define>

<set> ^md (cons '<gb:issue.period type="W3C-DTF" data="$time"/>
		md) </set>
<set> ^md (cons '<gb:property type="gb-prop" data="base"/>
		md) </set>

<set> ^meta-data (cons bib md) </set>

^meta-data
</Sequence>
</Define>