Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XSLT模板模式-xpath计算_Xslt_Xpath - Fatal编程技术网

XSLT模板模式-xpath计算

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

我希望根据源XML的属性动态更改应用模板模式,如下所示:

<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" />