0
我在分組「表單」標籤時遇到了一些麻煩。有四種類型的表格,每種表格可以有一個以上的作品。儘管我在下面的示例輸出中只顯示了兩種形式。正如你可以在我的輸出中看到的畫作是而不是分組在一起。在期望的輸出他們是。任何幫助或暗示,讓我的頭附近,是值得讚賞的。在XQuery中分組
我的輸出:
<author>
<name>BRAMANTE, Donato</name>
<born-died>b. 1444, Fermignano, d. 1514, Roma</born-died>
<nationality>Italian</nationality>
<biography>Donato Bramante was an Italian architect, who introduced the Early Renaissance style to Milan and the High Renaissance style to Rome, where his most famous design was St. Peter's Basilica.</biography>
<artworks form="painting">
<artwork date="1477">
<form>painting</form>
<artworkForm>painting</artworkForm>
<title>Heraclitus and Democritus</title>
<technique>Fresco transferred to canvas</technique>
<location>Pinacoteca di Brera, Milan</location>
</artwork>
</artworks>
<artworks form="painting">
<artwork date="1477">
<form>painting</form>
<artworkForm>painting</artworkForm>
<title>Heraclitus and Democritus</title>
<technique>Fresco transferred to canvas</technique>
<location>Pinacoteca di Brera, Milan</location>
</artwork>
</artworks>
<artworks form="architecture">
<artwork date="1485">
<form>architecture</form>
<artworkForm>architecture</artworkForm>
<title>Interior view toward choir</title>
<technique>Fresco, height of arch 10,6 m</technique>
<location>Santa Maria presso San Satiro, Milan</location>
</artwork>
</artworks>
</author>
所需的輸出
<author>
<name>BRAMANTE, Donato</name>
<born-died>b. 1444, Fermignano, d. 1514, Roma</born-died>
<nationality>Italian</nationality>
<biography>Donato Bramante was an Italian architect, who introduced the Early Renaissance style to Milan and the High Renaissance style to Rome, where his most famous design was St. Peter's Basilica.</biography>
<artworks form="painting">
<artwork date="1477">
<form>painting</form>
<artworkForm>painting</artworkForm>
<title>Heraclitus and Democritus</title>
<technique>Fresco transferred to canvas</technique>
<location>Pinacoteca di Brera, Milan</location>
</artwork>
<artwork date="1477">
<form>painting</form>
<artworkForm>painting</artworkForm>
<title>Heraclitus and Democritus</title>
<technique>Fresco transferred to canvas</technique>
<location>Pinacoteca di Brera, Milan</location>
</artwork>
</artworks>
<artworks form="architecture">
<artwork date="1485">
<form>architecture</form>
<artworkForm>architecture</artworkForm>
<title>Interior view toward choir</title>
<technique>Fresco, height of arch 10,6 m</technique>
<location>Santa Maria presso San Satiro, Milan</location>
</artwork>
</artworks>
</author>
我的XQuery:
<authors>
{
for $author in doc("authors.xml")/authors/author
let $artworks := doc("artworks.xml")/artworks/artwork
return
<author>
<name>{$author/name/text()}</name>
<born-died>{$author/born-died/text()}</born-died>
<nationality>{$author/nationality/text()}</nationality>
<biography>{$author/biography/text()}</biography>
{
for $artwork in $artworks
let $nameInAuthor := $author/name/text()
let $nameInArtwork := $artwork/author/text()
where $nameInAuthor = $nameInArtwork
return
<artworks form="{$artwork/form/text()}">
<artwork date="{$artwork/date/text()}">
<title>{$artwork/title/text()}</title>
<technique>{$artwork/technique/text()}</technique>
<location>{$artwork/location/text()}</location>
</artwork>
</artworks>
}
</author>
}
</authors>
我試過ü唱不同的值(),但我剛剛得到上述
<authors>
{
for $author in doc("authors.xml")/authors/author
let $artworks := doc("artworks.xml")/artworks/artwork
return
<author>
<name>{$author/name/text()}</name>
<born-died>{$author/born-died/text()}</born-died>
<nationality>{$author/nationality/text()}</nationality>
<biography>{$author/biography/text()}</biography>
{
for $artwork in $artworks
let $nameInAuthor := $author/name/text()
let $nameInArtwork := $artwork/author/text()
where $nameInAuthor = $nameInArtwork
return
for $artworkForm in distinct-values($artworks/form/text())
let $form := $artwork/form/text()
where $form = $artworkForm
return
<artworks form="{$artworkForm}">
{
<artwork date="{$artwork/date/text()}">
<form>{$form}</form>
<artworkForm>{$artworkForm}</artworkForm>
<title>{$artwork/title/text()}</title>
<technique>{$artwork/technique/text()}</technique>
<location>{$artwork/location/text()}</location>
</artwork>
}
</artworks>
}
</author>
}
</authors>
謝謝。它沒有抓住沒有藝術品的作品數據的作品。也許是一個路徑問題,但它是一個正確的方向開始我認爲 – bigubosu
得到它的工作,這只是一個元素名稱的問題。謝謝。 – bigubosu