This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Creating a node from a variable


[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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]