vikash
vikash

Reputation: 3

Xquery --- FORG0001: "": invalid value for cast/constructor error

I am using Xquery mapping in my OSB project. Below is a sample code I am using which is throwing error

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'

Later I am using above defined variable to map to a target node BaseStorageUOM(String)

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

When I run this its throwing Error executing the XQuery transformation:

{http://www.w3.org/2005/xqt-errors}FORG0001: "": invalid value for cast/constructor: {http://www.w3.org/2001/XMLSchema}double: error: double: Invalid double value:

I couldnt figure out the issue with the code.

Upvotes: 0

Views: 6993

Answers (1)

duncdrum
duncdrum

Reputation: 733

This simplified version runs fine using Saxon, so the XQuery is ok, provided you have a return somewhere no mentioned in your example.

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> )

Upvotes: 0

Related Questions