Re: [xsl] Only output element when parameter value is not equal to blank (or null)

Subject: Re: [xsl] Only output element when parameter value is not equal to blank (or null)
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Thu, 01 Feb 2007 13:11:22 +0100
Chris Coyle wrote:
I tried:
                                              <xsl:if
test="exists($productid)">
					   <Attribute name="PRODUCTID"
type="string"><xsl:value-of
select="$productid"/></Attribute>
					</xsl:if>

but got the following error:
06:47:27.062 global (ERROR) - Uncaught Exception:
'exists' is not a valid XSLT or XPath function.

exists() is an XPath 2 function, you use an XPath/XSLT 1 parser. But even if you weren't, it is not the right thing to do, exists($param) will always return true(), with one exception, when the variable returns an empty sequence:


<xsl:param name="myparam" select="()" />
or <xsl:param name="myparam" select="/.." />

then this yields false:
<xsl:if test="exists($myparam)" >....

However, with:

<xsl:param name="myparam" select=" '' " />
or <xsl:param name="myparam" select="0" />
or <xsl:param name="myparam"  />

then this yields true:
<xsl:if test="exists($myparam)" >....


Cheers! -- Abel Braaksma

Current Thread