首页 文章

在Xquery中使用fn:string-length时出错

提问于
浏览
1

我试图在Xquery中使用fn:string-length函数,奇怪的是我收到此错误 .

第19行,第66列: XP0004 [XP0004a]:运算符“gt”不适用于{http://www.w3.org/2001/XMLSchema}integer和类型的参数://www.w3.org/2001/XMLSchema}字符串

我想要做的就是获得一个XPath表达式的长度并将其与某个值进行比较 .

{                 
  let $PlaceofDeliveryZoneCodeVal := $getRevenueRequest1/ns0:AlternativeCode/ns0:AlternativeCodeVal/text()
  return
    if(fn:string-length($PlaceofDeliveryZoneCodeVal) > "8") then
      <ns1:GeoId>
        <ns1:AlternativeCodeVal>{$PlaceofDeliveryZoneCodeVal}</ns1:AlternativeCodeVal>
      </ns1:GeoId>
    else()
}

1 回答

  • 3

    问题是因为整数用引号括起来,所以你要将整数与字符串进行比较:

    (fn:string-length($PlaceofDeliveryZoneCodeVal) > "8")
    

    如果删除引号,则比较将成功:

    (fn:string-length($PlaceofDeliveryZoneCodeVal) > 8)
    

相关问题