Latest web development tutorials

XSLT <xsl: if> element

<Xsl: if> element is used to place a conditional test against the XML file content.

<Xsl: if> element

To place the conditions for testing the contents of the XML file, add the XSL document <xsl: if> element.


<xsl:if test="expression">

Place where <xsl: if> element

To add conditional tests in the XSL file <xsl: for-each> element is added inside <xsl: if> element:


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"

<xsl:template match="/">
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<xsl:for-each select="catalog/cd">
<xsl:if test="price &gt; 10">
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>


try it"

Note: The value of the testattribute contains the essential need to be evaluated expression.

The above code will only output prices higher than the CD title and artist elements 10.