You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在XPath 1.0中判断属性值是否以2结尾?

XPath 1.0 实现需求的表达式

直接使用以下XPath即可满足你的要求:

/node[newused[1] != "New" and sellingprice[1][string-length(.) >= 4 and string-length(.) <= 6 and substring(., string-length(.), 1) = "2"]]

关键逻辑说明

  • 模拟ends-with功能:在XPath 1.0里,通过substring(., string-length(.), 1)提取目标字符串的最后一位字符,再判断是否等于"2"。其中string-length(.)用于获取当前sellingprice节点文本的长度,substring函数从该长度对应的位置开始截取1个字符,也就是字符串的最后一位。
  • 长度范围限制:用string-length(.) >= 4 and string-length(.) <= 6确保文本长度在4-6位之间。
  • 原有条件保留:保留了你原表达式中newused[1] != "New"的判断逻辑。

内容的提问来源于stack exchange,提问作者user21174586

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 02:55:38