XSLT <xsl:if>Element
The <xsl:if> element is used to perform conditional checks on XML data. It outputs the corresponding content only when the specified condition is true.
<xsl:if> Element
In XSLT, if you need to decide whether to output a piece of content based on the value or state of an XML node, you can use the <xsl:if> element for conditional control.
Syntax
... content to be executed when the condition is true ...
</xsl:if>
Explanation:The test attribute is used to specify the condition expression (an XPath expression). When the expression evaluates to true, the inner content is processed and output.
Where to Place the <xsl:if> Element
Typically, <xsl:if> is used together with loop statements, for example, to filter each node inside <xsl:for-each>:
Example
Try it Yourself »
Note:The test attribute is required. Its value is an XPath expression, such as comparison operations (> , <, =) or logical judgments.
Explanation:In the above example, only when price is greater than 10 will the corresponding CD be output to the table.
Other Extensions