Check attribute existance : 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. 5. Check attribute existance
File: Data.xml

<?xml version="1.0" standalone="yes"?>
<poem author="jm" year="1667">
  <verse>line 1</verse>
  <verse>line 2</verse>
  <verse>line 3</verse>
  <verse>line 4</verse>
</poem>

File: Transform.xslt

<?xml version="1.0" standalone="yes"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="text" />
  <xsl:template match="poem">
    <xsl:if test="@author='jm'">1. The poem's author is jm.</xsl:if>
  </xsl:template>
</xsl:stylesheet>

Output:

1. The poem's author is jm.
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.