Check value of attribute : attribute « XPath « XML Tutorial






File: Data.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="Transform.xslt"?>
<advertisement action="create">
   asdf
</advertisement>

File: Transform.xslt
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="text" indent="no" />
  <xsl:variable select="advertisement/text" name="path" />

  <xsl:template match='/'>
    <xsl:apply-templates select="$path" />
  </xsl:template>

  <xsl:template match="text">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="headline">
    <xsl:text>\F4</xsl:text>
    <xsl:value-of select="text()" />
  </xsl:template>

  <xsl:template match="para">
    <xsl:if test="self::para[@fontsize='agate']">
      <xsl:text>&#13;\F1</xsl:text>
      <xsl:value-of select="text()" />
    </xsl:if>
    <xsl:if test="self::para[@justify='flushleft']">
      <xsl:text>&lt;</xsl:text>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>








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