Using xsl:if

You can make choices based on the input document using the <xsl:if> element. To use this element, you simply set its test attribute to an expression that evaluates to a Boolean value.

Here's an example. In this case, I'll list the planets one after the other and add a HTML horizontal rule, <HR>, element after the last element—but only after the last element. I can do that with <xsl:if> like this:

Listing . ch13_25.xsl
 <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="PLANETS"> <HTML> <HEAD> <TITLE> Planets </TITLE> </HEAD> <BODY> <xsl:apply-templates select="PLANET"/> </BODY> </HTML> </xsl:template> <xsl:template match="PLANET"> <P> <xsl:value-of select="NAME"/> ...

Get Real World XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.