-
Notifications
You must be signed in to change notification settings - Fork 13
XQuery Samples
Daniel Aitken edited this page Jan 17, 2020
·
3 revisions
(: Add a MODS "accessCondition" node containing text :)
xquery version "3.0" encoding "UTF-8";
declare namespace mods="http://www.loc.gov/mods/v3";
copy $input := .
modify insert node <accessCondition>Rights Info</accessCondition> into $input/mods:mods
return $input
(: Add a 'foo' attribute (value 'bar' into MODS typeOfResource elements :)
xquery version "3.0" encoding "UTF-8";
declare namespace mods="http://www.loc.gov/mods/v3";
copy $input := .
modify insert node attribute foo {'bar'} into $input/mods:mods/mods:typeOfResource
return $input
(: Replace the contents of all MODS typeOfResource nodes with "New Type" :)
xquery version "3.0" encoding "UTF-8";
declare namespace mods="http://www.loc.gov/mods/v3";
copy $input := .
modify (
for $text in $input/mods:mods/mods:typeOfResource
return replace value of node $text with "New Type"
)
return $input
(: Replace the value of all @authority elements with "New Authority" :)
xquery version "3.0" encoding "UTF-8";
declare namespace mods="http://www.loc.gov/mods/v3";
copy $input := .
modify (
for $att in $input//@authority
return replace value of node $att with "New Authority"
)
return $input
(: Delete the first MODS typeOfResource node :)
xquery version "3.0" encoding "UTF-8";
declare namespace mods="http://www.loc.gov/mods/v3";
copy $input := .
modify delete node $input/mods:mods/mods:typeOfResource
return $input
(: Delete all @authority attributes :)
xquery version "3.0" encoding "UTF-8";
declare namespace mods="http://www.loc.gov/mods/v3";
copy $input := .
modify (
for $att in $input//@authority
return delete node $att
)
return $input
(: Delete all @authority nodes that have the value 'marcrelator' :)
xquery version "3.0" encoding "UTF-8";
declare namespace mods="http://www.loc.gov/mods/v3";
copy $input := .
modify (
for $att in $input//@authority
where $att="marcrelator"
return delete node $att
)
return $input
(: Concatenate the string literal '-SUFFIX' onto the end of all @authority attributes :)
xquery version "3.0" encoding "UTF-8";
declare namespace mods="http://www.loc.gov/mods/v3";
copy $input := .
modify (
for $att in $input//@authority
return replace value of node $att with concat($att, '-SUFFIX')
)
return $input
(: Concatenate the string literal '-SUFFIX' onto the end of all @authority attributes
that contain the string literal 'marc' :)
xquery version "3.0" encoding "UTF-8";
declare namespace mods="http://www.loc.gov/mods/v3";
copy $input := .
modify (
for $att in $input//@authority
where contains($att, 'marc')
return replace value of node $att with concat($att, '-SUFFIX')
)
return $input
(: Replace the first occurrence of the word "flavour" in the mods:abstract with its US
counterpart "flavor" :)
xquery version "3.0" encoding "UTF-8";
declare namespace mods="http://www.loc.gov/mods/v3";
copy $input := .
modify (
for $element in $input/mods:mods/mods:abstract
where contains($element, "flavour")
return replace value of node $element with concat(substring-before($element, "flavour"), "flavor", substring-after($element, "flavour"))
)
return $input
(: Ensure mods:subject/mods:topic nodes only use lower-case letters :)
xquery version "3.0" encoding "UTF-8";
declare namespace mods="http://www.loc.gov/mods/v3";
copy $input := .
modify (
for $element in $input/mods:mods/mods:subject/mods:topic
return replace value of node $element with translate($element, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')
)
return $input