Skip to content
Daniel Aitken edited this page Jan 17, 2020 · 3 revisions

INSERT NODE

(: 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

INSERT ATTRIBUTE

(: 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 NODE TEXT

(: 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 ATTRIBUTE TEXT

(: 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 NODE

(: 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 ATTRIBUTE

(: 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

TEXT VALUE CONDITIONAL

(: 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

XQUERY FUNCTIONS - CONCAT

(: 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

XQUERY FUNCTIONS - CONTAINS

(: 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

XQUERY FUNCTIONS - SUBSTRINGS

(: 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

XQUERY FUNCTIONS - TRANSLATE

(: 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