Subject: RE: dynamic sorting
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Thu, 5 Feb 2004 17:01:25 -0000
|
Dynamic sorting is a FAQ, though your example is unusual since you seem
to be selecting the node-set to be sorted dynamically, rather than the
sort key.
If your parameter is always an element name, you can use
*[name()=$param]. If it's a more general XPath expression, you need the
xx:evaluate() extension function offered by some products, which allows
you to treat a string as an XPath expression.
In your example $sort is the string "person", not the XPath expression
"person".
Michael Kay
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
> Peter Billen
> Sent: 05 February 2004 15:02
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: dynamic sorting
>
>
> Hello all,
>
> I'm breaking my head on some problem, and I hope you can help
> me with it.
>
> Imagine the following part of an xml file:
>
> <person>
> <fname>Jup</fname>
> <lname>Nope</lname>
> <bday>Also</bday>
> ...
> </person
>
> The following works perfect:
>
> <xsl:template match="/">
> <xsl:apply-templates select="person">
> <xsl:sort select="person/fname"/
> </xsl:apply-templates>
> </xsl:template>
>
> But when I put the string "person" into a parameter named
> "sort", it doesn't work anymore:
>
> <xsl:template match="/">
> <xsl:param name="sort">person</xsl:param>
> <xsl:apply-templates select="$sort">
> <xsl:sort select="person/fname"/
> </xsl:apply-templates>
> </xsl:template>
>
> My goal is that the user of my xsl file can give a parameter
> "sort" (to his xslt parser) which defines his preferred way
> of sorting.
>
> Any ideas what is wrong?
>
> Thanks a lot,
>
> --
> Peter
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|