aspose file tools*
The moose likes Product and Other Certifications and the fly likes Xpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "Xpath" Watch "Xpath" New topic
Author

Xpath

Rajan Thiyagarajan
Ranch Hand

Joined: Dec 12, 2002
Posts: 61
<AAA>
<BBB/>
<BBB/>
<BBB/>
<BBB/>
<BBB/>
<BBB/>
<BBB/>
<BBB/>
<CCC/>
<CCC/>
<CCC/>
</AAA>
The following XPath will select all middle BBB elements of the above tree structure.
//BBB[ position() = floor(last() div 2 + 0.5) or position() = ceiling(last() div 2 + 0.5) ]
Can somebody tell me how ?
Thanks
rajan


- IBM Certified - eBusiness Solution Technologist
- IBM Certified Developer - XML
- Microsoft Certified Application Developer
- Tibco Certified Professional
- Sun Certified Java Professional

Perseverance can make miracles happen
Micheal Jacob
Ranch Hand

Joined: Nov 25, 2002
Posts: 89
Hi Rajan,
Let see ur xml this way.

so the xpath is //BBB[ position() = floor(last() div 2 + 0.5)]
As it is // it will find all BBB tags.The filter checks whether the element position is matching the other side floor(last() div 2 + 0.5).
from this, last() give you 11,
last() div 2 give you 5.5
last() div 2 + 0.5 give you 6
so it will find the 6 BBB element.
Thats how it arrives at middle element.
Hope this helps you.
Micheal
Micheal Jacob
Ranch Hand

Joined: Nov 25, 2002
Posts: 89
Hi Rajan,
Please ignore the above mail,
Use same xml but the answer will be 4 th BBB tag.
Because inside // the context is changed
so last() gives you 8
last() div 2 gives you 4
last() div 2 + 0.5 gives you 4.5
floor(last()...) gives you 4
so it selects the BBB tag whose position is 4.
Micheal
Rajan Thiyagarajan
Ranch Hand

Joined: Dec 12, 2002
Posts: 61
Thanks Michael.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Xpath
 
Similar Threads
A doubt about Xpath expression
NMTOKENS ...
Difference between count() and last()
Table nested inside a div
Preceding siblings