<?xml version="1.0"?>
<!--以下代码摘自XSLTSL工程-->
<!--在XSLT中判断XML文档的结点类型 -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
xmlns:node="http://xsltsl.org/node"
extension-element-prefixes="doc node">
<xsl:template name="node:type">
<xsl:param name="node" select="."/>
<xsl:choose>
<xsl:when test="not($node)"/>
<!------------------------------------------------------------------->
<!--运用了self轴-->
<xsl:when test="$node[1]/self::*"> <!--元素结点-->
<xsl:text>element</xsl:text>
</xsl:when>
<xsl:when test="$node[1]/self::text()"> <!--文本结点-->
<xsl:text>text</xsl:text>
</xsl:when>
<xsl:when test="$node[1]/self::comment()"> <!--注释结点-->
<xsl:text>comment</xsl:text>
</xsl:when>
<xsl:when test="$node[1]/self::processing-instruction()"> <!--处理指令结点-->
<xsl:text>processing instruction</xsl:text>
</xsl:when>
<xsl:when test="not($node[1]/parent::*)"> <!--根结点-->
<xsl:text>root</xsl:text>
</xsl:when>
<!--下面两种类型的判断巧妙运用了集合的概念-->
<xsl:when test="count($node[1] | $node[1]/../namespace::*) = count($node[1]/../namespace::*)">
<xsl:text>namespace</xsl:text>
</xsl:when>
<xsl:when test="count($node[1] | $node[1]/../@*) = count($node[1]/../@*)">
<xsl:text>attribute</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>