Attributes can be accessed in similar way as elements : attribute « XPath « XML Tutorial






"@" is in the front of attribute names.
"@name" matches name attribute of an element.
"data/@color" matches color attribute of data element.


File: Data.xml
<?xml version="1.0"?>
<dog name="Joe">
  <data weight="18 kg" color="black"/>
</dog>

File: Transform.xslt

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="dog">
      <paragraph>
        <b>
          <xsl:text>Dog: </xsl:text>
        </b>
        <xsl:value-of select="@name"/>
      </paragraph>
      <paragraph>
        <b>
          <xsl:text>Color: </xsl:text>
        </b>
        <xsl:value-of select="data/@color"/>
      </paragraph>
    </xsl:template>

</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?><paragraph><b>Dog: </b>Joe</paragraph><paragraph><b>Color: </b>black</paragraph>








4.6.attribute
4.6.1.What is Attribute Axis
4.6.2.Attributes can be accessed in similar way as elements
4.6.3.select="state/@joined"
4.6.4.If the element has an attribute
4.6.5.Check attribute existance
4.6.6.Check value of attribute
4.6.7.Attributes can be processed in the same way as elements
4.6.8.Select elements, which contain or do not contain the given attribute
4.6.9.includes or excludes elements if the specified attribute is present
4.6.10.for-each select="attribute::*"