0

我在我的 OSB 项目中使用 Xquery 映射。下面是我正在使用的示例代码,它抛出错误

let $unitofmeasure := 
  if (data($ItemMaster/ns1:Item/ns1:dcunitofmeasure)= 1) then
    'CS'
  else if (data($ItemMaster/ns1:Item/ns1:dcunitofmeasure) = 2 or 
           data($ItemMaster/ns1:Item/ns1:dcunitofmeasure) = 3 ) then
    'EA'
  else if (data($ItemMaster/ns1:Item/ns1:corpwarehouseunitofmeasure) = 2 or 
           data($ItemMaster/ns1:Item/ns1:corpwarehouseunitofmeasure) = 3 ) then
    'EA'
  else 
    'CS'

后来我使用上面定义的变量映射到目标节点 BaseStorageUOM(String)

{
  if ($unitofmeasure != '') then
    (
      <BaseStorageUOM>{xs:string($unitofmeasure)}</BaseStorageUOM>
    )
  else 
    (
      <BaseStorageUOM>CS</BaseStorageUOM>
    )
}

当我运行它时,它会抛出执行 XQuery 转换的错误:

{ http://www.w3.org/2005/xqt-errors }FORG0001:“”:强制转换/构造函数的值无效:{ http://www.w3.org/2001/XMLSchema }double:错误:double:无效的双精度值:

我无法弄清楚代码的问题。

4

1 回答 1

0

这个简化版本使用 Saxon 运行良好,所以 XQuery 没问题,只要您return的示例中没有提到某个地方。

let $data :=  <root>
                <dcunitofmeasure>2</dcunitofmeasure>
              </root>

 let $unitofmeasure :=  if ($data//dcunitofmeasure = 1) 
                        then 'CS'
                          else if ($data//dcunitofmeasure = 2 or $data//dcunitofmeasure = 3) 
                          then 'EA'
                        else 'CS'

 return
   if ($unitofmeasure != '') 
   then ( <BaseStorageUOM>{xs:string($unitofmeasure)}</BaseStorageUOM> )
   else  ( <BaseStorageUOM>CS</BaseStorageUOM> )
于 2017-12-20T19:07:18.550 回答