This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Creating a node from a variable
- From: "Thomas B. Passin" <tpassin at mitretek dot org>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Mon, 3 Dec 2001 11:38:00 -0500
- Subject: Re: [xsl] Creating a node from a variable
- References: <3C0BA514.4020406@umbrars.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
[Alessio Mazzieri]
> is there a method to create a node using the content of an <xsl:variable>?
>
> Something like this (but, unfortunately, not this!)
>
> <xsl:variable name="nodename">
> SomeName
> </xsl:variable>
>
> <xsl:element name="$nodename"/>
>
> The desidered output is
>
> <SomeName/>
>
> in the produced document.
You almost have it. You want to use
<xsl:element name="{$nodename}"/>
This use of braces ({}) is called an "attribute value template".
ALSO, you can't have any whitespace in an element name, so you should write
<xsl:variable name="nodename">SomeName</xsl:variable>
instead of what you had. Or even more trouble-free and compact:
<xsl:variable name="nodename" select='"SomeName"'/>
Note that "SomeName" is in (double) quotes to make it a string instead of
the name of an element (otherwise you would get a set of all the "SomeName"
nodes, which is not what you want). It may be hard to see that in the
example, depending on your display font.
Cheers,
Tom P
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list