我的xml是这样的: inputxml的完整xml
<course>
<reg_num>10616</reg_num>
<subj>BIOL</subj>
<crse>361</crse>
<sect>F</sect>
<title>Genetics and MolecularBiology</title>
<units>1.0</units>
<instructor>Russell</instructor>
<days>M-W-F</days>
<time>
<start_time>11:00AM</start_time>
<end_time>11:50</end_time>
</time>
<place>
<building>PSYCH</building>
<room>105</room>
</place>
</course>
我需要对课程采取不同的价值观,并请教这些课程的导师。
这是我当前的代码:
let $x := doc("reed.xml")/root/course
for $y in distinct-values($x/title)
let $z := $y/instructor
return ( {data($y)} ,{data($z)})
我在做什么错
答案 0 :(得分:0)
在您发布的代码中,for循环正在对不同的@objc func handlePan(_ gestureRecognizer: UIPanGestureRecognizer) {
if(textField.isEditing){return;}
if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
let translation = gestureRecognizer.translation(in: self.view)
gestureRecognizer.view!.center = CGPoint(x: gestureRecognizer.view!.center.x + translation.x, y: gestureRecognizer.view!.center.y + translation.y)
gestureRecognizer.setTranslation(CGPoint.zero, in: self.view)
}
}
字符串值的序列进行迭代。
您不能将XPath输入这些字符串。
相反,您希望XPath进入title
课程,并在每次迭代中使用$x
选择$y
等于{{1 }},然后选择course
。
title
答案 1 :(得分:0)
在XQuery 3.1中,您可以通过 group by 进行此操作。
for $course := doc("reed.xml")/root/course
group by $title := $course/title
return ( <title>{$title}</title> ,
<instructors>{$course/instructor}</instructors> )