我有如下 3 个 XML 文件,我想将所有这 3 个文档连接在一起,以便我可以执行聚合函数来找出特定分类名称的销售额。但是似乎我写的代码有问题。请指导我如何对三个文档执行聚合功能。
ClassDescription.XML
<classification name="Electronic">
<Description>electronic devices that requires electric</Description>
</classification>
<classification name="SoftToy">
<Description>Fluffy toys that kids like</Description>
</classification>
ToyClassification.XML
<toy toyID="11">
<name>Doll</name>
<classification>SoftToy</classification>
</toy>
<toy toyID="22">
<name>Xbox</name>
<classification>Electronic</classification>
</toy>
<toy toyID="33">
<name>PS3</name>
<classification>Electronic</classification>
</toy>
ToySale.XML
<toySale companyID="1" toyID="11" >
<amount>15</amount>
</toySale>
<toySale companyID="3" toyID="11" >
<amount>12</amount>
</toySale>
<toySale companyID="1" toyID="22" >
<amount>3</amount>
</toySale>
<toySale companyID="2" toyID="33" >
<amount>7</amount>
</toySale>
<ClassList>
<classification name="SoftToy">
<totalSale>4</totalSale>
</classification>
<classification name="Electronic">
<totalSale>3</totalSale>
</classification>
</ClassList>
下面是我拥有但似乎无法正常工作的代码。我可以知道什么是正确的 xquery 可以正常工作吗?
for $class in (ClassDescription.XML)//classification/@name
for $toyClass in (ToyClassification.XML)//toy/@toyID
for $sale in (ToySale.XML)//toySale/@toyID
let $sum := (ToySale.XML)//toySale[@toyID = $toyClass]
where $sale=$toyClass and $class=$toyClass/../name
order by sum($sum/amount)
return <ClassList>{$class}</ClassList>