To select an attribute using XPath, you prefix the attribute's name with a
Example of Selecting an Attribute
Consider the following XML document. Note that the
artist node now has an attribute called
If we wanted to select the
status attribute of the
artist node under the
rock node, we could use the following expression:
Attributes, just like any other node, can be the subject of a conditional statement.
For example, imagine we're using XSLT to transform our XML document, and we want to select all
artist nodes where the
status attribute is set to
active. We could use the XSL
if element to test the value.
Here's what we would write: