xml – 如何在XSL / XPath中按部分名称选择元素?
发布时间:2020-12-16 07:41:09 所属栏目:百科 来源:网络整理
导读:如何使用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:appl
如何使用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字符串函数. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |