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

Re: Using a variable to get the value of an element

Subject: Re: Using a variable to get the value of an element
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sat, 26 Jan 2002 00:27:06 +0000
get element by name value
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:

  "&#xA;   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


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.