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]

Re: Does XSL support an eval?


At 00/05/02 02:23 +1000, JamesW@cardsetc.com.au wrote:
>Is there a way in XSL to take an XPath query described in a parameter or 
>variable, and reference this parameter in the select attribute of say, 
>xsl:for-each to iterate through the node set described by the query.
>
>ie.
>
><xsl:variable name="myPath" select="'/my/XPath/@query'"/>
><xsl:for-each select="{$myPath}">
>         ...
></xsl:for-each>
>
>We were under the impression that using the curly braces might achieve 
>this, but haven't had any luck so far.

You are *so* close that I hope you don't get hurt kicking yourself.

Using standard XSLT 1.0 (no extensions) you can assign a node set to a 
variable using an XPath expression ... unfortunately, you quoted your 
expression which is assigning a string value to the variable, not a node 
set.  When you assign a node set and you remove the brace brackets you 
have, it works just fine (see example below).

I hope this helps.

................ Ken


T:\ftemp>type test.xml
<?xml version="1.0"?>
<my>
  <XPath query="first">
  </XPath>
  <XPath query="third">
  </XPath>
  <XPath query="second">
  </XPath>
</my>

T:\ftemp>type test.xsl
<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version="1.0">

<xsl:output method="text"/>

<xsl:template match="/">                         <!--root rule-->
   <xsl:variable name="myPath" select="/my/XPath/@query"/>
   <xsl:for-each select="$myPath">
     <xsl:text>Value: </xsl:text>
     <xsl:value-of select="."/>
     <xsl:text>&#xd;&#xa;</xsl:text>
   </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>xt test.xml test.xsl
Value: first
Value: third
Value: second

T:\ftemp>

--
G. Ken Holman                    mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Web site: XSL/XML/DSSSL/SGML services, training, libraries, products.
Practical Transformation Using XSLT and XPath      ISBN 1-894049-04-7
Next instructor-led training:               2000-05-11/12,2000-05-15,
-                                    2000-06-12,2000-06-13,2001-01-27


 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]