xsl-list
[Top] [All Lists]

RE: referring to variables using variables?

2004-01-12 09:15:10

Is there anyway that i can achieve the same solution but in a slightly different way?

thanks james walker


From: "Michael Kay" <mhk(_at_)mhk(_dot_)me(_dot_)uk>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: RE: [xsl] referring to variables using variables?
Date: Mon, 12 Jan 2004 15:51:08 -0000

XSLT is not a macro language. The content of a variable is a value
(either a boolean, a string, a number, or a node-set). It is not part of
the text of an XPath expression. I think this is where your confusion
comes from.

For example, if $x contains the string 'xyz', then $x/pqr does not mean
xyz/pqr, it means 'xyz'/pqr, which is an error: the operands of the "/"
operator must be node-sets, not strings.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
> [mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
> james walker
> Sent: 12 January 2004 13:56
> To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
> Subject: [xsl] referring to variables using variables?
>
>
> I am trying to access different xml documents where the
> variable name of the
> document (declared at the top of the file) is equal to the
> category name of
> the file being translated:
> e.g. given this xslt:
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:variable name="jaka" select="document('http:......')" />
> <xsl:variable name="foobar" select="document('http:......')" />
>
> <xsl:template match="category">
> <xsl:variable name="catname" select="name" />
> <xsl:for-each select="$catname/root/child::*)">
> <li><xsl:value-of select="detail" /></li> </xsl:for-each>
> <xsl:apply-templates select="./category" /> </xsl:template>
> </xsl:stylesheet>
>
> I translated this with file1.xml which contained the two
> category names jaka
> aand foobar. i have named the categories in the file1.xml to
> be $foobar and
> $jaka so when $catname is substitued into
> $catname/root/child::* it should
> look like $foobar/root/child::* for foobar categoyr and
> $jaka/root/child::*
> for jaka category.
>
> However, when i translate it, it doesnt seem to show anything
> when it gets
> to the xpath staement $catname/root/child::*.
> I tested to see if it works when u put the variable name
> directly in there
> and it does (e.g. putting  $foobar/root/child::* )??
> Does anyone know if i am close to the solution (am i making a
> silly mistake
> with variable decalration?0
> cheers
> james walker
>
> _________________________________________________________________
> Express yourself with cool emoticons - download MSN Messenger today!
> http://www.msn.co.uk/messenger
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


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


_________________________________________________________________
Find a cheaper internet access deal - choose one to suit you. http://www.msn.co.uk/internetaccess


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