我的XSLT中有一个参数,它通常是我在其上应用模板的一组适当的节点。
<apply-templates select="$conferences" />
然而,有时会出现问题,它会以字符串的形式出现。在这种情况下,我只想跳过应用模板。但是正确的检验方法是什么呢?当然我可以检查它是不是字符串,但是我怎么检查参数是不是。"模板化"?
<if test=" ? ">
<apply-templates select="$conferences" />
</if>
由于您使用的是XSLT 2.0,因此可以简单地执行
<xsl:if test="$conferences instance of node()*">
你可以这样做:
<apply-templates select="$conferences/*" />
只适用于包含XML的情况。字符串将不被应用。
如果您想预先执行一个条件,请执行如下操作:
<xsl:choose>
<xsl:when test="count($conferences/*) > 0"> <!-- it is XML -->
<xsl:apply-templates select="$conferences/*" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$conferences" /> <!-- it is not XML -->
</xsl:otherwise>
</xsl:choose>