Totally new to xpath.
I have xml:
<Values>
<Value Value="a" CustomAtr="1" />
<Value Value="b" CustomAtr="2" />
<Value Value="c" CustomAtr="3" />
</Values>
To get value by index, i can use: string(/*/Value[1]/@CustomAtr)
Is it possible to get value by key?
Hot to get CustomAtr
value where Value="b"
?
Thank you
We can use XPath to generate attribute expressions to locate nodes in an XML document. When there are certain uniquely recognized attribute values accessible in the container tag, we employ the XPath functions (contains or starts-with) with the attribute. The “@” symbol is used to access attributes.
Using the XPath contains() function, we can extract all the elements on the page that match the provided text value. Here, tag: tag is the name of the tag that contains the specific word. word: In this case, the word refers to the text that must be discovered in a specific string.
XPath Tutorial from basic to advance level. This attribute can be easily retrieved and checked by using the @attribute-name of the element. @name − get the value of attribute "name". <td><xsl:value-of select = "@rollno"/></td> Attribute can be used to compared using operators.
this should do the trick:
string(//Value[@Value='b']/@CustomAttr)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With