XPATH 匹配函数问题——有效但无效
我正在使用 Eclipse 运行 XSL 2.0 (XPATH 2.0),并且有以下源:
<testTop>
<Level1 id="abc" Text="from 1-2"/>
<Level1 id="pqr" Text="from 3-44" />
<Level1 id="xyz" Text="from 49-101" />
</testTop>
当我在 Eclipse 中测试以下表达式时,//*[matches(@Text, '\d+-\d+' )]
我得到了正确的节点,但不是 Text 属性本身
Level1 ID=abc
Level1 ID=pqr
Level1 ID=xyz
...而 //@Text
给了我 Text 属性。谁能帮我理解为什么?我想获取 Text 属性值并使用字符串函数解析它们。最终结果应该如下所示:
我不应该得到所有属性吗?每个节点匹配的部分?
I'm using Eclipse to run an XSL 2.0 (XPATH 2.0), and I have the following source:
<testTop>
<Level1 id="abc" Text="from 1-2"/>
<Level1 id="pqr" Text="from 3-44" />
<Level1 id="xyz" Text="from 49-101" />
</testTop>
When I test the following expression in Eclipse, //*[matches(@Text, '\d+-\d+')]
I get the right nodes, but not the Text attributes themselves
Level1 ID=abc
Level1 ID=pqr
Level1 ID=xyz
... whereas //@Text
gives me the Text attributes. Can anyone help me to understand why?? I'd like to get the Text attribute values and parse them using string functions. THE END RESULT SHOULD LOOK LIKE THIS:
<output originalText="from 1-2" value1="1" value2="2" />
Shouldn't I be getting all the attributes that are part of each node that matched?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 XPath 正在选择具有您想要的属性的元素。如果您想选择与您的模式匹配的
@Text
,您需要调整 XPath 以选择属性而不是元素。您可以使用此 XPath:
或此 XPath:
Your XPath is selecting the elements that have the attributes you want. If you want to select the
@Text
that match your pattern, you need to adjust your XPath to select the attributes rather than the element.You could use this XPath:
or this XPath: