Skip to Content
Real World XML
book

Real World XML

by Steven Holzner
January 2003
Beginner to intermediate content levelBeginner to intermediate
1200 pages
23h 42m
English
Peachpit Press
Content preview from Real World XML

Sorting Elements

You can use the <xsl:sort> element to sort node sets. You use this element inside <xsl:apply-templates> and then use its select attribute to specify what to sort on. For example, here's how I sort the planets based on density:

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

    <xsl:template match="PLANETS">
        <HTML>
            <HEAD>
                <TITLE>
                    Planets
                </TITLE>
            </HEAD>
            <BODY>
                <H1>Planets sorted by density</H1>
                <TABLE BORDER="1">
                    <TD>Planet</TD>
                    <TD>Mass</TD>
                    <TD>Day</TD>
                    <TD>Density</TD>
                    <xsl:apply-templates>
					<xsl:sort select="DENSITY"/>
					</xsl:apply-templates> </TABLE> </BODY> </HTML> </xsl:template> <xsl:template match="PLANET"> <TR> <TD><xsl:apply-templates select="NAME"/></TD> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Inside XML

Inside XML

Steven Holzner
XML Hacks

XML Hacks

Michael Fitzgerald

Publisher Resources

ISBN: 0735712867Purchase book