如何解决明确值错误

时间:2014-07-15 12:33:44

标签: xpath xquery

如何在XQuery中解决此错误。我希望数据与XML结果中的重复不同。我试图在for语句的doc前面添加distinct-values,但是描述了这个错误。

Engine name: Saxon-PE XQuery 9.5.1.3
Severity: fatal
Description: XPTY0019: Required item type of first operand of '/' is node(); supplied        value has item type xs:anyAtomicType
         Start location: 23:0
        URL: http://www.w3.org/TR/xpath20/#ERRXPTY0019

这是代码:

for $sv1 in distinct-values(doc('tc.xml')//term/year)
 let $sv2 := doc('tc.xml')//term[year= $sv1]
 let $sv3 := doc('tc.xml')//student[idStudent= $sv1/idStudent](:HERE IS THE ERROR LINE:)
 let $sv4 := doc('tc.xml')//program[idStudent= $sv3/idStudent]
  return
  <Statistics>
    {$sv1 } 
    <Count_Student>{count($sv2)}</Count_Student>
    <a50_60>{count(doc('tc.xml')/mydb//program[doc('tc.xml')/mydb//term/year =$sv1][avg>= 50 and avg < 60])}</a50_60>
</Statistics>

提前谢谢。

1 个答案:

答案 0 :(得分:1)

distinct-values()会将您的输入视为雾化,这意味着$sv1/idStudent无效,因为$sv1不是元素。我认为您应该使用$sv1而不是在提供错误的行上使用$sv2

相关问题