我有成千上万的XML文件需要执行XQuery。
这就是我要查询的XML,格式是一致的:
<Archive xmlns="http://www.xxxx.com/egAr/1.0" Location="file://xxxxxx/Digital_Archive/773592.zip" Version="1.0">
<General Application="xxxx 16.0.1 - Build 1108 - Sep 30 2016" Author="xxxx@xxxx1" ModificationDate="2018-02-07T08:04:10-05:00" Server="xxxxxxx"/>
<Job CSREmail="" Category="Digital" Category2="MCSD904LAYOUT" Category3="Mat HSLPETG10022 / S257 petg 50m" Category4="No" Category5="xxxxx" Category6="2" Category7="xxxxxx" Created="2016-03-07T09:33:15-05:00" CreatedFrom="xxxxxx" CustomerID="xxxxxx" CustomerJobReference="xxxxxxx" JobFolder="xxxxxxx" Name="773592" OrderID="773592" ProjectID="773592" SubOrderID="">
<Description>xxxxxxx</Description>
</Job>
<Customer ID="332420" Name="xxxxxxx"/>
<JobParams>
<JobParam Name="steprepeat.No Across" Value="0"/>
<JobParam Name="steprepeat.No Around" Value="0"/>
<JobParam Name="steprepeat.Spacing across" Value="0"/>
<JobParam Name="steprepeat.Spacing around" Value="0"/>
<JobParam Name="steprepeat.Fronts around" Value="0"/>
<JobParam Name="steprepeat.Fronts across" Value="0"/>
<JobParam Name="steprepeat.Backs across" Value="0"/>
<JobParam Name="steprepeat.Backs around" Value="0"/>
</JobParams>
</Archive>
这是我的Xquery:
for $t in //@Category2,
$v in //@OrderID
let $d := "MCHT65780LAYOUT"
where $t = $d
order by $v
return concat ("Job: ",$v, " Die: ", $t)
它或多或少地产生了我正在寻找的东西,但是我对“for”循环有问题,我得到了无限的结果而BaseX停在了500,000的结果。如果我只在“for”语句中放入一个项目,我会得到正确的结果数,但我需要在结果中看到“OrderID”和“Category2”。
基本上我想搜索$ d并查看使用该值的作业。
迈克尔凯在下面的回答就像一个魅力。我还想出了如何使用“contains”函数的部分匹配产生结果:declare namespace a="http://www.xxxx.com/egAr/1.0";
for $j in //a:Job
let $t := $j/@Category2
let $v := $j/@OrderID
let $d := "67"
order by $v
where ($t [contains (.,$d)])
return concat ("Job: ",$v, " Die: ", $t)
答案 0 :(得分:4)
我怀疑您不想考虑出现在文档中任何位置的所有@Category2
和@OrderId
对,而只考虑出现在同一个Job元素中的对。
你可以把它写成
declare namespace a="http://www.xxxx.com/egAr/1.0";
for $j in //a:Job
let $t := $j/@Category2
let $v := $j/@OrderID
let $d := "MCHT65780LAYOUT"
where $t = $d
order by $v
return concat ("Job: ",$v, " Die: ", $t)
但我可能会把它写成:
declare namespace a="http://www.xxxx.com/egAr/1.0";
for $j in //a:Job[@Category2 = "MCHT65780LAYOUT"]
order by $j/@OrderID
return $j/concat("Job: ", @OrderID, " Die: ", @Category2)