O'Reilly logo

Real World XML by Steven Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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"/> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required