Re: ifdefined test for variable

Subject: Re: ifdefined test for variable
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 6 Aug 1999 09:37:25 +0100 (BST)
> 'if defined' test on a variable?

No, because either it is defined, or trying to reference it in a test
would generate an error.

your $onload variable must have some value always, perhaps in your
`false' case it is the empty string, or null node list

so you could do something like

<xsl:if test=" ''= $onload">
    <xsl:attribute name="onload">$onload</xsl:attribute>
</xsl:if>

or even, given the coersion of non empty strings to boolean true:

<xsl:if test="$onload">
    <xsl:attribute name="onload">$onload</xsl:attribute>
</xsl:if>

However it is possibly easier just to not bother with the test and just
go

<xsl:copy-of select="$onload"/>

where onload has value either a null result tree fragment, or
the result of running
 <xsl:attribute name="onload">something</xsl:attribute>

David


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


Current Thread