[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
news:1072588445.3fee669d6e86e@xxxxxxxxxxxxxxx
>
> Hi,
>
> Here's what I want to do :
> In a template I've got a variable which value is a string, this string is
also
> 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.

Exceptions:

  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">
        <varName1>tree1</varName1>
        <varName2>tree2</varName2>
       .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
        <varNameN>treeN</varNameN>
     </varContainer: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
compile-time.

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