5.7.4 XSL File to Use (SampleXSLT.xsl)

The following shows the XSL file read by the sample program.

<?xml version="1.0" encoding="Shift_JIS"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">
 <xsl:output method="html" indent="yes" encoding="Shift_JIS"/>

 <xsl:template match="/">
   <xsl:apply-templates />
 </xsl:template>

 <!-- start conversion for START as a root -->
 <xsl:template match="START">
   <HTML>
     <HEAD>
       <TITLE>Display XML at a table of HTML</TITLE>
     </HEAD>
     <BODY BGCOLOR="#C0C0C0">
     <FONT SIZE="5">Ordering Payment Slip</FONT>
     <TABLE BORDER="2">
     <TR><TH>Brand_Name</TH><TH>Unit_Price</TH>
         <TH>Amount</TH><TH>Subtotal</TH></TR>
     <xsl:apply-templates />
     <TR><TH>Total</TH><TD>&#160;</TD><TD>&#160;</TD>
     <TD ALIGN="RIGHT"><xsl:value-of
         select="(//Merchandise[1]/Unit_Price * //Merchandise[1]/Amount +
                  //Merchandise[2]/Unit_Price * //Merchandise[2]/Amount +
                  //Merchandise[3]/Unit_Price * //Merchandise[3]/Amount)" /></TD></TR>
     </TABLE>
     </BODY>
   </HTML>
 </xsl:template>

 <xsl:template match="Payment_Slip">
   <xsl:apply-templates />
 </xsl:template>

 <!-- make one line with one merchandise, and output a subtotal -->
 <xsl:template match="Merchandise">
   <TR><xsl:apply-templates />
   <TD ALIGN="RIGHT">
       <xsl:value-of select="number(Unit_Price)*number(Amount)" />
   </TD></TR>
 </xsl:template>

 <!-- output a brand name -->
 <xsl:template match="Brand_Name">
   <TD><xsl:value-of select="."/></TD>
 </xsl:template>

 <!-- output unit price -->
 <xsl:template match="Unit_Price">
   <TD ALIGN="RIGHT"><xsl:value-of select="."/></TD>
 </xsl:template>

 <!-- output amount -->
 <xsl:template match="Amount">
   <TD ALIGN="RIGHT"><xsl:value-of select="."/></TD>
 </xsl:template>
</xsl:stylesheet>