XML Tutorials - Herong's Tutorial Examples - Version 5.05, by Dr. Herong Yang
"if" - The Conditional Element
This section describes the 'if' element, which is used in the content of a 'template' element. The 'if' element is a conditional statement that be used to put a block of output content under a logical condition.
if: A child element used as part of the content of a "template element. A "if" element serves as a conditional statement to do things conditionally. The syntax of the "if" element is:
<xsl:if test="condition"> content </xsl:if>
where the "condition" is an XPath expression to return Boolean value, and "content" is a mixture literal data and XSLT elements to be used only if the condition is true.
If the specified condition returns true, the specified content will be used. If the specified condition returns false, the specified content will be ignored.
Here are some examples of "if" elements:
<!-- for expired elements, output a message --> <xsl:if test="@status='expired'"> This <xsl:value-of select="name(.)"/> record has expired! </xsl:if> <!-- for active elements, apply transformations --> <xsl:if test="@status='active'"> <xsl:apply-templates/> </xsl:if>
Last update: 2014.
Table of Contents
Introduction of XML (eXtensible Markup Language)
DOM (Document Object Model) Programming Interface
SAX (Simple API for XML) Programming Interface
DTD (Document Type Definition) Introduction
Validating an XML Document against the Specified DTD Document Type
XSD (XML Schema Definition) Introduction
Validating XML Documents Against Specified XML Schemas
XSL (Extensible Stylesheet Language) Introduction
XSLT (XSL Transformations) Introduction
►XSLT Elements as Programming Statements
"value-of" - Evaluating XPath String Expressions
Examples of Using "value-of" Elements
"{expression}" - Shorthand of "value-of" Elements
"variable" - Declaring Variables
"for-each" - Looping through a Node Set
Examples of Using "for-each" Elements
►"if" - The Conditional Element
"choose" - The If...Else Element
Control and Generate XML Element in the Result
XML Tools Plugin for Notepad++