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模板优先级的概述/参考资料吗
提前谢谢 中描述了完整解析过程 通常,以下规则按顺序适用(例如,由于导入优先级较低而被排除在考虑之外的模板将被永久排除,无论其优先级如何):
优先级
属性中具有较高值的模板具有较高的优先级优先级
属性的模板将被指定默认优先级。具有更具体模式的模板优先<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