将简单的 XPath 查询转换为 E4X 查询
人们可能会认为 XPath 查询的相应 E4X 查询 //*[@foo = "bar"]
将是 ..*.(@foo == "bar")< /code>,但是每当它到达没有 foo 属性的元素时就会抛出错误。我目前正在使用
..*.(function::valueOf().@foo == "bar")
代替。
我的问题是是否有另一种更简单的方法来做到这一点。
One might think the corresponding E4X query for the XPath query, //*[@foo = "bar"]
, would be ..*.(@foo == "bar")
, but that will throw an error whenever it gets to an element without a foo attribute. I am currently using ..*.(function::valueOf().@foo == "bar")
instead.
My question is if there is another, less of a hack-way to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
稍微不那么hacky的方法可能是使用attribute函数:
..*.(function::attribute("foo") == "bar")
little bit less hacky way might be using the attribute function:
..*.(function::attribute("foo") == "bar")