473,385 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Template that adds a given attribute and value

Hi

I've been messing around with adding attributes to certain nodes. I've looked
at FAQ at http://www.dpawson.co.uk/ without finding what I'm looking for.

Is it possible to have a template that is called with a node, an attribute
name and an attribute value. The template would add the the given attribute
name with the attribute value to the given note. Is this possible with XSLT -
and if so, where can I get it? :-)

Jun 27 '08 #1
2 1419
Hvid Hat wrote:
I've been messing around with adding attributes to certain nodes. I've looked
at FAQ at http://www.dpawson.co.uk/ without finding what I'm looking for.

Is it possible to have a template that is called with a node, an attribute
name and an attribute value. The template would add the the given attribute
name with the attribute value to the given note. Is this possible with XSLT -
and if so, where can I get it? :-)
You have already posted much of the solution:
<xsl:template name="add-attribute">
<xsl:param name="el"/>
<xsl:param name="att-name"/>
<xsl:param name="att-value"/>
<xsl:for-each select="$el">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="{$att-name}">
<xsl:value-of select="$att-value"/>
</xsl:attribute>
<xsl:copy-of select="node()"/>
</xsl:copy>
</xsl:for-each>
</xsl:template>

Call as

<xsl:call-template name="add-attribute">
<xsl:with-param name="el" select="foo"/>
<xsl:with-param name="att-name" select="'bar'"/>
<xsl:with-param name="att-value" select="'baz'"/>
</xsl:call-template>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
On 07-06-2008 15:05:54, Martin Honnen wrote:
You have already posted much of the solution:
<xsl:template name="add-attribute">
<xsl:param name="el"/>
<xsl:param name="att-name"/>
<xsl:param name="att-value"/>
<xsl:for-each select="$el">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="{$att-name}">
<xsl:value-of select="$att-value"/>
</xsl:attribute>
<xsl:copy-of select="node()"/>
</xsl:copy>
</xsl:for-each>
</xsl:template>

Call as

<xsl:call-template name="add-attribute">
<xsl:with-param name="el" select="foo"/>
<xsl:with-param name="att-name" select="'bar'"/>
<xsl:with-param name="att-value" select="'baz'"/>
</xsl:call-template>
Perfect! Thanks, Martin.
Jun 27 '08 #3

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

Similar topics

2
by: Julien Phalip | last post by:
Hi everyone! I am doing an XSL transformation from the following XML file: <foo> <attribute>a</attribute> </foo> The xslt file is:
1
by: Rolf Kemper | last post by:
Dear Experts, I'm going to create an Excell spreadsheet xml. So far things work very well. But in case I add <Row> elements by a recursive template call it goes wrong. See the attached XSLT...
7
by: Rolf Kemper | last post by:
Dear All, somehow I remember that such or similar question was discussed already somewhere. But I can't find it anymore. I have a template calling itself. As long it goes deeper into the...
1
by: bjam | last post by:
Hi, if I want to include a set of call template methods into my xsl file can I do that? Meaning I want to have the template method below of data_output in another file that I can use in several...
9
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the...
3
by: Steve | last post by:
Is there any way of specifying the startMode when using the xslTransform class? We are updating code which used msxml to the system.xml classes but can find no way to specify the startMode. We...
2
by: rick | last post by:
Greetings, I am trying to generate an html table that looks through the following xml source and lists links to all of the files (resource-file) and finds the resource-forms that match those...
6
by: Neal | last post by:
Hi All, I used an article on XSLT and XML and creating a TOC written on the MSDN CodeCorner. ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dncodecorn/html/corner042699.htm However, it did'nt...
1
by: Joe Strout | last post by:
Wow, this was harder than I thought (at least for a rusty Pythoneer like myself). Here's my stab at an implementation. Remember, the goal is to add a "match" method to Template which works like...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.