Nested if statement : if « XSLT stylesheet « XML Tutorial






File: Data.xml
<?xml version="1.0"?>
<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"?>
<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="@year &lt; '1850'">
      The poem is old.
      <xsl:if test="@year &lt; '1700'">
        The poem is very old.
      </xsl:if>
      <xsl:if test="@year &lt; '1500'">
        The poem is very, very old.
      </xsl:if>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
Output:


      The poem is old.
      
        The poem is very old.








5.44.if
5.44.1.The Element: Conditional Processing
5.44.2.Use if statement to test if an element as an attribute
5.44.3.Check two attributes
5.44.4.Nested if statement
5.44.5.if test="not(preceding-sibling::address[zip=$lastZip])"
5.44.6.if test="(position() mod 2) = 1"
5.44.7.select with if them else statement
5.44.8.xsl:if instruction enables conditional processing
5.44.9.Use if statement to check whether it is the last