By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,201 Members | 956 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,201 IT Pros & Developers. It's quick & easy.

XSLT: How to avoid empty attributes in attribute-sets?

P: n/a

I'm using xsl:attribute-sets to reduce redundancy in my XSLT.
An example from a transformation to XHTML (the attribute values are
simply copied from input to output):

<xsl:attribute-set name="cellhalign">
<xsl:attribute name="align">
<xsl:value-of select="@align" />
<xsl:attribute name="char">
<xsl:value-of select="@char" />
<xsl:attribute name="charoff">
<xsl:value-of select="@charoff" />

Works fine, except that it generates empty attributes, if the attribute
is not defined in the source XML:

<td align="" char="" charoff="">31</td>

That's quite ugly. Especially when you have a lot of <td>'s...

Now you cannot use <xsl:ifin an <xsl:attribute-set>.
So if you like to create a "conditional attribute" you'd have to do it
within the template:

<xsl:template match="nitf:td">
<xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align" />
<!-- repeat that for the other attrs -->

But doing that will be extremely redundant if the same attributes apply
to several templates.

It there any solution to avoid redundant attribute declarations *and*
avoid empty attributes in the output XML?

Thank you very much!
Thomas Wittek
Jabber: st*********
GPG: 0xF534E231
Aug 26 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.