节点名称上的 XPath 通配符 [英] XPath wildcards on node name

查看:41
本文介绍了节点名称上的 XPath 通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的 XML 文件中获取一个节点,该节点有一个前缀,例如latest_",但这可能会改变,我希望我的 XSLT 尽可能流畅.这是我要使用的 XPath:

I want to grab a node from my XML file, the node has a prefix such as "latest_", but this may change and I'm keen for my XSLT to be as fluid as possible. Here's the XPath I want to use:

/data/stats/*_cost

这应该匹配latest_costnewest_costanything_cost,有没有办法做到这一点?

This should match latest_cost, newest_cost, anything_cost, is there a way of doing this?

干杯:-)

推荐答案

这是正确的 XPath 1.0 表达式,它在任何命名空间中选择名称的最后 5 个字符等于_cost"的元素.

This is the correct XPath 1.0 expression which selects an element with the last 5 character of name equal to "_cost" in any namespace.

/data/stats/*[substring(name(), string-length(name()) - 4) = '_cost']

这篇关于节点名称上的 XPath 通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆