我是 xquery 的新手,正在尝试阅读有关使用该工具的不同参考资料。我一直在尝试测试并尝试生成一些 xml 格式的消息,但这让我感到困惑。这是我的 xQuery 代码:
示例 XQuery
declare variable $requestBody as element() external;
declare function VerifyOrderDetailTransformation($requestBody as element())
as element() {
<msg>
<header>
<headtitle>This is the title</headtitle>
</header>
<dbody>
{GenerateEquipmentListNodes($requestBody)}
</dbody>
</msg>
};
declare function GenerateEquipmentListNodes($requestBody as element())
as element()* {
let $titleList := (
for $e in $requestBody//bookstore//book
let $dTitle := $e/title/text()
return
<theTitle>{$dTitle}</theTitle>
)
return
<dTitleList>
{$titleList}
</dTitleList>
};
VerifyOrderDetailTransformation($requestBody)
示例 XML
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
以下是在 XML 上运行 xQuery 生成的输出:
电流输出
<msg>
<head>
<title>This is the title</title>
</head>
<body>
<dTitleList/>
</body>
</msg>
预期产出
<msg>
<head>
<title>This is the title</title>
</head>
<body>
<dTitleList>
<theTitle>Everyday Italian</theTitle>
<theTitle>Harry Potter</theTitle>
<theTitle>XQuery Kick Start</theTitle>
<theTitle>Learning XML</theTitle>
<dTitleList/>
</body>
</msg>
我的问题是,我可能错过了什么?