XML代码重复结果,如何实现不同的值?

时间:2019-03-27 05:37:37

标签: sql xml xquery basex

尝试按价格和发布者代码比较两列。但是结果给了我两倍的答案。尝试使用不同的值来避免重复出现的结果,但会不断出现语法错误

我正在使用BASEx9.2运行XML文件

<results>
  {
    for $e in doc("../henry/Book.xml")//Book,
        $p in doc("../henry/Book.xml")//Book
    where $e/PublisherCode = $p/PublisherCode and $e/Price = $p/Price
          and $e/Title != $p/Title
    return
        <Pair>"{ $e/Title }" - "{ $p/Title }"</Pair>
  }
</results>

我的预期结果是

<results>
  <Pair>"<Title>The Stranger</Title>" - "<Title>The Fall</Title>"</Pair>
  <Pair>"<Title>The Edge</Title>" - "<Title>Slay Ride</Title>"</Pair>
  <Pair>"<Title>Beloved</Title>" - "<Title>Jazz</Title>"</Pair>
  <Pair>"<Title>Nine Stories</Title>" - "<Title>Franny and Zooey</Title>"</Pair>
  <Pair>"<Title>Nine Stories</Title>" - "<Title>The Catcher in the Rye</Title>"</Pair>
  <Pair>"<Title>Franny and Zooey</Title>" - "<Title>The Catcher in the Rye</Title>"</Pair>
</results>

我目前的结果是:

<results>
  <Pair>"<Title>The Stranger</Title>" - "<Title>The Fall</Title>"</Pair>
  <Pair>"<Title>The Edge</Title>" - "<Title>Slay Ride</Title>"</Pair>
  <Pair>"<Title>Beloved</Title>" - "<Title>Jazz</Title>"</Pair>
  <Pair>"<Title>Nine Stories</Title>" - "<Title>Franny and Zooey</Title>"</Pair>
  <Pair>"<Title>Nine Stories</Title>" - "<Title>The Catcher in the Rye</Title>"</Pair>
  <Pair>"<Title>Jazz</Title>" - "<Title>Beloved</Title>"</Pair>
  <Pair>"<Title>Franny and Zooey</Title>" - "<Title>Nine Stories</Title>"</Pair>
  <Pair>"<Title>Franny and Zooey</Title>" - "<Title>The Catcher in the Rye</Title>"</Pair>
  <Pair>"<Title>The Fall</Title>" - "<Title>The Stranger</Title>"</Pair>
  <Pair>"<Title>Slay Ride</Title>" - "<Title>The Edge</Title>"</Pair>
  <Pair>"<Title>The Catcher in the Rye</Title>" - "<Title>Nine Stories</Title>"</Pair>
  <Pair>"<Title>The Catcher in the Rye</Title>" - "<Title>Franny and Zooey</Title>"</Pair>
</results>

1 个答案:

答案 0 :(得分:0)

我认为您首先想按出版商代码和价格将图书分组,例如。

./node_modules/.bin/nightwatch -c local.conf.js --group logingroup --env firefox

然后您要为每个组形成标题对,我想使用一个用于该帮助的功能

<Results>{
for $book in doc("../henry/Book.xml")//Book
group by $pubCode := $book/PublisherCode, $price := $book/Price
return 
  <group pubCode="{$pubCode}" price="{$price}">{$book/title}</group>
}</Result>

因此您将使用

declare function local:pair($seq) {
  (
      if (exists(tail($seq)))
      then
          (tail($seq)!<Pair>"{ head($seq) }" - "{ . }"</Pair>,
           local:pair(tail($seq))
          )
       else ()
  )
};