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: Passing sort criteria as a paramter


Hi David,

> You seemed to get this msg to the list. Wendell, thanks. I didn't
> think of that. BTW, can I use an xsl:attribute tag for another xsl
> element?

Since Wendell nabbed the other question, I'll answer this one ;)

I take it you're asking whether you can use xsl:attribute to
dynamically create an attribute on an XSLT element. So you're asking
if you can do:

  <xsl:sort>
    <xsl:attribute name="select">
      <xsl:value-of select="$sortby" />
    </xsl:attribute>
  </xsl:sort>

As a way of getting around the fact that $sortby is a string and you
want to interpret it as an XPath expression.

The answer is no, you can't. You can only use xsl:attribute to add
attributes onto result elements (whether created with literal result
elements or with xsl:element).

Of course if the 'xsl:sort' were a literal result element, then it
would be fine. So if you were generating a stylesheet from your
stylesheet, and set up a namespace alias for the XSLT namespace so
that 'oxsl' was the prefix used for the XSLT elements you're
generating, you can do:

  <oxsl:sort>
    <xsl:attribute name="select">
      <xsl:value-of select="$sortby" />
    </xsl:attribute>
  </oxsl:sort>

and it will generate:

  <oxsl:sort select="Amount[../IsCredit = 1]" />

By the way, I suggest that you forward your use case on to
xsl-editors@w3.org - hopefully if they receive enough use cases then
they will add an evaluate() function to XSLT 2.0, so that you could
just do:

  <xsl:sort select="evaluate($sortby)" />

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]