i have repeat following xslt snippet 100 times , small possible. there way make equivalent xslt snippet shorter?
<xslo:variable name="myvariable" select="//this/that/anotherthing" /> <xslo:choose> <xslo:when test="string($myvariable) != 'nan'"> <xslo:text>1</xslo:text> </xslo:when> <xslo:otherwise> <xslo:text>0</xslo:text> </xslo:otherwise> </xslo:choose> i'm setting state of checkbox based on whether or not value exists in //this/that/anotherthing in source xml.
can xslt 1.0 or xslt 2.0, doesn't matter.
you can use if instead of xsl:choose (xslt 2.0 only)...
<xsl:value-of select="if (string(number(//this/that/anotherthing)) = 'nan') 0 else 1"/> i dropped xsl:variable, if need other reason, can put back.
you create function...
<xsl:function name="local:isnumber"> <xsl:param name="context"/> <xsl:value-of select="if (string(number($context)) = 'nan') 0 else 1"/> </xsl:function> usage...
<xsl:value-of select="local:isnumber(//this/that/anotherthing)"/>
Comments
Post a Comment