problems with fn:root function and comparision

Friday, 19 March 2010 · 4 messages · last reply 22 Mar 2010
JK
Jiří Kadlec19 Mar 2010 17:12 #
Hi guys, I'm having a trouble with using fn:root function. I want to check if given XPath selects root node. So i decided to do it with following for eg. /test/nodes - is example XPath chosing non root element and i want to check if this is root element byt running one of these statements
fn:root(/test/nodes) = /test/nodes or fn:root() = /test/nodes
both of these return true on following document:
<?xml version='1.0' encoding='UTF-8'?>
<test>
    <nodes>
        <node></node>
    </nodes>
    <nodes2>
    </nodes2>
</test>

when I run just first part of statement fn:root(/test/nodes)   I get:
<test>
  <nodes>
    <node/>
  </nodes>
  <nodes2/>
</test>
which is ok when I run separately /test/nodes i got this:
<nodes>
  <node/>
</nodes>
it's also ok but when I try to compare it together I get false which is definitelly not OK. i.e fn:root(/test/nodes) = /test/nodes .... returns true Am I doing something wrong or it's a bug in base-X. I have tried also last BASE-X 6.03 and I'm having same problem. Thank you for help Jiri
CG
Christian Grün19 Mar 2010 18:44 #
Hi Jiří, "=" is a »general comparison« operator, which compares the atomized values of your left and right operands. So-called »node comparison« operators will give you the expected result:
  fn:root(/test/nodes) is /test/nodes
More details in the specs: http://www.w3.org/TR/xquery/#id-node-comparisons Christian
Quoted text · Jiří Kadlec · 41 lines
On Fri, Mar 19, 2010 at 5:12 PM, Jiří Kadlec <jir.kadlec at post.cz> wrote: > Hi guys, > > I'm having a trouble with using fn:root function. I want to check if given XPath selects root node. So i decided to do it with following > > for eg. /test/nodes - is example XPath chosing non root element and i want to check if this is root element byt running one of these statements > > fn:root(/test/nodes) = /test/nodes or fn:root() = /test/nodes > > both of these return true on following document: > > <?xml version='1.0' encoding='UTF-8'?> > <test> > <nodes> > <node></node> > </nodes> > <nodes2> > </nodes2> > </test> > > when I run just first part of statement fn:root(/test/nodes) I get: > <test> > <nodes> > <node/> > </nodes> > <nodes2/> > </test> > > which is ok when I run separately /test/nodes i got this: > <nodes> > <node/> > </nodes> > > it's also ok but when I try to compare it together I get false which is definitelly not OK. > i.e fn:root(/test/nodes) = /test/nodes .... returns true > > Am I doing something wrong or it's a bug in base-X. I have tried also last BASE-X 6.03 and I'm having same problem. > > Thank you for help > > Jiri
___________________________ Christian Gruen Universitaet Konstanz Department of Computer & Information Science D-78457 Konstanz, Germany Tel: +49 (0)7531/88-4449, Fax: +49 (0)7531/88-3577 http://www.inf.uni-konstanz.de/~gruen
JK
Jiří Kadlec22 Mar 2010 08:36 #
Hi Christian, thanks for your help. I tried using is operator instead of = and now I got expected result, but I got error with comparsion where true should be returned. i.e when I call fn:root(/test) is /test which should return true, but it returns false. I'm using same simple XML.
<?xml version='1.0' encoding='UTF-8'?>
 <test>
    <nodes>
        <node></node>
    </nodes>
    <nodes2>
    </nodes2>
</test>
Is there something above /test some "super root"? I have checked what returns each command and the result is the same. for both, but when I check tree map window in base-x gui I found out that fn:root(/test) select my.xml and /test select test node directly. Is this a right behaviour? Thanks again for quick and helpful responses Jiri
Quoted text · Christian Grün · 71 lines
> Hi Jiří, > > "=" is a »general comparison« operator, which compares the atomized > values of your left and right operands. So-called »node comparison« > operators will give you the expected result: > > fn:root(/test/nodes) is /test/nodes > > More details in the specs: http://www.w3.org/TR/xquery/#id-node-comparisons > > Christian > > > On Fri, Mar 19, 2010 at 5:12 PM, Jiří Kadlec <jir.kadlec at post.cz> wrote: > > Hi guys, > > > > I'm having a trouble with using fn:root function. I want to check if given > XPath selects root node. So i decided to do it with following > > > > for eg. /test/nodes - is example XPath chosing non root element and i want to > check if this is root element byt running one of these statements > > > > fn:root(/test/nodes) = /test/nodes or fn:root() = /test/nodes > > > > both of these return true on following document: > > > > <?xml version='1.0' encoding='UTF-8'?> > > <test> > > <nodes> > > <node></node> > > </nodes> > > <nodes2> > > </nodes2> > > </test> > > > > when I run just first part of statement fn:root(/test/nodes) I get: > > <test> > > <nodes> > > <node/> > > </nodes> > > <nodes2/> > > </test> > > > > which is ok when I run separately /test/nodes i got this: > > <nodes> > > <node/> > > </nodes> > > > > it's also ok but when I try to compare it together I get false which is > definitelly not OK. > > i.e fn:root(/test/nodes) = /test/nodes .... returns true > > > > Am I doing something wrong or it's a bug in base-X. I have tried also last > BASE-X 6.03 and I'm having same problem. > > > > Thank you for help > > > > Jiri > > ___________________________ > > Christian Gruen > Universitaet Konstanz > Department of Computer & Information Science > D-78457 Konstanz, Germany > Tel: +49 (0)7531/88-4449, Fax: +49 (0)7531/88-3577 > http://www.inf.uni-konstanz.de/~gruen > > > >
CG
Christian Grün22 Mar 2010 13:19 #
Hi Jiří,
Quoted text · Jiří Kadlec · 1 line
> i.e when I call fn:root(/test) is /test which should return true, but it returns false. I'm using same simple XML.
The query result is correct, as each XML document has a document node on top… [1] fn:root(/test) is /test → false [3] fn:root(/test) is / → true [2] fn:root(doc('test.xml')/test) is doc('test.xml') → true Hope this helps; feel free to ask for more, Christian
Quoted text · Jiří Kadlec · 90 lines
> > <?xml version='1.0' encoding='UTF-8'?> > <test> > <nodes> > <node></node> > </nodes> > <nodes2> > </nodes2> > </test> > > Is there something above /test some "super root"? I have checked what returns each command and the result is the same. for both, but when I check tree map window in base-x gui I found out that fn:root(/test) select my.xml and /test select test node directly. Is this a right behaviour? > > Thanks again for quick and helpful responses > > Jiri > > > >> Hi Jiří, >> >> "=" is a »general comparison« operator, which compares the atomized >> values of your left and right operands. So-called »node comparison« >> operators will give you the expected result: >> >> fn:root(/test/nodes) is /test/nodes >> >> More details in the specs: http://www.w3.org/TR/xquery/#id-node-comparisons >> >> Christian >> >> >> On Fri, Mar 19, 2010 at 5:12 PM, Jiří Kadlec <jir.kadlec at post.cz> wrote: >> > Hi guys, >> > >> > I'm having a trouble with using fn:root function. I want to check if given >> XPath selects root node. So i decided to do it with following >> > >> > for eg. /test/nodes - is example XPath chosing non root element and i want to >> check if this is root element byt running one of these statements >> > >> > fn:root(/test/nodes) = /test/nodes or fn:root() = /test/nodes >> > >> > both of these return true on following document: >> > >> > <?xml version='1.0' encoding='UTF-8'?> >> > <test> >> > <nodes> >> > <node></node> >> > </nodes> >> > <nodes2> >> > </nodes2> >> > </test> >> > >> > when I run just first part of statement fn:root(/test/nodes) I get: >> > <test> >> > <nodes> >> > <node/> >> > </nodes> >> > <nodes2/> >> > </test> >> > >> > which is ok when I run separately /test/nodes i got this: >> > <nodes> >> > <node/> >> > </nodes> >> > >> > it's also ok but when I try to compare it together I get false which is >> definitelly not OK. >> > i.e fn:root(/test/nodes) = /test/nodes .... returns true >> > >> > Am I doing something wrong or it's a bug in base-X. I have tried also last >> BASE-X 6.03 and I'm having same problem. >> > >> > Thank you for help >> > >> > Jiri >> >> ___________________________ >> >> Christian Gruen >> Universitaet Konstanz >> Department of Computer & Information Science >> D-78457 Konstanz, Germany >> Tel: +49 (0)7531/88-4449, Fax: +49 (0)7531/88-3577 >> http://www.inf.uni-konstanz.de/~gruen >> >> >> >> >

⚡Generated with XQuery