When using XSLT how does one test to see if a variable has a value? Or more specifically, how do you properly nest the xsl:value-of method below so that it returns '' rather than failing to transform, when a value has not been assigned?
Declaration options could potentially be either...
<xsl:variable name="ID" select="//MessageID"/>
<xsl:variable name="ID" select=""/>
What needs to be added to this so that it does not to fail the transform?
<Container>
<xsl:attribute name="ID" select="$ID"/>
</Container>
Desired output:
<Container ID=""/>
Currently, the transform will fail if the variable's select statement does not find the referenced node.
I have tried several different approaches:
<xsl:if test="$ID"><xsl:value-of select="$ID"/></xsl:if>
<xsl:if test="string-length($ID)>0"><xsl:value-of select="$ID"/></xsl:if>
<xsl:if test="count($ID)>0"><xsl:value-of select="$ID"/></xsl:if>
<xsl:if test="($ID) !=''"><xsl:value-of select="$ID"/></xsl:if>
and I have even attempted declaring an empty variable for comparison:
<xsl:variable name="empty_string"/>
<xsl:if test="($ID) != $empty_string"><xsl:value-of select="$ID"/></xsl:if>
I find this question to be very similar, but distinctly different than: In XSLT how do you test to see if a variable exists?