Project

Profile

Help

XQuery function: Error with result type

Added by Scree Pales almost 8 years ago

Hi, I'm trying to apply a xquery file to a xml file. While parsing the xquery file i already receive warnings like: @Warning on line 38 column 8 of Mapping.xq: Branch 1 of conditional will fail with a type error if executed. Required item type of result of call to vmf:myFunction is xs:boolean; supplied value has item type xs:integer@

When executing i get the error: @Type error on line 38 column 29 of Mapping.xq: XPTY0004: Required item type of result of call to vmf:myFunction is xs:boolean; supplied value has item type xs:integer net.sf.saxon.s9api.SaxonApiException: Required item type of result of call to vmf:myFunction is xs:boolean; supplied value has item type xs:integer at net.sf.saxon.s9api.XQueryEvaluator.run(XQueryEvaluator.java:372) at my.project.Transformer.xqueryFunction(Transformer.java:166) at my.project.Transformer.importFiles(Transformer.java:873) at my.project.Main.main(Main.java:40) Caused by: net.sf.saxon.trans.XPathException: Required item type of result of call to vmf:myFunction is xs:boolean; supplied value has item type xs:integer at net.sf.saxon.expr.ErrorExpression.evaluateItem(ErrorExpression.java:125) at net.sf.saxon.expr.ErrorExpression.iterate(ErrorExpression.java:148) at net.sf.saxon.expr.instruct.Choose.iterate(Choose.java:909) at net.sf.saxon.value.Closure.iterate(Closure.java:189) at net.sf.saxon.value.Closure.head(Closure.java:160) at net.sf.saxon.expr.UserFunctionCall.evaluateItem(UserFunctionCall.java:453) at net.sf.saxon.expr.CastExpression.evaluateItem(CastExpression.java:393) at net.sf.saxon.expr.CastExpression.evaluateItem(CastExpression.java:33) at net.sf.saxon.expr.Expression.process(Expression.java:880) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:364) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:311) at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:149) at net.sf.saxon.expr.ForExpression.process(ForExpression.java:493) at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:655) at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:149) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:364) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:311) at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:653) at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:149) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:364) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:311) at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:149) at net.sf.saxon.expr.LetExpression.process(LetExpression.java:568) at net.sf.saxon.expr.ForExpression.process(ForExpression.java:493) at net.sf.saxon.expr.ForExpression.process(ForExpression.java:493) at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:713) at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:653) at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:149) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:364) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:311) at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:149) at net.sf.saxon.query.XQueryExpression.run(XQueryExpression.java:408) at net.sf.saxon.s9api.XQueryEvaluator.run(XQueryEvaluator.java:370) ... 3 more@

The function looks like this: @declare function vmf:myFunction ( $input as xs:string ) as xs:boolean? { if ( $input = 'JA' ) then 1 else if ( $input = 'NEIN' ) then 0 else 0 } ;@

Replacing the 1 and the 0 with true() and false() fixes the error. The problem is that i cannot alter the xquery file. It's a generated file from Altova Mapforce. Can i somehow tell Saxon to interpret the integer value like a boolean? Thanks in advance Scree


Replies (2)

RE: XQuery function: Error with result type - Added by Michael Kay almost 8 years ago

Can i somehow tell Saxon to interpret the integer value like a boolean?

No, sorry, you can't. The generated code is clearly incorrect. If you can't get Altova to fix their product, then one thing you could possibly attempt is to repair the query by converting it to XQueryX, transforming the XQueryX (e.g. to add a cast/constructor around the function body), and then serializing it back to XQuery syntax. Alternatively you could write some code that attempts to modify Saxon's expression tree before execution - but it would be pretty fiddly.

RE: XQuery function: Error with result type - Added by Scree Pales almost 8 years ago

Ok, thanks for the info. Then i will annoy the guys at the Altova forum :P

    (1-2/2)

    Please register to reply