Xml 通过适当插入标记格式化xquery的输出

Xml 通过适当插入标记格式化xquery的输出,xml,formatting,xquery,Xml,Formatting,Xquery,我已经编写了xquery,但输出格式不正确 这是我的密码 let $doc:=(doc("hamlet.xml")) for $y in distinct-values($doc/PLAY/ACT/SCENE/SPEECH/SPEAKER/text()) return <SPEAKER> {$y} <scene>{$doc/PLAY/ACT/SCENE/SPEECH[SPEAKER = $y]/../TITLE}</scene> </SPEAKER&g

我已经编写了xquery,但输出格式不正确

这是我的密码

let $doc:=(doc("hamlet.xml"))
for $y in distinct-values($doc/PLAY/ACT/SCENE/SPEECH/SPEAKER/text())
return 
<SPEAKER>
{$y}
<scene>{$doc/PLAY/ACT/SCENE/SPEECH[SPEAKER = $y]/../TITLE}</scene>
</SPEAKER>
let$doc:=(doc(“hamlet.xml”))
对于不同值的$y($doc/PLAY/ACT/SCENE/SPEECH/SPEAKER/text())
返回
{$y}
{$doc/PLAY/ACT/SCENE/SPEECH[SPEAKER=$y]/../TITLE}
它正在产生的输出是

<SPEAKER>BERNARDO<scene>
<TITLE>SCENE I.  Elsinore. A platform before the castle.</TITLE>
<TITLE>SCENE II.  A room of state in the castle.</TITLE>
</scene>
</SPEAKER>
<SPEAKER>FRANCISCO<scene>
<TITLE>SCENE I.  Elsinore. A platform before the castle.</TITLE>
</scene>
</SPEAKER>
<SPEAKER>BERNARDO
<scene>SCENE I.  Elsinore. A platform before the castle.</scene>
<scene>SCENE II.  A room of state in the castle.</scene>

</SPEAKER>
<SPEAKER>FRANCISCO
<scene>SCENE I.  Elsinore. A platform before the castle.</scene>
</SPEAKER>
贝尔纳多 第一幕艾尔西诺。城堡前的平台。 第二场。城堡中的一个国家的房间。 弗朗西斯科 第一幕艾尔西诺。城堡前的平台。 我想要的输出应该是

<SPEAKER>BERNARDO<scene>
<TITLE>SCENE I.  Elsinore. A platform before the castle.</TITLE>
<TITLE>SCENE II.  A room of state in the castle.</TITLE>
</scene>
</SPEAKER>
<SPEAKER>FRANCISCO<scene>
<TITLE>SCENE I.  Elsinore. A platform before the castle.</TITLE>
</scene>
</SPEAKER>
<SPEAKER>BERNARDO
<scene>SCENE I.  Elsinore. A platform before the castle.</scene>
<scene>SCENE II.  A room of state in the castle.</scene>

</SPEAKER>
<SPEAKER>FRANCISCO
<scene>SCENE I.  Elsinore. A platform before the castle.</scene>
</SPEAKER>
贝尔纳多 第一幕艾尔西诺。城堡前的平台。 第二场。城堡中的一个国家的房间。 弗朗西斯科 第一幕艾尔西诺。城堡前的平台。 为了得到正确的输出,我做了很多努力,我该怎么做?请帮助

尝试:

let $doc:=(doc("hamlet.xml"))
for $y in distinct-values($doc/PLAY/ACT/SCENE/SPEECH/SPEAKER/text())
return 
<SPEAKER>
{$y}
<scene>{$doc/PLAY/ACT/SCENE/SPEECH[SPEAKER = $y]/../TITLE/text()}</scene>
</SPEAKER>
let$doc:=(doc(“hamlet.xml”))
对于不同值的$y($doc/PLAY/ACT/SCENE/SPEECH/SPEAKER/text())
返回
{$y}
{$doc/PLAY/ACT/SCENE/SPEECH[SPEAKER=$y]/../TITLE/text()}

您确定要创建混合内容吗?我会用另一个元素(例如“BERNARDO”)来包装说话人的名字,以尽可能避免混合内容。如果你有可能定义你自己的输出,我会考虑改变这一点。