Add a namespace node to an element in XQuery
David Carlisle just sent me the way to add a namespace node to an element in XQuery. Here is his example:
declare function local:add-ns-node( $elem as element(), $prefix as xs:string, $ns-uri as xs:string ) as element() { element { QName($ns-uri, concat($prefix, ":x")) }{ $elem }/* }; local:add-ns-node(<xxx><a/></xxx>, "p1", "uri2")
Run with Saxon 8.7.3 for Java, it results in:
<?xml version="1.0" encoding="UTF-8"?> <xxx xmlns:p1="uri2"> <a/> </xxx>
The context of the discussion can be found in this thread (you'll have to go deep in the thread to see the David's post).
Maybe a candidate to an XQuery FAQ? Anyway, thanks David.
Labels: xquery
0 Comments:
Post a Comment
<< Home