Subject: Re: [xsl] value of xsl:param in xsl:sort From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 14 Feb 2002 08:30:10 +0000 |
Hi Kunal, > ======================== > <xsl:param name="sortByElement">AuthorList/Author/Name</xsl:param> > <xsl:sort select="$sortByElement" order="ascending"></xsl:sort> > ======================== Others have shown how you get around this problem if the $sortByElement is the name of a single element with *[name() = $sortByElement]. Unfortunately, in your case, $sortByElement is not the name of a single element, but rather a path that steps down several levels to get the value that you want. This difference makes what you're after very difficult to do in a single XSLT 1.0 transformation. I'm sure that there are ways to achieve it (since everything is possible in XSLT) but they will probably not be very pretty. The easiest thing to do is to use an extension function that allows you to evaluate paths dynamically, such as saxon:evaluate() or xalan:evaluate() (you can create your own in MSXML). For example, in Xalan you'd do: <xsl:param name="sortByElement">AuthorList/Author/Name</xsl:param> <xsl:sort select="xalan:evaluate($sortByElement)" order="ascending"/> If you can't do that, the next best thing is to make the transformation into a two-stage process. The $sortByElement parameter is passed into the first stage, and is used to create an XSLT stylesheet in which the xsl:sort's select attribute holds the correct path. Then the resulting XSLT is used to transform your source document for the second stage. $sortByElement -> (XSLT generator) -> stylesheet | v XML source -> (XSLT process) -> result The XSLT generator could be a full XSLT stylesheet. Or, in the simplest case, you might be able to take your existing stylesheet as a DOM, and alter the select attribute in that DOM before using it as the stylesheet for the main transformation. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] value of xsl:param in xsl, Kunal H. Parikh | Thread | Re: [xsl] value of xsl:param in xsl, Joerg Pietschmann |
RE: [xsl] XSLT: SUM function Not , Oliver Becker | Date | Re: [xsl] XSLT !! easy one!! , Trai, Oliver Becker |
Month |