抱歉这里有一个完整的xquery noob。我正在尝试编写一个查询,以便从以下xml文档中返回剂量,药物和诊断,当且仅当存在元素" trmt:drugTreatment"当下。
<?xml version="1.0" encoding="UTF-8"?>
<clin:Clinic
xmlns:cids="http://www.example.org/schema/hosptial/clinicIds"
xmlns:clin="http://www.example.org/schema/hospital/clinic"
xmlns:pat="http://www.example.org/schema/hospital/patient"
xmlns:prov="http://www.example.org/schema/hospital/provider"
xmlns:trmt="http://www.example.org/schema/hospital/treatment"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/schema/hospital/clinic
Clinic.xsd ">
<clin:Patient>
<pat:patient-id>0001</pat:patient-id>
<pat:patientName>Thomas Edison</pat:patientName>
<pat:dob>1991-01-01</pat:dob>
<pat:treatments>
<pat:treatment>
<trmt:providerId>001</trmt:providerId>
<trmt:diagnosis>Heart</trmt:diagnosis>
<trmt:drugTreatment>
<trmt:dosage>12.5mg</trmt:dosage>
<trmt:drugName>heart_med</trmt:drugName>
</trmt:drugTreatment>
</pat:treatment>
</pat:treatments>
</clin:Patient>
<clin:Provider>
<prov:provider-id>001</prov:provider-id>
<prov:providerName>XYZ</prov:providerName>
<prov:specialization>Cardiology</prov:specialization>
</clin:Provider>
</clin:Clinic>
以下是我的简单xquery,如上所述它基本上应该返回剂量,药物和诊断。但是,当我运行查询时,我得到结果的整个元数据
查询
for $t in $clinData//clin:Patient
where some $x in $t/pat:patient-id
satisfies $t/pat:patient-id = $patient-id
return <Treatment>
<Drug>
{$t//treatment:drugName}
</Drug>
<Dosage>
{$t//treatment:dosage}
</Dosage>
<Dignosis>
{$t//treatment:diagnosis}
</Dignosis>
</Treatment>
结果
<?xml version="1.0" encoding="UTF-8"?>
<Treatment><Drug>heart_med</Drug><Dosage><trmt:dosage
xmlns:cids="http://www.example.org/schema/hosptial/clinicIds"
xmlns:clin="http://www.example.org/schema/hospital/clinic"
xmlns:pat="http://www.example.org/schema/hospital/patient"
xmlns:prov="http://www.example.org/schema/hospital/provider"
xmlns:trmt="http://www.example.org/schema/hospital/treatment"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance">12.5mg</trmt:dosage></Dosage><Dignosis><trmt:diagnosis
xmlns:cids="http://www.example.org/schema/hosptial/clinicIds"
xmlns:clin="http://www.example.org/schema/hospital/clinic"
xmlns:pat="http://www.example.org/schema/hospital/patient"
xmlns:prov="http://www.example.org/schema/hospital/provider"
xmlns:trmt="http://www.example.org/schema/hospital/treatment"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance">Heart</trmt:diagnosis></Dignosis></Treatment>
我在这里做错了什么?
答案 0 :(得分:0)
有一个直接的代码味道,因为&#34;满足&#34;这里的条款:
where some $x in $t/pat:patient-id
satisfies $t/pat:patient-id = $patient-id
不引用$ x(这意味着序列中的所有项都将满足条件,或者没有条件)。
所以(不看你的实际逻辑)我想你可能想要:
where some $x in $t/pat:patient-id
satisfies $x = $patient-id
我不知道$ patient-id是什么,但我认为它是一个持有一个或多个患者ID的外部变量。如果是这样,那么你可以摆脱整个&#34;其中&#34;条款,只写
for $t in $clinData//clin:Patient[pat:patient-id=$patient-id]...