- From: David B. Bitton <david@codenoevil.com>
- Date: Fri, 25 Jan 2002 10:30:20 -0500 (EST)
- To: xsl-editors@w3.org
As requested by Jeni Tennison, I am forwarding you my post from the xsl-list. I am in need of an evaluate function so I can pass an element name and predicate into a stylesheet as a param. Basically, I pass the element that I used to sort by as a param, so my xsl:sort's select attribute looks like this: select="*[local-name() = $sortby]" But I have an instance where I need this: select="Amount[../IsCredit=1]" Now I understand that I could do Select="*[local-name() = $sortby][../IsCredit=1]" But that is not applicable for any other element other than Amount (and only a credit amount). This is all because we display debits and credits in different columns, and we allow the user to sort be either column. Unfortunately the only way I have to differentiate a credit from a debit is a sibling flag, IsCredit, which can be either 1 or 0, which as you can see, would be used as a predicate against the Amount element. Hopefully this will be considered for the next version of XPath. Thanks. -----Original Message----- From: Jeni Tennison [mailto:jeni@jenitennison.com] Sent: Friday, January 25, 2002 5:25 AM To: David B. Bitton Cc: xsl-list@lists.mulberrytech.com Subject: Re: [xsl] 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/
Received on Friday, 25 January 2002 12:23:23 UTC