XPath:如何检查相似节点的多个属性
如果我有一些像这样的xml:
<root>
<customers>
<customer firstname="Joe" lastname="Bloggs" description="Member of the Bloggs family"/>
<customer firstname="Joe" lastname="Soap" description="Member of the Soap family"/>
<customer firstname="Fred" lastname="Bloggs" description="Member of the Bloggs family"/>
<customer firstname="Jane" lastname="Bloggs" description="Is a member of the Bloggs family"/>
</customers>
</root>
如何在纯XPath(而不是XSLT)中获得一个xpath表达式来检测姓氏相同但具有不同描述的行?那么它会拉出上面的最后一个节点吗?
If I have some xml like:
<root>
<customers>
<customer firstname="Joe" lastname="Bloggs" description="Member of the Bloggs family"/>
<customer firstname="Joe" lastname="Soap" description="Member of the Soap family"/>
<customer firstname="Fred" lastname="Bloggs" description="Member of the Bloggs family"/>
<customer firstname="Jane" lastname="Bloggs" description="Is a member of the Bloggs family"/>
</customers>
</root>
How do I get, in pure XPath - not XSLT - an xpath expression that detects rows where lastname is the same, but has a different description? So it would pull the last node above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是如何使用单个 XPath 表达式执行此操作:
此表达式选择属性
lastname
等于“Bloggs”的所有
元素,并且属性description
的不同值。选定的节点是:
Here's how to do this with a single XPath expression:
This expression selects all
<customer>
elements with attributelastname
equal to "Bloggs" and different value of the attributedescription
.The selected nodes are:
不过,分步进行会表现得更好。
It would perform better doing it in steps, though.