I'm trying to write a XSLT1.0 template that accepts a node as parameter. Inside that template, I need to test if the node passed as parameter is of particular type, in my case a text node. I can check the type of the current node via self::text()
and similar constructs, but how do I do that when the node in question is given by a variable?
Here's a piece of code that actually does what I need, but I think there must be a more straightforward way to achieve that. This $node/../text()
does not seem right to me, to say the least.
<xsl:template name="renderCommand">
<xsl:param name="node"/>
<xsl:variable name="nodeName">
<xsl:choose>
<xsl:when test="$node/../text()">
<xsl:value-of select="name($node)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('.', name($node))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
</xsl:template>