only for RuBoard |
xsl:if provides simple conditional evaluation.
Attribute Name | Enforced | Description | Values |
---|---|---|---|
test | Required | An expression that evaluates to a Boolean | Boolean expression |
Given the following XML instance document, links.xml :
<links> <link name="NewRiders.com" URL="http://www.newriders.com" /> <link name="Xmlandasp.net" URL="http://www.xmlandasp.net" /> <link name="MSDN Online Library" URL="http://msdn.microsoft.com/library" /> </links>
The following stylesheet displays all the elements in a table with every other row colored medium gray:
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <table> <xsl:for-each select="links/link"> <tr> <td> <xsl:if test="position() mod 2 = 0"> <xsl:attribute name="bgcolor">silver</xsl:attribute> </xsl:if> <xsl:value-of select="@name" /> </td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>
This results in the following markup:
<?xml version="1.0" encoding="UTF-16"?> <table> <tr> <td>NewRiders.com</td> </tr> <tr> <td bgcolor="silver">Xmlandasp.net</td> </tr> <tr> <td>MSDN Online Library</td> </tr> </table>
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:for-each, xsl:if, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements
xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements
only for RuBoard |