applying common attributes

What I am trying to do is generate a bit of code which could then be used to apply attributes to various elements if there has been a value specified. I have tried doing it with an attribute-set, but this is not working because it doesn’t like conditionals inside attribute sets.

Here is an example of what I’ve tried to use for attribute-set

<xsl:attribute-set name="common">
  <xsl:if test="@name != ''">
    <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
  <xsl:if test="@type != ''">
    <xsl:attribute name="type"><xsl:value-of select="@type" /></xsl:attribute>
</pre><BR><BR>I have used various ways to apply these, such as:<BR><BR><pre class="ip-ubbcode-code-pre">
  <xsl:use-attribute-sets="common" />


<input xsl:use-attribute-sets="common">

When I replace the conditionals in the attribute-set with static values (ie <xsl:attribute name=“name”><xsl:value-of select=“@name” /></xsl:attribute>) it works fine, but I do not want to do this because I dont want all elements to have, say, a name tag simply because I applied the common attribute-set, but rather only if one has been specified.

Anyone know a way to accomplish what I am trying to do? This would save me quite a bit of code if I could define all the common attributes once, and apply/insert the code where I want to run checks against them, applying where necessary.



- if you look at you’ll see that
xsl:attribute-set only allows for child nodes of type xsl:attribute
- you may try the following

<xsl:template match=“*” mode=“common”>
<xsl:if test=“@name != ‘’”>
<xsl:attribute name=“name”><xsl:value-of select=“@name” /></xsl:attribute>
<xsl:if test=“@type != ‘’”>
<xsl:attribute name=“type”><xsl:value-of select=“@type” /></xsl:attribute>

<xsl:apply-templates match=“.” mode=“common”>

Best regards

Thanks Uli. This seems to work in my initial testing, with one small modification (match not allowed in apply-templates, using ‘select’ seems to work).

I’ll know a bit better if it will work in my specific requirement on Monday. Thx again