Explain how the following-sibling :: A / B axis works with arguments.
1 answer
Actually, there are no arguments for the "axes". Let there be such xml:
<bookstore> <book> <title lang="eng">Harry Potter</title> <price>29.99</price> <author>JK Rowling</author> </book> <book> <title lang="eng">Learning XML</title> <price>39.95</price> <author>Erik T. Ray</author> </book> </bookstore>
First we find some element, for example, the name "Learning XML":
//title[.="Learning XML"]
and now we want to know the price of this book. Price is an element of the following (following-sibling), it will turn out like this:
//title[.="Learning XML"]/following-sibling::price
or directly price:
//title[.="Learning XML"]/following-sibling::price/text()
or author:
//title[.="Learning XML"]/following-sibling::author/text()
Other axes work similarly, for example, the name of previous (if there are several) books:
//title[.="Learning XML"]/ancestor::book/preceding-sibling::book/title/text()
Found a certain title, climbed to the level of books, got all the previous books, learned from them the title.
Or the price of the previous (one) book:
//title[.="Learning XML"]/ancestor::book/preceding-sibling::book[1]/price/text()
- Thanks for the links and info. PS I wonder why they were called the Axis - voipp
- Well, you can explain it like this: the default axis is children, i.e. every step goes inside the tree. and another movement along the tree - not deep down - goes along other axes ... It is not necessary to reward it, if the answer suits you completely enough to be accepted. Optionally, you can add a thumbs up. your karma is not spent. - Yura Ivanov
|