Sorting Example

Figure 19. sort.xml

<doc>
<para>Here's a table of sales:</para>
<table>
<row><cell>3000</cell><cell>Widgets 'R' Us</cell></row>
<row><cell>2400</cell><cell>Widget Design and Implementation</cell></row>
<row><cell>10000</cell><cell>Widgets for Dummies</cell></row>
<row><cell>101</cell><cell>101 Uses for a Dead Widget</cell></row>
</table>
</doc>


Figure 20. sort.xsl

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

<xsl:import href="element.xsl"/>

<xsl:template match="table">
  <xsl:if test="@id"><a name="{@id}"/></xsl:if>
  <table>
    <xsl:apply-templates select="row">
      <xsl:sort data-type="number" select="./cell[1]"/>
    </xsl:apply-templates>
  </table>
</xsl:template>
</xsl:stylesheet>


Figure 21. sort.html

<p>Here's a table of sales:</p>
<table>
<tr>
<td>101</td><td>101 Uses for a Dead Widget</td>
</tr>
<tr>
<td>2400</td><td>Widget Design and Implementation</td>
</tr>
<tr>
<td>3000</td><td>Widgets 'R' Us</td>
</tr>
<tr>
<td>10000</td><td>Widgets for Dummies</td>
</tr>
</table>