Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Use of XSL:variable in XML-Attribute

Thread Tools

Use of XSL:variable in XML-Attribute

Posts: n/a
Hi !
I have a little question. With my XSL File I add additional XML-Tags to
an existing XML-File. But I would like to use a xsl:variable for
inserting a value into an additional xml-attribute.

<xsl:template match="Header">
<xsl:copy >
<xsl:apply-templates select="SubHeader"/>
<xsl:variable name="ProjectName" select="SubHeader/@name"/>
<SubDir name=$ProjectName>

Because <subDir> would be treated like an XML-Tag, it is not possible
to add the value of the variable in the name attribute !?!

My destination should look like:

<SubDir name="TestProject">
Is this possible ? Or do I use to "Exportz" the additional XML-Tag in a
second XML file ?


Reply With Quote
Chris Huebsch
Posts: n/a
schaf (16 Sep 2005 01:00:18 -0700):
> Is this possible ? Or do I use to "Exportz" the additional XML-Tag in a
> second XML file ?

You copy an xml-file and would like to add an additiona attribute to an

Why do you not use xsl:attribute?

Perhaps you can show us a minimal example input and output

Chris Huebsch www.hü | TU Chemmnitz, Informatik, RNVS
GPG-Encrypted mail welcome! ID:7F2B4DBA | Str. d. Nationen 62, B204
Chemnitzer Linux-Tage 2005, 5.-6.März | D-09107 Chemnitz | +49 371 531-1377, Fax -1803
Reply With Quote
Joris Gillis
Posts: n/a

Tempore 10:00:18, die Friday 16 September 2005 AD, hinc in foro {comp.text.xml} scripsit schaf <(E-Mail Removed)>:

> <xsl:template match="Header">
> <xsl:copy >
> <xsl:apply-templates select="SubHeader"/>
> <xsl:variable name="ProjectName" select=""/>
> <SubDir name=$ProjectName>

Attribute Value Template:
<SubDir name="{$ProjectName}">
or even: <SubDir name="{SubHeader/@name}">

(The string between the {curly} brackets is interpreted as an XPath expression)

Joris Gillis (
Gaudiam omnibus traderat W3C, nec vana fides
Reply With Quote
Posts: n/a
Thanks the solution with the {$ProjectName} was wath I needed.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Could not use ''; file already in use. M K ASP .Net 11 04-09-2008 11:35 AM
where to use CPLD & where to use FPGA? VHDL 6 03-06-2006 07:27 AM
How do I know when to use the Viewstate and when to use the posted data? :-) Simon ASP .Net 1 11-09-2004 02:32 AM
Can I use XPath or something to a remote Mac or Linux box and just query an xml file, not using web services and use encyrption? jake ASP .Net 0 07-06-2004 02:16 PM
Cannot use the profile "default" because it is in use, not. Firefox 1 07-04-2004 03:41 AM