xsl:if instruction enables conditional processing : if « XSLT stylesheet « XML Tutorial






File: Data.xml
<?xml version="1.0" encoding="utf-8"?>
<list>
    <entry name="A"/>
    <entry name="B"/>
    <entry name="C"/>
    <entry name="D"/>
</list>
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:template match="list">
      <xsl:for-each select="entry">
        <xsl:value-of select="@name"/>
        <xsl:text>, </xsl:text>
      </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?>A, B, C, D,








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