Here's the first post in what I hope will be an occasional series on using XQuery code with library metadata.
I wrote this query to create controlaccess elements for EAD documents. It takes the value of persname element and creates a new node, the controlaccess element for each of our 227 EAD documents. Using a MarkLogic update function, xdmp: node-insert-after, it also inserts the new controlacess nodes after each first did element.
NOTE: For unprefixed names (our EAD documents have unprefixed names) I needed to declare default element namespace, otherwise new elements will go into no namespace. This is what happpened when I first tested the controlaccess elements.
The next step will be editing by hand the altrender attribute putting the names in direct order and removing dates and parenthetical qualifiers. We'll be using this value for display purposes.
xquery version "1.0-ml";
declare default element namespace "urn:isbn:1-931666-22-9";
let $docs := xdmp:directory("/EAD/")
let $newNodes := for $doc in $docs
let $name := fn:string($doc/ead/archdesc/did/
origination/persname)
order by $name ascending
return <controlaccess>
<persname encodinganalog="100" role="creator"
source="lcnaf" altrender="{$name}">{$name}</persname>
</controlaccess>
let $topNodes := for $doc in $docs
let $sibling := ($doc/ead/archdesc/did)[1]
order by fn:string($doc/ead/archdesc/did/origination/
persname) ascending
return $sibling
return for $topNode at $x in $topNodes
return xdmp:node-insert-after($topNode, $newNodes[$x])
Comments