Xml XQuery格式化输出
我正在尝试格式化输出 我有这个xmlXml XQuery格式化输出,xml,xquery,Xml,Xquery,我正在尝试格式化输出 我有这个xml <?xml version="1.0" encoding="UTF-8"?> <personnel> <person id="Big.Boss"> <name> <family>Boss</family> <given>Big</given> </name&g
<?xml version="1.0" encoding="UTF-8"?>
<personnel>
<person id="Big.Boss">
<name>
<family>Boss</family>
<given>Big</given>
</name>
<email>chief@oxygenxml.com</email>
<link subordinates="one.worker two.worker three.worker four.worker
five.worker"/>
</person>
<person id="one.worker">
<name>
<family>Worker</family>
<given>One</given>
</name>
<email>one@oxygenxml.com</email>
<link manager="Big.Boss"/>
</person>
<person id="two.worker">
<name>
<family>Worker</family>
<given>Two</given>
</name>
<email>two@oxygenxml.com</email>
<link manager="Big.Boss"/>
</person>
<person id="three.worker">
<name>
<family>Worker</family>
<given>Three</given>
</name>
<email>three@oxygenxml.com</email>
<link manager="Big.Boss"/>
</person>
<person id="four.worker">
<name>
<family>Worker</family>
<given>Four</given>
</name>
<email>four@oxygenxml.com</email>
<link manager="Big.Boss"/>
</person>
<person id="five.worker">
<name>
<family>Worker</family>
<given>Five</given>
</name>
<email>five@oxygenxml.com</email>
<link manager="Big.Boss"/>
</person>
</personnel>
老板
大的
chief@oxygenxml.com
工人
一个
one@oxygenxml.com
工人
两个
two@oxygenxml.com
工人
三
three@oxygenxml.com
工人
四
four@oxygenxml.com
工人
五
five@oxygenxml.com
这是XQuery
for $b in doc("Persons.xml")/personnel/person/name
where $b/family = "Boss"
return
<persons>
<found> { $b/family, $b/given}</found>
</persons>
用于文档中的$b(“Persons.xml”)/personal/person/name
其中$b/family=“Boss”
返回
{$b/家庭,$b/给定}
我得到这个输出
<?xml version="1.0" encoding="UTF-8"?>
<persons>
<found>
<family>Boss</family>
<given>Big</given>
</found>
</persons>
老板
大的
我如何得到这个输出,而不是用空格分隔
<persons>
<found>Big Boss</found>
</persons>
大老板
只需选择元素的字符串值,而不是元素本身:
<found>{
$b/family/fn:string(),
$b/given/fn:string()
}</found>
这些是其他可能的选择 使用
fn:data()
-
使用fn:string-join()
-
{字符串联接($b/族,$b/给定),“”)}
正如您所注意到的,这将返回节点Boss
,并包含所有子节点。在本例中,唯一的子对象是所需的(#PCDATA)
要返回节点内的文本(#PCDATA),请使用text()
您的报税表应为:
<persons>
<found>
{
$b/family/text(),
" ",
$b/given/text()
}
</found>
</persons>
{
$b/系列/文本(),
" ",
$b/给定/文本()
}
<persons>
<found> { data($b/family), data($b/given)}</found>
</persons>
<persons>
<found> { data($b/family), data($b/given)}</found>
</persons>
<persons>
<found> { string-join(($b/family, $b/given), " ")}</found>
</persons>
$b/family
$b/family/text()
<persons>
<found>
{
$b/family/text(),
" ",
$b/given/text()
}
</found>
</persons>