我有两个 XML 文档 Students.xml 和 Admission.xml,我需要一个 xquery 来返回从入学日期起 30 天完成的学生的学生 ID 和学生姓名。我对如何加入他们以及使用条件提出困惑感到困惑,请帮助。
学生.xml
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<StudentDetails>
<Student_ID>1</Student_ID>
<Student_Name>Mark</Student_Name>
</StudentDetails>
<StudentDetails>
<Student_ID>2</Student_ID>
<Student_Name>Robin</Student_Name>
</StudentDetails>
<StudentDetails>
<Student_ID>3</Student_ID>
<Student_Name>Charlie</Student_Name>
</StudentDetails>
</root>
录取.xml
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<AdmissionDetails>
<Admission_ID>1</Admission_ID>
<Admission_Date>2017-10-06</Admission_Date>
<Admission_Status>Admitted</Admission_Status>
<Student_ID>3</Student_ID>
</AdmissionDetails>
<AdmissionDetails>
<Admission_ID>2</Admission_ID>
<Admission_Date>2017-04-14</Admission_Date>
<Admission_Status>Admitted</Admission_Status>
<Student_ID>2</Student_ID>
</AdmissionDetails>
<AdmissionDetails>
<Admission_ID>3</Admission_ID>
<Admission_Date>2017-08-16</Admission_Date>
<Admission_Status>Admitted</Admission_Status>
<Student_ID>1</Student_ID>
</AdmissionDetails>
到目前为止,我的代码是这样的,但它给了我一个重复值的结果,迫切需要帮助。
for $sid in doc("Student.xml")/root/StudentDetails/Student_ID
for $aid in doc("Admission.xml")/root/AdmissionDetails/Student_ID
for $x in doc("Admission,xml")/root/AdmissionDetails/Admission_Date
where $sid = $aid and $x >current-date() + xs:dayTimeDuration("P30D")
return $sid
这就是结果
<?xml version="1.0" encoding="UTF-8"?>
<Student_ID>1</Student_ID>
<Student_ID>1</Student_ID>
<Student_ID>10</Student_ID>
<Student_ID>10</Student_ID>