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
Xslt XSL模板优先级_Xslt_Operator Precedence - Fatal编程技术网

Xslt XSL模板优先级

Xslt XSL模板优先级,xslt,operator-precedence,Xslt,Operator Precedence,我有两个模板 <template match="vehicle_details[preceding-sibling::vehicle_type = '4x4']/*"> ... </xsl:template> <xsl:template match="vehicle_details[descendant::color = 'red']/*" > ... </xsl:template> ... ... 我的问题是:哪个模板将优先

我有两个模板

<template match="vehicle_details[preceding-sibling::vehicle_type = '4x4']/*">
    ...
</xsl:template>
<xsl:template match="vehicle_details[descendant::color = 'red']/*" >
    ...
</xsl:template>

...
...
我的问题是:哪个模板将优先于转换。有人能给我一个关于XSL模板优先级的概述/参考资料吗


提前谢谢

中描述了完整解析过程

通常,以下规则按顺序适用(例如,由于导入优先级较低而被排除在考虑之外的模板将被永久排除,无论其优先级如何):

  • 导入的模板的优先级低于主样式表中的模板
  • 优先级
    属性中具有较高值的模板具有较高的优先级
  • 没有
    优先级
    属性的模板将被指定默认优先级。具有更具体模式的模板优先
  • 如果前面三个步骤考虑了多个模板,那么这是一个错误,但是XSLT处理器可以通过默认设置为文件中的最后一个模板来恢复
  • 在您的特定情况下,两个模板具有相同的优先级,因此上述第4条适用。证明:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match=
                 "vehicle_details[preceding-sibling::vehicle_type = '4x4']/*">
            template1
        </xsl:template>
        <xsl:template match="vehicle_details[descendant::color = 'red']/*">
            template2
        </xsl:template>
    </xsl:stylesheet>
    
    但是如果我们交换模板的顺序:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="vehicle_details[descendant::color = 'red']/*">
            template2
        </xsl:template>
        <xsl:template match=
                 "vehicle_details[preceding-sibling::vehicle_type = '4x4']/*">
            template1
        </xsl:template>
    </xsl:stylesheet>
    

    一个好的解释必须绝对清楚地说明,导入优先级和
    优先级
    是两件不同的事情,无论导入的样式表中的模板优先级有多高,其优先级都低于导入样式表中任何模板的优先级。@Dimitre-我打算按顺序读取规则。也许这还不清楚。我补充了一点解释。+1正确答案。观察:依赖错误恢复机制是不好的做法。对优先级值很重要(!):最大“默认优先级”为0.5,因此您可以使用1、2等作为4。上图:是否可以要求对此类冲突和冲突候选人进行详细说明?这将是一个有用的调试功能。
    template2
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="vehicle_details[descendant::color = 'red']/*">
            template2
        </xsl:template>
        <xsl:template match=
                 "vehicle_details[preceding-sibling::vehicle_type = '4x4']/*">
            template1
        </xsl:template>
    </xsl:stylesheet>
    
    template1