This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Using a variable to get the value of an element
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Ben Skelton" <bskelton at Habaneros dot com>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Sat, 26 Jan 2002 00:27:06 +0000
- Subject: Re: [xsl] Using a variable to get the value of an element
- Organization: Jeni Tennison Consulting Ltd
- References: <0CA8380EDC953641854A37F41D66E03206504E@jarocho.Habaneros.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Ben,
> I need the value of an element, but the name of that element is
> stored in a variable - see below:
You either need an evaluate() extension function or, for this simple
case, you can use the pattern:
*[name() = $variable]
Which locates all the elements whose name is the value of the
$variable.
One thing you need to watch out for in your particular example is
whitespace. The $hello variable will contain a string that looks like:
"
 officename1_en"
To avoid that whitespace, you either have to normalize the variable
before you compare it to the name of the element:
*[name() = normalize-space($hello)]
or you need to create the $hello variable without the extraneous
whitespace, with:
<xsl:variable name="hello">officename1_<xsl:value-of
select="$PageLang /></xsl:variable>
or:
<xsl:variable name="hello">
<xsl:text>officename1_</xsl:text>
<xsl:value-of select="$PageLang" />
</xsl:variable>
or:
<xsl:variable name="hello">
<xsl:value-of select="concat('officename1_', $PageLang)" />
</xsl:variable>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list