Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
IMCreator - Free Website Builder

XPath Attributes

To select an attribute using XPath, you prefix the attribute's name with a @ symbol.

Example of Selecting an Attribute

Consider the following XML document. Note that the "artist" node now has an attribute called "status":

Code

If we wanted to select the "status" attribute of the "artist" node under the "rock" node, we could use the following expression:

Code

Another Example

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:

Code

Enjoy this page?

  1. Link to this page (copy/paste into your own website or blog):
  2. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!