在Xquery

时间:2015-07-25 19:59:59

标签: xml xquery

我的XML数据库示例如下:

<releases>
<release id="1" status="Accepted">
    <artists>
      <artist>
        <id>1</id><name>Persuader, The</name><anv></anv><join></join><role></role><tracks></tracks></artist></artists><title>Stockholm</title><labels>
      <label catno="SK032" name="Svek"></label></labels><extraartists>
      <artist>
        <id>239</id><name>Jesper Dahlbäck</name><anv></anv><join></join><role>Music By [All Tracks By]</role><tracks></tracks></artist></extraartists><formats>
      <format name="Vinyl" qty="2" text="">
        <descriptions>
          <description>12"</description><description>33 ⅓ RPM</description></descriptions></format></formats><genres>
      <genre>Electronic</genre></genres><styles>
      <style>Deep House</style></styles><country>Sweden</country><released>1999-03-00</released><notes>The song titles are the names of Stockholm's districts.</notes><master_id>5427</master_id><data_quality>Complete and Correct</data_quality><tracklist>
      <track>
        <position>A</position><title>Östermalm</title><duration>4:45</duration></track><track>
        <position>B1</position><title>Vasastaden</title><duration>6:11</duration></track><track>
        <position>B2</position><title>Kungsholmen</title><duration>2:49</duration></track><track>
        <position>C1</position><title>Södermalm</title><duration>5:38</duration></track><track>
        <position>C2</position><title>Norrmalm</title><duration>4:52</duration></track><track>
        <position>D</position><title>Gamla Stan</title><duration>5:16</duration></track></tracklist><identifiers>
      <identifier description="A-Side" type="Matrix / Runout" value="MPO SK 032 A1 G PHRUPMASTERGENERAL T27 LONDON"></identifier><identifier description="B-Side" type="Matrix / Runout" value="MPO SK 032 B1"></identifier><identifier description="C-Side" type="Matrix / Runout" value="MPO SK 032 C1"></identifier><identifier description="D-Side" type="Matrix / Runout" value="MPO SK 032 D1"></identifier></identifiers><videos>
      <video duration="290" embed="true" src="http://www.youtube.com/watch?v=AHuQWcylaU4">
        <title>The Persuader (Jesper Dahlbäck) - Östermalm</title><description>The Persuader (Jesper Dahlbäck) - Östermalm</description></video><video duration="380" embed="true" src="http://www.youtube.com/watch?v=5rA8CTKKEP4">
        <title>The Persuader - Vasastaden</title><description>The Persuader - Vasastaden</description></video><video duration="335" embed="true" src="http://www.youtube.com/watch?v=QVdDhOnoR8k">
        <title>The Persuader-Stockholm-Sodermalm</title><description>The Persuader-Stockholm-Sodermalm</description></video><video duration="289" embed="true" src="http://www.youtube.com/watch?v=hy47qgyJeG0">
        <title>The Persuader - Norrmalm</title><description>The Persuader - Norrmalm</description></video></videos><companies>
      <company>
        <id>271046</id><name>The Globe Studios</name><catno></catno><entity_type>23</entity_type><entity_type_name>Recorded At</entity_type_name><resource_url>http://api.discogs.com/labels/271046</resource_url></company><company>
        <id>56025</id><name>MPO</name><catno></catno><entity_type>17</entity_type><entity_type_name>Pressed By</entity_type_name><resource_url>http://api.discogs.com/labels/56025</resource_url></company></companies></release><release id="2" status="Accepted">
    <artists>
      <artist>
        <id>2</id><name>Mr. James Barth &amp; A.D.</name><anv></anv><join></join><role></role><tracks></tracks></artist></artists><title>Knockin' Boots Vol 2 Of 2</title><labels>
      <label catno="SK 026" name="Svek"></label><label catno="SK026" name="Svek"></label></labels><extraartists>
      <artist>
        <id>26</id><name>Alexi Delano</name><anv></anv><join></join><role>Producer, Recorded By</role><tracks></tracks></artist><artist>
        <id>27</id><name>Cari Lekebusch</name><anv></anv><join></join><role>Producer, Recorded By</role><tracks></tracks></artist><artist>
        <id>26</id><name>Alexi Delano</name><anv>A. Delano</anv><join></join><role>Written-By</role><tracks></tracks></artist><artist>
        <id>27</id><name>Cari Lekebusch</name><anv>C. Lekebusch</anv><join></join><role>Written-By</role><tracks></tracks></artist></extraartists><formats>
      <format name="Vinyl" qty="1" text="">
        <descriptions>
          <description>12"</description><description>33 ⅓ RPM</description></descriptions></format></formats><genres>
      <genre>Electronic</genre></genres><styles>
      <style>Broken Beat</style><style>Techno</style><style>Tech House</style></styles><country>Sweden</country><released>1998-06-00</released><notes>All joints recorded in NYC (Dec.97).</notes><master_id>713738</master_id><data_quality>Correct</data_quality><tracklist>
      <track>
        <position>A1</position><title>A Sea Apart</title><duration>5:08</duration></track><track>
        <position>A2</position><title>Dutchmaster</title><duration>4:21</duration></track><track>
        <position>B1</position><title>Inner City Lullaby</title><duration>4:22</duration></track><track>
        <position>B2</position><title>Yeah Kid!</title><duration>4:46</duration></track></tracklist><identifiers>
      <identifier description="Side A Runout Etching" type="Matrix / Runout" value="MPO SK026-A -J.T.S.-"></identifier><identifier description="Side B Runout Etching" type="Matrix / Runout" value="MPO SK026-B -J.T.S.-"></identifier></identifiers><videos>
      <video duration="365" embed="true" src="http://www.youtube.com/watch?v=MXqC4-ei_zE">
        <title>Mr. james Barth &amp; Alexi Delano</title><description>Mr. james Barth &amp; Alexi Delano</description></video><video duration="260" embed="true" src="http://www.youtube.com/watch?v=FWkM_3MQKZk">
        <title>'Dutchmaster' - Mr. James Barth &amp; A.D. (knockin' boots vol 2)</title><description>'Dutchmaster' - Mr. James Barth &amp; A.D. (knockin' boots vol 2)</description></video></videos><companies>
      <company>
        <id>266169</id><name>JTS Studios</name><catno></catno><entity_type>29</entity_type><entity_type_name>Mastered At</entity_type_name><resource_url>http://api.discogs.com/labels/266169</resource_url></company><company>
        <id>56025</id><name>MPO</name><catno></catno><entity_type>17</entity_type><entity_type_name>Pressed By</entity_type_name><resource_url>http://api.discogs.com/labels/56025</resource_url></company></companies></release></releases>

我正在尝试使用XQuery获取标题列表,其中标题与发布/艺术家/艺术家/名称相同。我正在尝试使用以下代码:

let $r := db:open("releases1","releases.xml") return
for $b in $r/releases/release
let $a := 
          for $t in $r/releases/release/artists
          where $t/artist/name/text() = $b/title/text()
          return $t
 return $b/title

然而,我的结果却是错误的。我做错了什么

输出如下:

<title>Stockholm</title>
<title>Knockin' Boots Vol 2 Of 2</title>
<title>Profound Sounds Vol. 1</title>
<title>Moving Cities</title>
<title>Flowerhead</title>
<title>Knockin' Boots (Vol 1 Of 2)</title>
<title>Moonchildren EP</title>.......50,000

我收到了50,000 / 50,000的结果。这是不可能的。 &#34;斯德哥尔摩&#34;是上述的标题。然而,艺术家&#39;名字不匹配。不应该包括这个结果。

1 个答案:

答案 0 :(得分:0)

没有必要将FLWOR表达式嵌入另一个表达式中。

for $t in db:open("releases1","releases.xml")/releases/release/artists
      where $t/artist/name = $t/../title
      return $t