[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Choosing different sorts
Subject: RE: [xsl] Choosing different sorts From: <Jarno.Elovirta@xxxxxxxxx> Date: Thu, 15 Jul 2004 10:35:06 +0300 |
Hi, > I had a look in the archives before posting, and am > not sure I understand the method which uses: > > <xsl:sort select="*[name(.) = $sortfield]"/> Expression *[name(.) = $sortfield] will return a node-set of elements whose name equal the string value of the variable sortfield. In xsl:sort the result is converted to a string, thus if the node-set contains more that one node, the string value of the first node in the set is used as the sort key. > I have tried, in my code to have: > > <xsl:for-each select="file"> > <xsl:choose> > <xsl:when test="$sort='design'"><xsl:sort > select="name"/></xsl:when> See the spec <http://www.w3.org/TR/xslt#element-sort>: "When used in xsl:for-each, xsl:sort elements must occur first." The way around this is e.g. <xsl:variable name="sortkey"> <xsl:choose> <xsl:when test="$sort='design'">name</xsl:when> <xsl:when test="$sort='stat'">status</xsl:when> <xsl:otherwise>id</xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:for-each select="file"> <xsl:sort select="*[name() = $sortkey]"/> ... </xsl:for-each> Cheers, Jarno - VNV Nation: Electronaut
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Choosing different sorts, Jeni Tennison | Thread | [xsl] Getting Extra space while con, Leena Sharma |
RE: [xsl] Learning Tool for XPath?, Robert Soesemann | Date | [xsl] generating an HTML web hiera, Arulraj |
Month |