T
Tjerk Wolterink
I have a variable $value as a parameter in the following template:
<xsl:template name="myTemplate">
<xslaram name="value"/>
<xsl:if test="$value">
<xsl:value-of select="$value"/>
</xsl:if>
</xsl:template>
Now i call myTemplate sometimes whit the a parameter $value that
is sometimes a text node, and sometimes it is not even a node.
Example:
<inputDoc>
<a>hello</a>
<a/>
</inputDoc>
xsl:
<xsl:for-each select="/inputDoc/a">
<xsl:call-template name="myTemplate">
<xsl:with-param name="value" select="./text()"/>
</xsl:call-template>
</xsl:for-each>
So i call myTemplate with parameter $value=a/text()
But for the second <a> element in <inputDoc> there
is not text() node.
This gives me the following error:
Cause: javax.xml.transform.TransformerException: The value is not a
node-set
With line number of the error pointing to the xsl:if in myTemplate.
No i tried the function nilled(), but that is XPath 2.0, i only
use XPath 1.0 and XSL 1.0
i know a possible solution is this:
<xsl:for-each select="/inputDoc/a">
<xsl:choose>
<xsl:when test=".[not(node())]">
<xsl:call-template name="myTemplate">
<xsl:with-param name="value" select="false()"/>
</xsl:call-template>
</xsl:when>
<xsltherwise>
<xsl:call-template name="myTemplate">
<xsl:with-param name="value" select="./text()"/>
</xsl:call-template>
</xsltherwise>
</xsl:for-each>
But this requires me to change every call to myTemplate,
which is alot of code. Can't i change myTemplate so
it works?
Who can help me? Please..
<xsl:template name="myTemplate">
<xslaram name="value"/>
<xsl:if test="$value">
<xsl:value-of select="$value"/>
</xsl:if>
</xsl:template>
Now i call myTemplate sometimes whit the a parameter $value that
is sometimes a text node, and sometimes it is not even a node.
Example:
<inputDoc>
<a>hello</a>
<a/>
</inputDoc>
xsl:
<xsl:for-each select="/inputDoc/a">
<xsl:call-template name="myTemplate">
<xsl:with-param name="value" select="./text()"/>
</xsl:call-template>
</xsl:for-each>
So i call myTemplate with parameter $value=a/text()
But for the second <a> element in <inputDoc> there
is not text() node.
This gives me the following error:
Cause: javax.xml.transform.TransformerException: The value is not a
node-set
With line number of the error pointing to the xsl:if in myTemplate.
No i tried the function nilled(), but that is XPath 2.0, i only
use XPath 1.0 and XSL 1.0
i know a possible solution is this:
<xsl:for-each select="/inputDoc/a">
<xsl:choose>
<xsl:when test=".[not(node())]">
<xsl:call-template name="myTemplate">
<xsl:with-param name="value" select="false()"/>
</xsl:call-template>
</xsl:when>
<xsltherwise>
<xsl:call-template name="myTemplate">
<xsl:with-param name="value" select="./text()"/>
</xsl:call-template>
</xsltherwise>
</xsl:for-each>
But this requires me to change every call to myTemplate,
which is alot of code. Can't i change myTemplate so
it works?
Who can help me? Please..