RE: XSLT eval()

Subject: RE: XSLT eval()
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Mon, 21 Feb 2000 09:53:02 -0000
> Have there been discussions with regard to adding the 
> equivalent of the JavaScript eval() function to XSLT / XPath as either a
core 
> function or as an add-on extension function?

Saxon 5.2 provides an evaluate() extension function which does exactly this.
> 
> Instead, if we could write:
> 
> <xsl:param name="COLUMN select="name"/>
> ...
> <xsl:for-each select="item">
>   <xsl:sort select="extensionFunctionNamespace:eval( $COLUMN )"/>
> ...
> 
> this would provide the best of both worlds, no? 

The Saxon syntax is

<xsl:param name="COLUMN" select="'name'"/>
...
<xsl:for-each select="item">
   <xsl:sort select="saxon:evaluate( $COLUMN )"/>

The quotes round 'name' are important: saxon:evaluate() takes as argument a
String containing an expression; if you omitted the quotes, expression
'name' would be evaluated in the context of the <xsl:param> statement, not
the <xsl:sort> statement.

Incidentally, provided the sort key is restricted to be a child element of
<item>, and in the absence of namespaces, someone previously posted the
solution

<xsl:sort select="*[name()=$COLUMN]"/>

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread
  • XSLT eval()
    • John Lam - Sun, 20 Feb 2000 17:19:21 -0500
      • James - Sat, 20 Feb 1999 17:13:36 -0700
      • <Possible follow-ups>
      • Kay Michael - Mon, 21 Feb 2000 09:53:02 -0000 <=
      • John Lam - Mon, 21 Feb 2000 08:00:48 -0500