[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Does XSL support an eval?

Subject: Re: Does XSL support an eval?
From: Josef Vosyka <Josef.Vosyka@xxxxxxxxxxxxxxxxxx>
Date: Tue, 02 May 2000 18:17:41 -0700
xsl variable eval
Hi folks,

this one was pretty good, but what if the path is more sophisticated, such
as compossition of variables and strings, for example:

Your XML:
<root>
 <A>aaa</A>
 <A-list>alist</A-list>
</root>

Your XSL:
<xsl:variable name="path">/root/</xsl:variable>
<xsl:variable name="element">A</xsl:variable>

And you want to reference element: "/root/A-list" but using your variables,
something like:
<xsl:for-each select="$path+$element+'-list'" />
 ....
??

I've got also one perhaps stupid question. If I have a variable, say:

<xsl:variable name="foo">foobar</xsl:variable>

and I want to render the actual VALUE on the resulting tree rather then
value of the NODE referenced by the variable?

For example:

<xsl:value-of select="$foo" />

is looking node "foobar" but I want to copy the text "foobar" on the
resulting tree.

I must be missing sg really basic here.


Thank you,
--Josef



"G. Ken Holman" wrote:

> At 00/05/02 02:23 +1000, JamesW@xxxxxxxxxxxxxxx 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@xxxxxxxxxxxxxxxxxxxx
> 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


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.