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