It's been about six months since I shared some XQuery code. Most of the code I write is used to search and manipulate metadata for our digital collections. I have a lot stockpiled, so the next few posts will be some XQuery examples.
This query was write to modify METS documents for a digital archival collection. We wanted a user interface feature that would allow the user to both show or hide blank pages for each individual archival item. Those who wanted the "feel" of the orginal artifact could see the blank pages. And those just interested in the content could hide them.
We identified the blank pages, so I had the blank page file names to work with. I wanted to add a TYPE attribute in the METS structMap div elements for all the blank pages: TYPE="blank-page".
This query was the solution. I worked my way from the fileSec to the structMap matching on identifiers until I got to the correct div element that needed the added blank page attribute. The MarkLogic function xdmp:node-insert child() was used to add the attributes to the correct div element.
xquery version "1.0-ml"; (: 9/16/11 Query for adding blank page attributes to structMap of METS documents using a sequence
of file names from blank page reports :)
declare namespace mets = "http://www.loc.gov/METS/"; declare namespace xlink = "http://www.w3.org/1999/xlink"; let $doc := fn:doc("/METS/Kuyper239-241.xml") let $file-names := ("/240-0001t", "/240-0002t", "/240-0004t", "/240-0006t", "/240-0008t") let $images := for $file-name in $file-names return fn:concat("Manuscripts/thumb/Kuyper/239-241", $file-name, ".jpg") for $image in $images for $file-location in $doc/mets:mets//mets:FLocat where $image = $file-location/@xlink:href return for $id in $file-location/parent::mets:file/@ID for $file-id in $doc/mets:mets/mets:structMap/mets:div/mets:div/mets:div/mets:fptr where $id = $file-id/@FILEID return xdmp:node-insert-child($file-id/parent::mets:div, attribute TYPE { "blank-page" })
Comments
You can follow this conversation by subscribing to the comment feed for this post.