XSLT模板模式-xpath计算
我希望根据源XML的属性动态更改应用模板模式,如下所示:XSLT模板模式-xpath计算,xslt,xpath,Xslt,Xpath,我希望根据源XML的属性动态更改应用模板模式,如下所示: <xsl:choose> <xsl:when test="@myAttribute"> <xsl:apply-templates select="." mode="@myAttribute"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="." mo
<xsl:choose>
<xsl:when test="@myAttribute">
<xsl:apply-templates select="." mode="@myAttribute"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="someOtherMode"/>
</xsl:otherwise>
</xsl:choose>
是否可以在mode属性中计算XPath?还有别的办法吗
谢谢 不,没有办法为
模式
属性使用动态值。它必须是静态的。在您的情况下,我建议您这样做(使用名称myNode作为上述示例的上下文节点):
<xsl:template match="myNode[@myAttribute = 'someValue']" mode="specialHandling">
<!-- template contents -->
</xsl:template>
<xsl:template match="myNode[@myAttribute = 'someOtherValue']" mode="specialHandling">
<!-- template contents -->
</xsl:template>
<xsl:template match="myNode[@myAttribute = 'aThirdValue']" mode="specialHandling">
<!-- template contents -->
</xsl:template>
<xsl:template match="myNode[not(@myAttribute)]" mode="specialHandling">
<!-- template contents -->
</xsl:template>
<xsl:apply-templates select="." mode="specialHandling" />