Created
December 15, 2018 18:09
-
-
Save fgeorges/26288f7620d3340ea51b6989dd7bd046 to your computer and use it in GitHub Desktop.
XQuery recursive descent copy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(:~ | |
: Template for the recursive descent copy. | |
: | |
: This function does not actually modify anything as such. Modify it as needed, | |
: this version does by default, for each node, a recursive exact same copy. | |
: | |
: Note that in addition to typeswitch cases, you can also have regular if/else | |
: statements, for more complex conditions, but conditions that can be expressed | |
: as typeswitch cases will be more efficient. | |
:) | |
declare function local:modify($node as node()) | |
{ | |
typeswitch($node) | |
(: recursively copy documents and elements :) | |
case document-node() return | |
document { | |
$node/node() => local:modify() | |
} | |
case element() return | |
element { fn:node-name($node) } { | |
$node/(@*|node()) => local:modify() | |
} | |
(: copy attributes, text nodes, comments and PIs :) | |
case attribute() return | |
$node | |
case text() return | |
$node | |
case comment() return | |
$node | |
case processing-instruction() return | |
$node | |
(: in MarkLogic, you can have other node types, like binary() and object() :) | |
default return | |
fn:error((), 'Unexpected node type') | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment