problem with parse-xml function

Thursday, 14 March 2013 · 2 messages · last reply 18 Mar 2013
BM
Bartosz Marciniak14 Mar 2013 18:53 #
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>&lt;a&gt;content 1&lt;/a&gt;
  <b>&lt;a&gt;content 2&lt;/a&gt;</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
CG
Christian Grün18 Mar 2013 15:17 #
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
Quoted text · Bartosz Marciniak · 70 lines
On Thu, Mar 14, 2013 at 6:53 PM, Bartosz Marciniak <marciniak.b at 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>&lt;a&gt;content 1&lt;/a&gt; > <b>&lt;a&gt;content 2&lt;/a&gt;</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 at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk

⚡Generated with XQuery