xml – 如何在XSL / XPath中按部分名称选择元素?

如何使用apply-templates仅按名称(非值)选择以特定模式结尾的元素?假设以下xml …
<report>
  <report_item>
    <report_created_on/>
    <report_cross_ref/>
    <monthly_adj/>
    <quarterly_adj/>
    <ytd_adj/>
  </report_item>
  <report_item>
   ....
  </report_item>
</report>

我想使用< xsl:apply-templates>在< report_item>的所有实例上其中,后代元素以’adj`结尾,因此,在这种情况下,只选择monthly_adj,quaterly_adj和ytd_adj并将其与模板一起应用.

<xsl:template match="report">
   <xsl:apply-templates select="report_item/(elements ending with 'adj')"/>
</xsl:template>
我不认为正则表达式语法在这种情况下是可用的,即使在XSLT 2.0中也是如此.但在这种情况下你不需要它.
<xsl:apply-templates select="report_item/*[ends-with(name(),'adj')]"/>

*匹配任何节点

[pred]对选择器执行节点测试(在本例中为*)(其中pred是在所选节点的上下文中评估的谓词)

name()返回元素的标记名称(为此目的,应该等同于local-name).

ends-with()是一个内置的XPath字符串函数.

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念