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

XML Tutorial
1. Introduction
2. Namespace
3. XML Schema
4. XPath
5. XSLT stylesheet
Java
XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
XML Tutorial » XPath » attribute 
4. 6. 2. Attributes can be accessed in similar way as elements
"@" 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. 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::*"
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.