具有多个条件的 XPath [英] XPath with multiple conditions
本文介绍了具有多个条件的 XPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用什么 XPath 来选择具有指定名称属性的任何类别以及具有指定值的任何子节点作者.
What XPath can I use to select any category with a name attribute specified and any child node author with the value specified.
我尝试了以下路径的不同变体,但均未成功:
I've tried different variations of the path below with no success:
//quotes/category[@name='Sport' and author="James Small"]
XML:
<?xml version="1.0" encoding="utf-8"?>
<quotes>
<category name="Sport">
<author>James Small<quote date="09/02/1985">Quote One</quote><quote date="11/02/1925">Quote nine</quote></author>
</category>
<category name="Music">
<author>Stephen Swann
<quote date="04/08/1972">Quote eleven</quote></author>
</category>
</quotes>
推荐答案
尝试://category[@name='Sport' and ./author/text()='James Small']
这篇关于具有多个条件的 XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文