查找以特定模式开头的属性名称 [英] Find attribute names that start with a certain pattern
问题描述
我正在寻找匹配特定模式的元素的所有属性.
I am looking to find all attributes of an element that match a certain pattern.
所以对于一个元素
<element s2="1" name="aaaa" id="1" />
<element s3="1" name="aaaa" id="2" />
我希望能够找到所有以 's' 开头的属性(返回 s1 的第一个元素的值和 s3 的值第二个元素).
I would like to be able to find all attributes that start with 's' (returning the value of s1 for the first element and s3 for the value of the second element).
如果这超出了 xpath 的能力,请告诉我.
If this is outside of xpath's ability please let me know.
推荐答案
使用:
element/@*[starts-with(name(), 's')]
此 XPath 表达式选择名称以字符串 's'
开头的所有属性节点,并且这些节点是名为 element
的元素的属性,这些元素是当前节点的子节点.
This XPath expression selects all atribute nodes whose name starts with the string 's'
and that are attributes of elements named element
that are children of the current node.
starts-with()
是 XPath 1.0 中的标准函数
starts-with()
is a standard function in XPath 1.0
这篇关于查找以特定模式开头的属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!