XSL 模板优先级
我有 2 个模板
<template match="vehicle_details[preceding-sibling::vehicle_type = '4x4']/*">
...
</xsl:template>
<xsl:template match="vehicle_details[descendant::color = 'red']/*" >
...
</xsl:template>
我的问题是:哪个模板将优先进行转换。有人可以给我有关 XSL 模板优先级的概述/资源吗?
提前致谢!
I have 2 Templates
<template match="vehicle_details[preceding-sibling::vehicle_type = '4x4']/*">
...
</xsl:template>
<xsl:template match="vehicle_details[descendant::color = 'red']/*" >
...
</xsl:template>
My question is: which template will take precedence on transformation. And can someone give me an overview/resources about XSL template precedence?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XSLT 规范第 5.5 节描述了完整的解决过程。
一般来说,以下规则按顺序适用(例如,由于导入优先级较低而从考虑中排除的模板将被永久删除,无论其优先级如何):
priority
属性的模板将被分配默认优先级。具有更具体模式的模板优先。在您的具体情况下,两个模板具有相同的优先级,因此上面的#4 适用。演示:
应用于此输入(两个模板都匹配):
输出:
但如果我们交换模板的顺序:
那么输出为:
The full resolution process is described in section 5.5 of the XSLT spec.
In general, the following rules apply in order (e.g. a template eliminated from consideration due to lower import precedence is eliminated permanently, regardless of its priority):
priority
attribute have higher precedencepriority
attribute are assigned a default priority. Templates with more specific patterns take precedence.In your specific case both templates have the same priority, so #4 above applies. To demonstrate:
Applied to this input (both templates match):
Output:
But if we swap the order of the templates:
Then the output is: