XQuery 多个 xml 文件? [英] XQuery multiple xml files?

查看:26
本文介绍了XQuery 多个 xml 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从 xQuery 打开 2 个文档并对它们进行连接?

Is it possible to open 2 documents from an xQuery and do a join on them?

推荐答案

是的,这里是 一个例子来自XQuery规范.:

Yes, here is an example from the XQuery spec.:

"Joins 将来自多个源的数据组合成单个结果,是一种非常重要的查询类型.在本节中,我们将说明如何在 XQuery 中表示几种类型的连接.我们将基于以下示例三个文件:

"Joins, which combine data from multiple sources into a single result, are a very important type of query. In this section we will illustrate how several types of joins can be expressed in XQuery. We will base our examples on the following three documents:

  1. 一个名为 parts.xml 的文档,其中包含许多 part 元素;每个 part 元素依次包含 partnodescription 子元素.
  2. 一个名为 suppliers.xml 的文档,其中包含许多 supplier 元素;每个 supplier 元素依次包含 suppnosuppname 子元素.
  3. 名为 catalog.xml 的文档,其中包含有关供应商和零件之间关系的信息.目录文档包含许多item 元素,每个元素又包含partnosuppnoprice 子元素.
  1. A document named parts.xml that contains many part elements; each part element in turn contains partno and description subelements.
  2. A document named suppliers.xml that contains many supplier elements; each supplier element in turn contains suppno and suppname subelements.
  3. A document named catalog.xml that contains information about the relationships between suppliers and parts. The catalog document contains many item elements, each of which in turn contains partno, suppno, and price subelements.

常规(内部")联接返回来自两个或多个相关源的信息,如下面的示例所示,该示例组合了来自三个文档的信息.该示例生成从目录文档派生的描述性目录",但包含零件描述而不是零件编号和供应商名称而不是供应商编号.新目录按零件描述的字母顺序排列,然后按供应商名称排列.*

A conventional ("inner") join returns information from two or more related sources, as illustrated by the following example, which combines information from three documents. The example generates a "descriptive catalog" derived from the catalog document, but containing part descriptions instead of part numbers and supplier names instead of supplier numbers. The new catalog is ordered alphabetically by part description and secondarily by supplier name.*

<descriptive-catalog>
   { 
     for $i in fn:doc("catalog.xml")/items/item,
         $p in fn:doc("parts.xml")/parts/part[partno = $i/partno],
         $s in fn:doc("suppliers.xml")/suppliers
                  /supplier[suppno = $i/suppno]
     order by $p/description, $s/suppname
     return
        <item>
           {
           $p/description,
           $s/suppname,
           $i/price
           }
        </item>
   }
</descriptive-catalog>

上一个查询仅返回有关有供应商的零件和有零件的供应商的信息.外连接是一种连接,它保留来自一个或多个参与源的信息,包括在另一个源中没有匹配元素的元素.例如,供应商和零件之间的左外连接可能会返回有关没有匹配零件的供应商的信息."

The previous query returns information only about parts that have suppliers and suppliers that have parts. An outer join is a join that preserves information from one or more of the participating sources, including elements that have no matching element in the other source. For example, a left outer join between suppliers and parts might return information about suppliers that have no matching parts."

请注意 XQuery 没有标准的 document() 函数(它是一个 XSLT 函数),而是具有 doc() 函数,它是XQuery 1.0 和 XPath 2.0 函数和运算符".

克里斯的回答至少有两个错误:

  1. XQuery 区分大小写 --符合标准的 XQuery 处理器将不允许 Chris 示例中使用的大写关键字.
  2. 没有必要像 doc() 那样为标准函数加上前缀,我只是引用了 XQuery 规范,它有前缀.否则,在我自己的代码中,我会省略fn"前缀.
  3. 函数 document() 不是标准的 XQuery/XPath 函数.doc() 函数应该是改为使用.
  1. XQuery is case sensitive -- the capitalised keywords used in Chris' example will not be allowed by a conforming XQuery processor.
  2. It is not necessary to prefix the standard functions like doc(), I am just quoting the XQuery spec, which has the prefix. Otherwise, in my own code I would omit the "fn" prefix.
  3. The function document() is not a standard XQuery/XPath function. The doc() function should be used instead.

这篇关于XQuery 多个 xml 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆