JasonBie

XPATH选取特征值的方法

XPath is one of the flexible standard for querying an xml document.

Let us consider the following CD xml as example:-

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd country="USA">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
</cd>
<cd country="UK">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<price>9.90</price>
</cd>
<cd country="USA">
<title>Greatest Hits</title> 
<artist>Dolly Parton</artist> 
<price>9.90</price> 
</cd>
<cd country="UK">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<price>9.90</price>
</cd>
</catalog>

In the above xml, if we would like to get distinct country names, then we can make use of the preceding-sibling property to check for any
existence of the country name so as to filter and show only distinct country names.

/catalog/cd[not(@country=preceding-sibling::cd/@country)]/@country

The above expression would select only distinct country names i.e. UK and USA only once each.

posted on 2012-03-12 15:23  JasonBie  阅读(225)  评论(0编辑  收藏  举报

导航