Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XSLT Developer's Guide

XSLT Transformation File (Transform.xsl)

When you finish the tutorial, Transform.xsl is as follows:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:param name="low_sales" select="21000"/>

<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="//summary/heading"/></title>
</head>
<body>
<xsl:variable name="ancillary" select="document('ancillary.xml')"/>
<div style="position:absolute;font-size:96;font-family:Times New Roman;
      color:#F0F0F0;z-index:-1">
   <xsl:value-of select="$ancillary//watermark"/>
</div>
<h1><xsl:value-of select="//summary/heading"/></h1>
<h2><xsl:value-of select="//summary/subhead"/></h2>
<p><xsl:value-of select="//summary/description"/></p>
<table>
<!-- create table heading row, filling in the 
             quarter numbers from left to right -->
<tr>
   <th>Region\Quarter</th>
   <xsl:for-each select="//data/region[1]/quarter">
      <th>Q<xsl:value-of select="@number"/></th>
   </xsl:for-each>
   <th>Total</th>
</tr>

<!-- create a table body row for each quarter, for each region,
                  filling cells with the number of books sold -->
<xsl:for-each select="//data/region">
<tr>
   <th style="text-align:left"><xsl:value-of select="name"/></th>

   <xsl:for-each select="quarter">
<td>
   <xsl:attribute name="style">
      <xsl:choose>
         <xsl:when test="number(@books_sold &lt;= $low_sales)">
               color:red;</xsl:when>
         <xsl:otherwise>color:green;</xsl:otherwise>
      </xsl:choose>
      text-align:right;
   </xsl:attribute>
   <xsl:value-of select="format-number(@books_sold,'###,###')"/>
</td>
   </xsl:for-each>

   <td style="text-align:right;font-weight:bold;">
      <xsl:value-of select="format-number(sum(quarter/@books_sold),'###,###')"/>
   </td>

</tr>
</xsl:for-each>

</table>
<div style="font-size:9">
   <xsl:value-of select="$ancillary//copyright"/>
</div>
</body>
</html>
</xsl:template>

</xsl:stylesheet>