select="state/@joined" : attribute « XPath « XML Tutorial






File: Data.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="Transform.xslt" type="text/xsl"?>
<member>
 <state joined="1995">Austria</state>
 <state joined="1950">Belgium</state>
 <state joined="1973">Denmark</state>
 <state joined="1995">Finland</state>
 <state joined="1950">France</state>

</member>


File: Transform.xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" />
  <xsl:template match="member">
    <xsl:text>Number of EU Member States: </xsl:text>
    <xsl:value-of select="count(state)" />
    <xsl:text>&#10;</xsl:text>
    <xsl:apply-templates select="state/@joined">
      <xsl:sort data-type="number" />
    </xsl:apply-templates>
    <xsl:text>&#10;</xsl:text>
  </xsl:template>

  <xsl:template match="state/@joined">
    <xsl:text> - </xsl:text>
    <xsl:apply-templates select=".." />
    <xsl:text> (</xsl:text>
    <xsl:value-of select="." />
    <xsl:text>)&#10;</xsl:text>
  </xsl:template>

</xsl:stylesheet>

Output:

Number of EU Member States: 5
 - Belgium (1950)
 - France (1950)
 - Denmark (1973)
 - Austria (1995)
 - Finland (1995)








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::*"