如何使用XPath匹配以数字结尾的字符串 [英] How to match string that ends with a number using XPath

查看:660
本文介绍了如何使用XPath匹配以数字结尾的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是我正在构建一个XPath表达式,以获取具有属性XXX的节点,其值为TP *,其中星号是数字。
假设我有这个XML文件

The issue is that I'm looking to construct an XPath expression to get nodes having attributes XXX having values like TP* where the star is a number. Suppose I have this XML file

<tagA attA="VAL1">text</tagA>
<tagB attB="VAL333">text</tagB>
<tagA attA="VAL2">text</tagA>
<tagA attA="V2">text</tagA>

所以xpath表达式应该让我全部 tagA 具有属性 attrA ,其值为 VAL *

// tagA [@attrA [matches('VAL\d')]] :不工作

So the xpath expression should get me all tagA having attribute attrA with values with the pattern VAL*
//tagA[@attrA[matches('VAL\d')]] : is not working

请帮忙吗?

推荐答案

如果您需要XPath 1.0解决方案,请尝试以下:

If you need XPath 1.0 solution, try below:

//tagA[boolean(number(substring-after(@attA, "VAL"))) or number(substring-after(@attA, "VAL")) = 0]

如果 @attA 不能 VAL0,然后只是

//tagA[boolean(number(substring-after(@attA, "VAL")))]

这篇关于如何使用XPath匹配以数字结尾的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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