【问题标题】:concatenation of one value with multiple values from another xquery一个值与来自另一个 xquery 的多个值的连接
【发布时间】:2021-03-08 15:16:59
【问题描述】:

嘿嘿。我是 XML 查询的新手,在寻找将两个 xquery 的结果合二为一的方法时遇到了一些问题。

考虑 XML:

<programs>
    <program id="488">
        <editor>Anna</editor>
        <channel>132</channel>
        <category>5</category>
    </program>
    <program id="178">
        <editor>Olle</editor>
        <channel>132</channel>
        <category>68</category>
    </program>
    <program id="179">
        <editor>Olle</editor>
        <channel>132</channel>
        <category>10</category>
    </program>
</programs>

我想提取编辑器列表以及他们处理过的类别,如下所示:

    <li>Anna 5 </li>
    <li>Olle 68 10</li>

这是我正在使用的 xquery 代码

                    let $editors :=
                        for $d in $sr/sr/programs/program
                        where $d/channel = "132"
                        return $d/editor
                    let $cat :=
                        for $a in $sr/sr/programs/program
                        where $a/editor = data($editors)
                        return concat($a/editor ,' ', $a/category)
                    for $result in distinct-values($cat)
                    return <li>{string($result)}</li>

感谢所有帮助!

【问题讨论】:

  • 您使用的是 XQuery 1 还是 3?

标签: xquery


【解决方案1】:

我会遍历不同的编辑器列表,从 XPath 中获得一个谓词,以限制channel 等于 132 的那些编辑器,然后为那些具有类似 XPath 和谓词过滤器的编辑器检索一个不同的类别列表,然后返回带有这些值的 HTML:

for $editor in distinct-values($sr/sr/programs/program[channel eq 132]/editor)
let $categories := 
  distinct-values($sr/sr/programs/program[channel eq 132 and editor eq $editor]/category)
return <li>{$editor, $categories}</li>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多