Whats the deal with that syntax?

page 109 Its less efficient, but if it makes you feel better about the syntax, you could write the stylesheet like this: xsl:template match= xsl:for-each select=addressbookaddress xsl:sort select=namelast-name xsl:sort select=namefirst-name xsl:for-each select=. -- This is slower, but it works -- xsl:apply-templates select=. xsl:for-each xsl:for-each xsl:template Dont actually do this. Im only trying to make a point. This stylesheet generates the same results as our earlier stylesheet.

6.1.2.2 Attributes

The xsl:sort element has several attributes, all of which are discussed here. select The select attribute defines the characteristic well use for sorting. Its contents are an XPath expression, so you can select elements, text, attributes, comments, ancestors, etc. As always, the XPath expression defined in select is evaluated in terms of the current context. data-type The data-type attribute can have three values: • data-type=text • data-type=number • A data-type=QName that identifies a particular datatype. The stated goal of the XSLT working group is that the datatypes defined in the XML Schema specification will eventually be supported here. The XSLT specification defines the behavior for data-type=text and data- type=number . Consider this XML document: ?xml version=1.0? numberlist number127number number23number number10number numberlist Well sort these values using the default value data-type=text : ?xml version=1.0? xsl:stylesheet version=1.0 xmlns:xsl=http:www.w3.org1999XSLTransform xsl:output method=text indent=no xsl:strip-space elements= xsl:variable name=newline xsl:text xsl:text xsl:variable xsl:template match= xsl:for-each select=numberlistnumber xsl:sort select=. xsl:value-of select=. page 110 xsl:value-of select=newline xsl:for-each xsl:template xsl:stylesheet When we sort these elements using data-type=text , heres what we get: 10 127 23 We get this result because a text-based sort puts anything that starts with a 1 before anything that starts with a 2. If we change the xsl:sort element to be xsl:sort select=. data-type=number , we get these results: 10 27 123 If you use something else here data-type=floating-point , for example, what the XSLT processor does is anybodys guess. The XSLT specification allows for other values here, but its up to the XSLT processor to decide how or if it wants to process those values. Check your processors documentation to see if it does anything relevant or useful for values other than data-type=text or data-type=number . A final note: if youre using data-type=number , and any of the values arent numbers, those non-numeric values will sort before the numeric values. That means if youre using order=ascending , the non-numeric values appear first; if you use order=descending , the non-numeric values appear last. ?xml version=1.0? numberlist number127number number23number numberzzznumber number10number numberyyynumber numberlist Given this less-than-perfect data, here are the correctly sorted results: zzz yyy 10 23 127 Notice that the non-numeric values were not sorted; they simply appear in the output document in the order in which they were encountered. order You can order the sort as order=ascending or order=descending . The default is order=ascending . case-order This attribute can have two values. case-order=upper-first means that uppercase letters sort before lowercase letters, and case-order=lower-first means that lowercase letters sort first. The case-order attribute is used only when the data-type attribute is text . The default value depends on the value of the soon-to-be-discussed lang attribute.