The xsl:if element tests whether a Boolean condition is true or false.
If it is true, then the content of the xsl:if element is instantiated.
If it is false, then nothing specified inside the xsl:ifelement is added to the result tree.
File: Data.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<sales>
<source>
<title>Book</title>
<url>http://www.java2java.com</url>
<amounts estimate="true" year="2002"/>
</source>
<nation>
<name>USA</name>
<capital>DC</capital>
<amount>32277942</amount>
<cc>dz</cc>
</nation>
<nation>
<name>Canada</name>
<capital>Ottwa</capital>
<amount>6373002</amount>
<cc>bi</cc>
</nation>
<nation>
<name>Maxico</name>
<capital>Maxico City</capital>
<amount>4465651</amount>
<cc>er</cc>
</nation>
</sales>
File: Transform.xslt
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="sales">
<xsl:apply-templates select="nation" />
</xsl:template>
<xsl:template match="nation">
<xsl:text> * </xsl:text>
<xsl:value-of select="name" />
<xsl:if test="amount > 10000000">
<xsl:text> (> 10M)</xsl:text>
</xsl:if>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
Output:
* USA (> 10M)
* Canada
* Maxico
|