How to use conditional statements in XSL

XSL provides support for conditional patterns, statements and values – much the same as any other programming language. The appropriate application of the available XSL functions allows you to implement each pattern.

<xsl:otherwise>

The XSLT <xsl:otherwise> element provides a default value/evaluation within the scope an <xsl:choose> conditional evaluation.

<xsl:when>

The XSLT <xsl:when> element provides a conditional test to use against the contents of an XML file within the scope a larger <xsl:choose> conditional evaluation.

<xsl:choose>

The XSLT <xsl:choose> element provides a complex conditional test to use against the contents of an XML file.

<xsl:if>

The XSLT <xsl:if> element provides a simple conditional test to use against the contents of an XML file.

<xsl:copy-of>

The XSLT <xsl:copy-of> element makes a deep copy of an XML node as defined by an expression in the select attribute.

<xsl:for-each>

The XSLT <xsl:for-each> element is used to iterate over XML nodes as defined by an expression in the select attribute.

<xsl:sort>

The XSLT <xsl:sort> element is used to apply an ordering on the results selected by a <xsl:for-each> element.

<xsl:value-of>

The XSLT <xsl:value-of> element is used to extract a value from an expression defined in the select attribute.

How to output CDATA with XSL

A CDATA element can be used to present formatted data or an XML document on its own.  The problem is that the XSLT processor will normally strip any leading and trailing whitespace, as well as carriage returns from an output XML document – unless instructed otherwise…