xquery 按字母顺序按组名创建联系人列表
我有一个带有条目元素的 xml。每个条目都有一个作者。我试图以这样的方式对条目进行分组,使得每个组都包含作者姓名以唯一字母字符开头的条目。所有作者姓名以字母“a”开头的条目都应该在一个组中,所有作者姓名以字母“b”开头的条目应该在另一组中,依此类推。
let $feeds :=
<feed>
<entry>
<author>a</author>
<title>Title a</title>
</entry>
<entry>
<author>b</author>
<title>Title ba</title>
</entry>
<entry>
<author>ab</author>
<title>Title ab</title>
</entry>
<entry>
<author>bb</author>
<title>Title bb</title>
</entry>
</feed>
for $entry in $feeds/entry
let $author := $entry/author
order by $author ascending
return
$entry
返回的结果:
<entry>
<author>a</author>
<title>Title a</title>
</entry>, <entry>
<author>ab</author>
<title>Title ab</title>
</entry>, <entry>
<author>b</author>
<title>Title ba</title>
</entry>, <entry>
<author>bb</author>
<title>Title bb</title>
</entry>
我正在尝试调整代码,返回的结果看起来像这样:
<group>
<author-group>
<entry>
<author>a</author>
<title>Title a</title>
</entry>, <entry>
<author>ab</author>
<title>Title ab</title>
</entry>
</author-group>
<author-group>
<entry>
<author>b</author>
<title>Title ba</title>
</entry>, <entry>
<author>bb</author>
<title>Title bb</title>
</entry>
</author-group>
<group>
在我的示例中,预计有两个作者组 - 第一个作者组由姓名以 a 开头的所有作者组成,第二个作者组由姓名以 b 开头的所有作者组成
我想忽略作者姓名中的大小写,即 aa 和 Aa 是视为相同。
然后我会为每个作者组创建一个联系人列表。
谢谢, 索尼
I have an xml with entry elements. Each entry has an author. I am trying to group the entries in such a manner such that each group consists of entries whose author name starts with a unique alphabetic character. All entries whose author names start with letter 'a' should be in one group, all entries whose authors whose names start with letter 'b' should be in another group, and so on..
let $feeds :=
<feed>
<entry>
<author>a</author>
<title>Title a</title>
</entry>
<entry>
<author>b</author>
<title>Title ba</title>
</entry>
<entry>
<author>ab</author>
<title>Title ab</title>
</entry>
<entry>
<author>bb</author>
<title>Title bb</title>
</entry>
</feed>
for $entry in $feeds/entry
let $author := $entry/author
order by $author ascending
return
$entry
Returned Result:
<entry>
<author>a</author>
<title>Title a</title>
</entry>, <entry>
<author>ab</author>
<title>Title ab</title>
</entry>, <entry>
<author>b</author>
<title>Title ba</title>
</entry>, <entry>
<author>bb</author>
<title>Title bb</title>
</entry>
I am trying to tweak around the code such that the returned result looks something like so:
<group>
<author-group>
<entry>
<author>a</author>
<title>Title a</title>
</entry>, <entry>
<author>ab</author>
<title>Title ab</title>
</entry>
</author-group>
<author-group>
<entry>
<author>b</author>
<title>Title ba</title>
</entry>, <entry>
<author>bb</author>
<title>Title bb</title>
</entry>
</author-group>
<group>
In my example, two author groups are expected - First author group consisting of all authors whose names start with a, second author group consisting of all authors whose names start with b
I would like to ignore cases in author names i.e. aa and Aa are treated as same.
I would then take each author group and create a contact list.
Thanks,
Sony
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此 XQuery 转换:
应用于提供的 XML 文档时:
产生所需的正确结果:
This XQuery transformation:
when applied on the provided XML document:
produces the wanted, correct result:
这是 XQuery 1.0 解决方案:
HTH
Here an XQuery 1.0 solution:
HTH