473,789 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use of XSL:variable in XML-Attribute

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="SubHead er"/>
<xsl:variable name="ProjectNa me" select="SubHead er/@name"/>
<SubDir name=$ProjectNa me>
....

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="TestProje ct">
.....
Is this possible ? Or do I use to "Exportz" the additional XML-Tag in a
second XML file ?

Thanks

Sep 16 '05 #1
3 1466
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
element-node?

Why do you not use xsl:attribute?

Perhaps you can show us a minimal example input and output
document-fragment.
Chris
--
Chris Huebsch www.hübsch-gemacht.de | 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
http://chemnitzer.linux-tage.de/ | +49 371 531-1377, Fax -1803
Sep 16 '05 #2
Hi,

Tempore 10:00:18, die Friday 16 September 2005 AD, hinc in foro {comp.text.xml} scripsit schaf <sc***@2wire.ch >:
<xsl:template match="Header">
<xsl:copy >
<xsl:apply-templates select="SubHead er"/>
<xsl:variable name="ProjectNa me" select=""/>
<SubDir name=$ProjectNa me>


Attribute Value Template:
<SubDir name="{$Project Name}">
or even: <SubDir name="{SubHeade r/@name}">

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

--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Gaudiam omnibus traderat W3C, nec vana fides
Sep 16 '05 #3
Hi!
Thanks the solution with the {$ProjectName} was wath I needed.
Regards

Sep 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4417
by: Xeon | last post by:
Hi, I'm trying this code snippet below but the parser (sablotron) returns error : <xsl:choose> <xsl:when test="some test case"> <xsl:variable name="test" select="0"/> </xsl:when> <xsl:otherwise>
5
4129
by: Nagi Peters | last post by:
Hello I try to tranform a XML Document in php/Sablotron with the following XSL Stylesheet. I tried to write "@id='1'" with the variable chapter_id. So it works: <xsl:variable name="chapter_id">1</xsl:variable> <xsl:template match="chapter"> snipp..
4
2589
by: sylvain.loiseau | last post by:
Hello Given a node set, I try to compute the total of the string-length value of each node. For instance, with : <xsl:for-each select="//q"> <!-- the length of each node is compute with: --> <xsl:value-of select="string-length(.)" />
2
1728
by: Norman Barker | last post by:
Hi, I have the following template <xsl:template match="midas:Request"> <xsl:variable name="var1" select="string(./midas:DataDescriptorGUID/@GUID)"/> <test> <result1><xsl:copy-of select="$OGC_Type"/></result1> <result2><xsl:copy-of select="$OGC_Type"/></result2> </test>
10
3827
by: Tjerk Wolterink | last post by:
The following code does not work: <xsl:variable name="width" select="form:image-width"/> <xsl:if test="$width>$max_image_width"> <xsl:variable name="width" select="$max_image_width"/> </xsl:if> <img class="admin" width="{$width}" src="{form:image-url}" /> The width attribute of img is always "", the $max_image_width variable is set to 200 and $width is initially set to the width of the image.
1
1611
by: schaf | last post by:
Hello NG ! I have a big problem. I would like to go through a xml file in a xsl:for-each statement. for-each entry (ID) in the XML file i would like to call an xsl:function, which returns a number. This number i have to summarize during the whole for-each statement. At the end i should have the sum of the added numbers. Like:
2
1480
by: sucheta.phatak | last post by:
Hello, I am trying to use XSLT. Here is the problem that I am facing. My XML file: <Book level="1" name="Mapplicationtoc1"> ....... Some more tags </Book>
5
6322
by: Afshar Mohebbi | last post by:
Hi everybody there, I've declared a <xsl:variable name="something" select="999"/> in my xslt and when I want to set another value in it (with same syntax) I get error the variable "something" has been declared previously. I couldn't find a way to change it's value. It seems it is constant. Is there any alternative way? Thanks in Advance Afshar
0
1447
by: paragguptaiiita | last post by:
I have one problem regarding displaying text from XML file. I have a XSL variable named $p = (0 0 0) (0.82 0 0) (1.63 -0.01 0) (2.63 -0.01 0) (3.63 -0.01 0) (4.63 -0.01 0) (5.63 -0.02 0) (6.63 -0.02 0) (7.63 -0.02 0) (8.6 -0.02 0) This line contains X,Y,Z coordinates of 10 points. for displaying each coordinate in a separate line.Like this.... (0 0 0) (0.82 0 0) (1.63 -0.01 0) (2.63 -0.01 0) (3.63 -0.01 0) (4.63 -0.01 0)
0
1517
by: paragguptaiiita | last post by:
I have one problem regarding displaying text from XML file. I have a XSL variable named $p = (0 0 0) (0.82 0 0) (1.63 -0.01 0) (2.63 -0.01 0) (3.63 -0.01 0) (4.63 -0.01 0) (5.63 -0.02 0) (6.63 -0.02 0) (7.63 -0.02 0) (8.6 -0.02 0) This line contains X,Y,Z coordinates of 10 points. for displaying each coordinate in a separate line.Like this.... (0 0 0) (0.82 0 0) (1.63 -0.01 0) (2.63 -0.01 0) (3.63 -0.01 0) (4.63 -0.01 0)
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.