Sorting |
The <xsl:sort> element sorts a set of nodes according to the criteria specified:
<xsl:apply-templates select="row"> <xsl:sort data-type="number" select="entry[2]"/> </xsl:apply-templates>It can appear as a child of <xsl:apply-templates> or <xsl:for-each>. It can also be nested.
Example 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>
Example 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>
Example 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>
XSL = XSLT + vocabulary of FOs and properties
XSL defines a powerful set of formatting objects
XSL uses (and extends) a set of Common Formatting Properties developed jointly with the CSS&FP (Cascading Style Sheet and Formatting Property) Working Group
When a result tree uses this standardized set of formatting objects and properties, then an XSL-compliant formatter can process that result tree to produce the specified output
<xsl:template match="chapter"> <fo:flow> <xsl:apply-templates/> </fo:flow> </xsl:template> <xsl:template match="chapter/title"> <fo:block font-size="18pt" font-weight="bold" text-align="centered"> <xsl:apply-templates/> </fo:block> </xsl:template> <xsl:template match="para"> <fo:block font-size="12pt" space-before="1pc" text-align="justified"> <xsl:apply-templates/> </fo:block> </xsl:template> <xsl:template match="emphasis"> <fo:inline font-style="italic"> <xsl:apply-templates/> </fo:inline> </xsl:template>
page-sequence--a major part (such as front or body) in which the basic page layout may differ from other parts
flow--a chapter- or section-like division within a page-sequence
block--a paragraph (or title or block quote, etc.)
inline--e.g., a font change within a paragraph
wrapper--a "transparent" object usable as either a block or inline object that has no effect other than to provide a place to hang inheritable properties
list FOs--list-block, list-item, list-item-label, list-item-body
graphic--references an external graphic object
table FOs--mostly analogous to the standard (CALS, OASIS, HTML) table models