Hi Jan,

Thanks for your feedback to the mailing list.

Your query will return the expected paths if you call BaseX as follows:

basex.bat -w -i datafile.xml queryfile.xq

A short explanation: By default, BaseX ignores whitespaces when
parsing XML documents. By specifying -w, whitespace chopping can be
suppresed [1,2]. If you want to permanently disable whitespace
chopping, you can achieve that by adding "CHOP=false" option in your
.basex configuration file [2]

A more comprehensive explanation (just ignore it if you are aware of
all the details): In your query, you are checking if the string value
of a parent element is identical to the string value of $rootElement.
The following comparison is equivalent to yours:

//Section[parent::*/data() != $rootElement/data()]

This is the reason why it matters if the whitespace-only nodes will be
parsed or not. – If your actual objective is to compare the XML
structure, you could the following:

//Section[not(deep-equal(parent::*, $rootElement))]

The following solution compares node identities:

//Section[not(parent::* is $rootElement)]

Hope this helps
Christian


[1] https://docs.basex.org/wiki/Command-Line_Options
[2] https://docs.basex.org/wiki/Configuration



> Using BaseX 9.5.1, cmd-line “basex.bat -i datafile.xml queryfile.xq” leads to 
> no result at all. I’m convinced there should be result equivalent to the one 
> of the online xquery tester (https://www.videlibri.de/cgi-bin/xidelcgi)
>
> For a modified query using string comparison based on fn:path(), BaseX gives 
> the expected result.
>
>
>
> %%% query begin %%%
>
> let $rootElement := /child::*
>
> for $x in //Section[parent::* != $rootElement]
>
> return fn:path($x)
>
> %%% query end %%%
>
>
>
> %%% data begin %%%
>
> <root>
>
>                 <Section id="should not be reported 1" />
>
>                 <Section id="should not be reported 2">
>
>                                 <Section id="should be reported 1"/>
>
>                                 <a>
>
>                                                 <Section id="should be 
> reported 2"/>
>
>                                 </a>
>
>                 </Section>
>
>                 <a>
>
>                                 <Section id="should be reported 3"/>
>
>                 </a>
>
> </root>
>
> %%% data end %%%
>
>
>
> %%% modified query begin %%%
>
> let $rootElementPath := fn:path(/child::*)
>
> for $x in //Section[fn:path(parent::*) != $rootElementPath]
>
> return fn:path($x)
>
> %%% query end %%%
>
>
>
> Kind regards
>
> Jan Červák

Reply via email to