Is it possible to check the type of a node I matched with a template inside the same template? In case it is, how can I do it? For example I would like to do something like this:
<xsl:template match="@*|node()">
<xsl:choose>
<xsl:when test="current() is an attribute">
<!-- ... -->
</xsl:when>
<xsl:when test="current() is an element">
<!-- ... -->
</xsl:when>
<xsl:otherwise>
<!-- ... -->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Take a look at this answer here, as this should give you the information you need:
Difference between: child::node() and child::*
This gives the following xsl:choose to test all the nodes, including the document node.
A more precise way to determine if the node
$node
is a root node:The expression in TimC's answer tests the type of the current node:
but isn't applicable in the case when we want to determine the type of a node in a variable -- which may belong to another document -- not to the current document.
Also, a test for a namespace node:
I highly recommend you to use the expressions on sequence types introduced in XPath 2.0. For example: