Hi Lorenzo:
The largest issue here is that you're putting the sort in the wrong place...
In this template:
<xsl:template match="xCVP/PersonDetails">
<html>
<body lang="eng">
<section>
<h>languages</h>
<p>
<xsl:apply-templates select="Languages/Language"/>
</p>
</section>
</body>
</html>
</xsl:template>
You are selecting for processing all Language elements, and at that point you
must put the sort, otherwise it'll process it in document order:
<xsl:apply-templates select="Languages/Language">
<xsl:sort select="@type" data-type="text" order="ascending"/>
</xsl:apply-templates>
Also note that:
<xsl:for-each select=".">
Will always execute exactly once because "." is short for "self::*" -- the
context node.
HTH!
Dion
-----Original Message-----
From: Lorenzo De Tomasi [mailto:lorenzo(_dot_)detomasi(_at_)libero(_dot_)it]
Sent: Monday, February 17, 2003 3:17 PM
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
I have a problem with xsl:sort
I have written this code
____________________________________________________________________________
XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="contact_temp.xsl"?>
<xCVP xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:a="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"
xmlns:n="urn:oasis:names:tc:ciq:xsdschema:xNL:2.0" xsi:schemaLocation="">
<PersonDetails lang="eng">
<Languages>
<Language type="other language" speak="good" read="excellent"
write="good" code="eng">English</Language>
<Language type="mother tongue" speak="excellent"
read="excellent" write="excellent" code="ita">Italiano</Language>
<Language type="other language" speak="basic" read="basic"
write="basic" code="fr">Fran^ßais</Language>
</Languages>
</PersonDetails>
</xCVP>
____________________________________________________________________________
XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="xCVP/PersonDetails">
<html>
<body lang="eng">
<section>
<h>languages</h>
<p>
<xsl:apply-templates select="Languages/Language"/>
</p>
</section>
</body>
</html>
</xsl:template>
<xsl:template match="PersonInfo">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Languages">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Language">
<xsl:for-each select=".">
<xsl:sort select="@type" data-type="text" order="ascending"/>
<xsl:choose>
<xsl:when test="@type='mother tongue'">
<l><span class="label"><xsl:value-of
select="@type"/></span><xsl:text> </xsl:text><xsl:value-of select="."/></l>
</xsl:when>
<xsl:otherwise>
<l><span class="label"><xsl:value-of
select="@type"/></span><xsl:text> </xsl:text><xsl:value-of
select="."/><xsl:text> </xsl:text><span class="label">speak</span><xsl:text>
</xsl:text><xsl:value-of select="@speak"/><xsl:text> </xsl:text><span
class="label">read</span><xsl:text> </xsl:text><xsl:value-of
select="@read"/><xsl:text> </xsl:text><span
class="label">write</span><xsl:text> </xsl:text><xsl:value-of
select="@write"/></l>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
____________________________________________________________________________
and tested it in Netscape 7 for mac and the result is
____________________________________________________________________________
RESULT
languages
other language English speak good read excellent write good
mother tongue Italiano
other language Français speak basic read basic write basic
____________________________________________________________________________
As you can seen the result is not what I want. The lines are not ordered by
type attribute, but by xml order. Have I done something wrong?
With xslt can I order a list created with xsl:for-each specifying a precise
order?
i.e. I want to make a list and I want to display first the items with
attribute type="special offer" in ascending order and then all the other
ones by ascending order.
XML
<item type="special offer!">book</item>
<item>book</item>
...
RESULT
special offer! book $10
special offer! cd $5
special offer! doll $10
book $20
cd $10
doll $20
Thank you very much!
____________________________________________________________________________
Lorenzo De Tomasi, student of Information Architecture, Interface Design and
Visual Design
via Bellaria 6, 21018 Sesto Calende (Varese), Italia
phone: +39 (0)331 924649
mobile: +39 329 3941065; +39 333 8979304
e-mail: lorenzo(_dot_)detomasi(_at_)libero(_dot_)it;
lorenzo(_dot_)detomasi(_at_)email(_dot_)it
website: http://biografica.tzone.it
ICQ uin: 11313132
Yahoo! Instant Messenger id: tummait
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list