Skip to content

Instantly share code, notes, and snippets.

@siahr
Created February 18, 2012 05:44
Show Gist options
  • Save siahr/1857665 to your computer and use it in GitHub Desktop.
Save siahr/1857665 to your computer and use it in GitHub Desktop.
Adds additional attribute to each element on BaseX. (use db:node-id() function)
declare function local:appendId($node as node()) {
typeswitch($node)
case $doc as document-node()
return document
{for $d in $doc/node() return local:appendId($d)}
default
return element
{node-name($node)}
{attribute node-id {db:node-id($node)}, $node/@*,
for $child in $node/node() return
if ($child instance of element())
then local:appendId($child)
else $child
}
};
local:appendId(fn:doc('bib'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment