Back
Next
XSLT Conditions provide us to control our work flow. Suppose in an
organization number of employees are working and every one knows each other by face or name
either employee is he or she. It mean to say that somebody we have to call
as Mr. or Miss in case of gender. Every programming language have
functionality to control flow with if else statement; So here in XSLT we
also have a structure to follow for the defining the Conditions in XSLT.
Here we can get into with real example.
Example of XSLT Conditions
XML Code for XSLT Conditions Example [XSLT_Conditions_Example.xml]
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="xslt_Sorting_Example.xsl"?>
<globalGuideLine>
<employee>
<FirstName>Jamima</FirstName>
<LastName>Elisibith</LastName>
<gender>f</gender>
</employee>
<employee>
<FirstName>Alfa</FirstName>
<LastName>Cute</LastName>
<gender>m</gender>
</employee>
<employee>
<FirstName>Kethrin</FirstName>
<LastName>Bruster</LastName>
<gender>f</gender>
</employee>
</globalGuideLine>
XSLT for XSLT Conditions Example [xslt_Conditions_Example.xsl]
<?xml version="1.0" encoding="ISO-8859-1"?>
<html xsl:version="1.0" xmlns:xsl="https://www.w3.org/1999/XSL/Transform"
xmlns="https://www.w3.org/1999/xhtml">
<body style="font-family:Arial,helvetica,sans-serif;font-size:12pt;
background-color:#EEEEEE">
<xsl:for-each select="globalGuideLine/employee">
<xsl:sort select="FirstName"/>
<div style="background-color: #cccccc;color:000000;padding:0px">
<span style="font-weight:bold;color:#000000">
<xsl:value-of select="FirstName"/> <xsl:value-of select="LastName"/></span>
</div>
<div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
<span style="font-style:none">
<xsl:if test="gender='m'">
<font color="red"><b>Mr. </b></font>
<xsl:value-of select="FirstName"/>
is working at Global Guide Line
</xsl:if>
<xsl:if test="gender='f'">
<font color="red"><b>Miss </b></font>
<xsl:value-of select="FirstName"/>
is working at Global Guide Line
</xsl:if>
</span>
</div>
</xsl:for-each>
</body>
</html>
Complete Example of XSLT Conditions
XSLT Tutorial sources of XSLT Condition, view it by simply clicking on file name of XSLT, XML
and Out Put of XSLT Conditions Example
Back
Next
|