Re: [xsl] Problems passing attributes

Subject: Re: [xsl] Problems passing attributes
From: "Paul Tyson" <paul@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 28 Sep 2001 09:17:06 -0700
If you *always* want to emit a border attribute, and you *always* want it to
be a numeric value (not null), here's an easy way:

<xsl:template match="table">
    <table cellspacing="0" cellpadding="0" border="0">
        <xsl:if test="@border != ''"><!-- if attribute exists and is
non-null -->
            <xsl:attribute name="border">
                <xsl:value-of select="@border"/><!-- use it's value -->
            </xsl:attribute>
        </xsl:if>
        <!-- do the table thing -->
    </table>
</xsl:template>

The last attribute specified in the literal result element takes precedence
if the same attribute name is used more than once.

If you only want to emit a border attribute when a non-null one is specified
on input, just leave the 'border="0"' out of the literal result element
begin tag.

If you don't care about emitting null border attributes, this is the most
compact:
    <table cellspacing="0" cellpadding="0" border="{@border}">
        <!-- do the table thing -->
    </table>

Have fun,
--Paul

----- Original Message -----
From: "Hewko, Doug" <Doug.Hewko@xxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, September 28, 2001 6:01 AM
Subject: [xsl] Problems passing attributes


> Can someone please tell me what am I doing wrong? I need to create tables,
> so I am mimicing HTML's tables. I am having problems passing the value of
> the "border" attribute to the HTML equiivalent. In my HTML code, I see
> "<table border="$border">  "
>
> Thanks.
>
> XML:
> <table border="1">
> <tr>
> <td>Column</td>
> </tr>
> </table>
>
> XSL:
>
> <xsl:template match="table">
> <xsl:if test="@border=''">
> <xsl:variable name="border">
> "0"
> </xsl:variable>
> </xsl:if>
> <xsl:if test="@border!=''">
> <xsl:variable name="border">
> <xsl:value-of select="@border"/>
> </xsl:variable>
> </xsl:if>
>
> <table border="$border;" cellspacing="0" cellpadding="0">
> <xsl:apply-templates />
> </table>
> </xsl:template>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread