In this concluding article, expand your XSLT vocabulary by exploring conditional constructs, loops, variables, and numbering, together with examples and illustrations of how these programming capabilities can substantially simplify your XSLT experience.
XSLT allows you to perform basic conditional tests within a template rule. The simplest form of conditional instruction is the instruction, which looks something like this
<xsl:if test="condition">
do this!
</xsl:if>
The "condition" here is a conditional expression, which evaluates to either true
or false. If the statement evaluates to true, the template is used; if not, it is ignored by the processor.
Here's a stylesheet to display these items as a list. Note how a conditional
test has been used to display an asterisk next to items with a high rating.
Here are a couple more examples of how this text can be used. The first template rule places the word "and" before printing the last item in the selected node collection, while the second displays a warning based on the value of a node.