Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Template that adds a given attribute and value

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 6/7/2008 3:06:00 PM

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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent