Example 4 of <xsl:if>

This example inserts the text "International Stock " when the <stock> element has an attribute named international.

XML File (stock.xml)

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="ifstock.xsl" ?>
   <stock international="yes">Microsoft</stock>
   <stock>Wingtip Toys</stock>
   <stock international="yes">Contoso Pharmaceuticals</stock>
   <stock>Contoso, Ltd</stock>
   <stock international="yes">Fabrikam, Inc.</stock>

XSLT File (ifstock.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:template match="/">

<xsl:template match="stock">
   <xsl:if test="@international">International Stock </xsl:if>
   <xsl:apply-templates />



This is the formatted output:

International Stock Microsoft

Wingtip Toys

International Stock Contoso Pharmaceuticals

Contoso, Ltd

International Stock Fabrikam, Inc.

The following is the processor utput, with line breaks added for clarity.


<p></p>International Stock Microsoft

<p></p>Wingtip Toys



</p>International Stock Fabrikam, Inc.


See Also


Example 1 of <xsl:if>
Example 2 of <xsl:if>
Example 3 of <xsl:if>