xsl-list
[Top] [All Lists]

Re: empty attribute tags rendering in HTML

2006-02-27 11:41:31
Hi Bonnie,

Try this out:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="/">
        <xsl:apply-templates/>
</xsl:template>

<xsl:template match="a|td|img">
        <xsl:element name="{name()}">
        <xsl:for-each select="@*">
                <xsl:if test="not(normalize-space(.) = '')">
                        <xsl:attribute name="{name()}"><xsl:value-of 
select="."/></xsl:attribute>
                </xsl:if>
        </xsl:for-each>
        <xsl:apply-templates/>
        </xsl:element>  
</xsl:template>

</xsl:stylesheet>

On 2/27/06, Bonnie Vasko <bvasko(_at_)whittmanhart(_dot_)com> wrote:
Hello everyone,

I'm relatively new to XSL. I'm troubleshooting the templates created by
my former co-worker. They're outputting all the attributes for every
instance of every tag, even though they're empty, as in this example:

<td rowspan="2" colspan="" border="0" class=""><a id="" class=""
target="" title="" href="gateway.jsp" name=""><img id="" border="0"
alt="GuardMyHeart.com" class=""
src="images/headerLogo.gif"></a></td>


Here is a sample of the xsl:

<xsl:template match="a">
<a name="{(_at_)name}" href="{(_at_)href}" title="{(_at_)title}" 
target="{(_at_)target}"
class="{(_at_)class}" id="{(_at_)id}">
<xsl:value-of select="." /><xsl:apply-templates select="img" /></a>
</xsl:template>

<xsl:template match="td">
<td valign="{(_at_)valign}" align="{(_at_)align}" width="{(_at_)width}"></td>
</xsl:template>

<xsl:template match="img">
<img src="{(_at_)src}" class="{(_at_)class}" alt="{(_at_)alt}" border="0"
id="{(_at_)id}"></img>
</xsl:template>


I'm assuming there should be some kind of test that determines if the
attribute is empty, and if it is, don't write it. I haven't been able to
find an example of this. This is xml/xsl version 1. Thank you in
advance. Also, if you can point me to any resources that explain this, I
would really appreciate it.

Thanks,

Bonnie Vasko
Senior Developer
WHITTMANHART
main: 215.636.9500
fax: 215.636.9526
bvasko(_at_)whittmanhart(_dot_)com
www.whittmanhart.com



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>