如何使用 XPath 3.0 查找每个非唯一 ID 的最新日期?
我第一次自己在这里发帖,而不是搜索现有的答案。想尝试一下,以防我对更具体问题的需求增加。
所以我想编写一个 XPath 3.0 查询来从每个
我的 XML 如下所示:
<Flows>
<Flow>
<ID>172</ID>
<Name>Name 1 version 1</Name>
<Published>2021-09-30</Published>
</Flow>
<Flow>
<ID>172</ID>
<Name>Name 1 version 2</Name>
<Published>2022-01-15</Published>
</Flow>
<Flow>
<ID>287</ID>
<Name>Name 2 version 1</Name>
<Published>2022-01-14</Published>
</Flow>
<Flow>
<ID>9</ID>
<Name>Name 3 version 1</Name>
<Published>2021-10-15</Published>
</Flow>
</Flows>
我想要以下输出:
<Name>Name 1 version 2</Name>
<Name>Name 2 version 1</Name>
<Name>Name 3 version 1</Name>
First time I'm posting here myself instead of searching for existing answers. Wanted to try it out in case my demand for more specific questions increases.
So I want to write an XPath 3.0 query to extract all the names from each <Flow>, but if there is multiple <Flow> with the same ID, I only want to return the name of the one with the more recent date, <Published>.
My XML looks like this:
<Flows>
<Flow>
<ID>172</ID>
<Name>Name 1 version 1</Name>
<Published>2021-09-30</Published>
</Flow>
<Flow>
<ID>172</ID>
<Name>Name 1 version 2</Name>
<Published>2022-01-15</Published>
</Flow>
<Flow>
<ID>287</ID>
<Name>Name 2 version 1</Name>
<Published>2022-01-14</Published>
</Flow>
<Flow>
<ID>9</ID>
<Name>Name 3 version 1</Name>
<Published>2021-10-15</Published>
</Flow>
</Flows>
And I want the following output:
<Name>Name 1 version 2</Name>
<Name>Name 2 version 1</Name>
<Name>Name 3 version 1</Name>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将返回所有名称,其中日期等于给定 ID
注释的最大值,如果有多个 Flow 元素具有相同的 ID 和最大日期,它将返回所有名称
this would return all the names, where the date equals the max for a given ID
note, that in case there are multiple Flow elements with the same ID, and the max date, it would return all of them