[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: value of xsl:param in xsl:sort
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|