Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: position() in XPath query

From: "Joe Fawcett" <joefawcett@---------.------>
To: NULL
Date: 10/2/2007 5:56:00 PM

"TarTar" <spam.spam@l...> wrote in message 
news:%238uJJxPBIHA.4836@T......
> Hi Dimitre,
>
> Thanks a lot! Now the code works like a charm.
>
> BTW
> Could you explain (or point to a resource) what's the differenece between 
> //name[position() > 10] and (//name)[position() > 10] ? The former one 
> (with brackets) works perfectly - but why?
>
> Leszek
>
The first retrieves name elements when they have a position() greater than 
ten within their siblings.
The second one retrieves all the name elements as one node-set and then 
filters them, removing the first ten.
An example:

<data>
<names>
<name att="1" block="1"/>
<name att="2" block="1"/>
<name att="3" block="1"/>
<name att="4" block="1"/>
<name att="5" block="1"/>
</names>
<names>
<name att="1" block="2"/>
<name att="2" block="2"/>
<name att="3" block="2"/>
<name att="4" block="2"/>
<name att="5" block="2"/>
</names>
<names>
<name att="1" block="3"/>
<name att="2" block="3"/>
<name att="3" block="3"/>
<name att="4" block="3"/>
<name att="5" block="3"/>
</names>
</data>

//name[position() > 3] gives:
<name att="4" block="1"/>
<name att="5" block="1"/>
<name att="4" block="2"/>
<name att="5" block="2"/>
<name att="4" block="3"/>
<name att="5" block="3"/>

(//name)[position() > 3] gives:
<name att="4" block="1"/>
<name att="5" block="1"/>
<name att="1" block="2"/>
<name att="2" block="2"/>
<name att="3" block="2"/>
<name att="4" block="2"/>
<name att="5" block="2"/>
<name att="1" block="3"/>
<name att="2" block="3"/>
<name att="3" block="3"/>
<name att="4" block="3"/>
<name att="5" block="3"/>

so if all the names are siblings anyway the two expressions give the same 
result.

-- 

Joe Fawcett (MVP - XML)

http://joe.fawcett.name




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent