472,791 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 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 1402
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.