[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: value of xsl:param in xsl:sort

Subject: Re: value of xsl:param in xsl:sort
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 14 Feb 2002 08:30:10 +0000
xslt param 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.