-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfots-copy.xqm
34 lines (33 loc) · 998 Bytes
/
fots-copy.xqm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(:~
: A copy function as demanded by the QT3 test suite.
:
: @author BaseX Team 2005-11, BSD License
: @author Leo Wörteler
: @version 0.1
:)
module namespace fots = "http://www.w3.org/2010/09/qt-fots-catalog";
(:~
: Creates a copy of the given XML node.
: @param $nd node to be copied
: @return copy of <code>$nd</code>
:)
declare function fots:copy(
$nd as node()
) as node() {
typeswitch($nd)
case document-node()
return document { map(fots:copy#1, $nd/(* | text())) }
case element()
return element { node-name($nd) }
{ map(fots:copy#1, $nd/(@* | * | text())) }
case attribute()
return attribute { node-name($nd) } { $nd/data() }
case processing-instruction()
return processing-instruction { node-name($nd) } { $nd/data() }
case comment()
return comment { $nd/data() }
case text()
return text { $nd/data() }
default return error(xs:QName('fots:FOTS9999'),
concat('Unknown node: ', serialize($nd)))
};