【发布时间】:2015-05-15 19:05:01
【问题描述】:
我在编写 XQuery 时遇到问题。我有这个 XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<book>
<title>Data</title>
<author>Serge Abiteboul</author>
<author>Peter Buneman</author>
<author>Dan Suciu</author>
<section id="intro" difficulty="easy" >
<title>Chapter1</title>
<p>Text ... </p>
<section>
<title>SubChapter1</title>
<p>Text ... </p>
</section>
<section>
<title>SubChapter2</title>
<p>Text ... </p>
<figure height="400" width="400">
<title>Figure1</title>
<image source="csarch.gif"/>
</figure>
<p>Text ... </p>
</section>
</section>
<section id="syntax" difficulty="medium" >
<title>Chapter2</title>
<p>Text ... </p>
<figure height="200" width="500">
<title>Figure2</title>
<image source="graphs.gif"/>
</figure>
<p>Text ... </p>
<section>
<title>SubChapter3</title>
<p>Text ... </p>
</section>
<section>
<title>SubChapter6</title>
<p>Text ... </p>
<figure height="250" width="400">
<title>Figure3</title>
<image source="relations.gif"/>
</figure>
</section>
<section>
<title>SubChapter5</title>
<p>Text ... </p>
</section>
</section>
</book>
我必须编写一个 Xquery 来计算章节中的每个子章节,以及每个章节中的每个图形。到目前为止,我已经到了这一点:
for $x in doc("file.xml")/book
return ((<main>{data($x/title)}</main>),
(<mChapter nrSubChapter="{count($x/section/title)}" nrFigure="{count($x/section/section/figure)}">{***data($x/section/title)***}</mChapter>),
(<mChapter nrSubChapter="{count($x/section/title}" nrFigures="{count($x//figure)}">{***data($x/section/title)***}</mChapter>))
我也不知道如何将章节标题放在标有***的地方。
【问题讨论】:
-
你卡在哪里了?任何错误信息,是不是输出不符合您的预期?请阅读how to post an SSCCE。尤其重要的是您当前的输出(或您收到的任何错误消息)和预期输出(与示例输入匹配)。