Problem with codepoints/integer in XQuery

Viewed 50

So im trying to execute this simple function:

declare function local:decodeBase64() as element(){
  <root-element>
    {    
      let $codepointsString := "77 97 110"
      let $codepoints := fn:replace( $codepointsString,' ',', ')
      let $x := fn:codepoints-to-string(xs:integer($codepoints))
      return
      $x
    }
  </root-element>
};

but i'm getting a error that i think it's because of xs:integer

however i can execute this code with the integer hardcoded

let $x := codepoints-to-string((77, 97, 110))

I noticed that i can run the code if i declare $codepoints as xs:integer* but i dont't know get a codePoint inside an element and use as xs:integer* to call codepoints-to-string function.

error:

http://www.w3.org/2005/xqt-errors}FORG0001: "77 97 110": invalid value for cast/constructor: {http://www.w3.org/2001/XMLSchema}integer: error: decimal: Invalid decimal value: unexpected char '32'
1 Answers

The original string needs to be split to multiple codepoint strings. The resulting strings can then be converted to integers:

let $codepointsString := "77 97 110"
let $codepoints := (
  for $string in fn:tokenize($codepointsString, " ")
  return xs:integer($string)
)
return fn:codepoints-to-string($codepoints)
Related