Reputation: 6265
Consider the following XML
<account>
<discussionPoints>
<education category="a" value="1"/>
<education category="b" value="42"/>
<education category="c" value="55"/>
</discussionPoints>
</account>
I'm trying to get the value of the value of the education where the category is "a". The particular education may or may not exist. The discussionPoints collection will always exist, though it could be empty. I'm new to XSLT and am needing some direction.
EDIT Fixed incorrect closing tag
Upvotes: 0
Views: 76
Reputation: 18563
Use the following XPath expression:
/account/discussionPoints/education[@category='a']/@value
It follows the child axis three times to match an education
element. Then it checks the attribute axis for category
without following it (as stated in the predicate) and then, provided that the value of category
is 'a'
, it follows the attribute axis again to fetch the value of value
attribute.
Upvotes: 2