[xsl] Re: variable indirection

Subject: [xsl] Re: variable indirection
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sun, 28 Dec 2003 18:26:52 +0100
<karim@xxxxxxxxxxxxxxxx> wrote in message
> Hi,
> Here's what I want to do :
> In a template I've got a variable which value is a string, this string is
> the name of a variable and I want to access it
> For example :
> $var1="var2" and I want to get $var2...
> Is that possible with xsl?

Generally no.


  1. A global xsl:variable with *static* content:

          document('')/*/xsl:variable[@name = $var1]/@select

  2. If the content of your variable is created dynamically, you can express
this with the following dynamically created xml:

     <varContainer:varContainer xmlns:varContainer="my:varContainer">
       .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .

    Then, if the above is the contents of the xsl:variable named
"vContainer", what you want is:

           $vContainer/*[name() = $var1]/node()

There's little meaning in your question as originally formulated, as
typically compiled languages (e.g. C, C++, Java, C#, etc.) do not allow
referencing a variable with dynamically created name.

Some of them have a pre-processor for this, but its work is done even before

Dimitre Novatchev.
FXSL developer

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html

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

Current Thread