This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]