Hi,
Let me show you a simple example that shows strange behaviour of parse-xml() function:
----------------------------------------------- declare function local:transform($nodes as node()*) as item()* { for $node in $nodes return typeswitch($node) case text() return parse-xml-fragment($node) case element(b) return element b {local:transform($node/node())} default return local:transform($node/node()) };
let $textdoc := <doc><a>content 1</a> <b><a>content 2</a></b> </doc>
let $doc := <doc>{ for $node in $textdoc/node() return local:transform($node) }</doc>
let $doc2 := <doc>{ for $node in $doc/node() return $node }</doc>
return $doc ----------------------------------------------------
After running it on baseX 7.6 the result is:
$doc = <doc> <a>content 1</a> <b> <a>content 2</a> </b> </doc>
but it differs from doc2:
$doc2 = <doc> <b> <a>content 2</a> </b> <a>content 1</a> </doc>
Why does using parse-xml() function change the order of the elements?
I ran this simple code on zorba and eXist (using util:parse() function) and $doc2 was the same as $doc.
Regards Bartosz Marciniak
Hi Bartosz,
thanks for the observation; I’ve added an entry to our bug tracker [1].
Best, Christian
[1] https://github.com/BaseXdb/basex/issues/661 ___________________________
On Thu, Mar 14, 2013 at 6:53 PM, Bartosz Marciniak marciniak.b@gmail.com wrote:
Hi,
Let me show you a simple example that shows strange behaviour of parse-xml() function:
declare function local:transform($nodes as node()*) as item()* { for $node in $nodes return typeswitch($node) case text() return parse-xml-fragment($node) case element(b) return element b {local:transform($node/node())} default return local:transform($node/node()) };
let $textdoc := <doc><a>content 1</a> <b><a>content 2</a></b>
</doc>
let $doc := <doc>{ for $node in $textdoc/node() return local:transform($node) }</doc>
let $doc2 := <doc>{ for $node in $doc/node() return $node }</doc>
return $doc
After running it on baseX 7.6 the result is:
$doc =
<doc> <a>content 1</a> <b> <a>content 2</a> </b> </doc>
but it differs from doc2:
$doc2 =
<doc> <b> <a>content 2</a> </b> <a>content 1</a> </doc>
Why does using parse-xml() function change the order of the elements?
I ran this simple code on zorba and eXist (using util:parse() function) and $doc2 was the same as $doc.
Regards Bartosz Marciniak _______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
basex-talk@mailman.uni-konstanz.de