This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Does XSL support an eval?
- To: xsl-list at mulberrytech dot com, xalan-dev at xml dot apache dot org
- Subject: Re: Does XSL support an eval?
- From: Josef Vosyka <Josef dot Vosyka at headland-media dot com>
- Date: Tue, 02 May 2000 18:17:41 -0700
- Organization: Headland digital media, Inc.
- References: <4.2.0.58.20000502175700.01a6c440@pop1.attglobal.net>
- Reply-To: xsl-list at mulberrytech dot com
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@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>
</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
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list