FORG0001: Cannot convert string "N" to double

I have XSL statement and when running it as XSL transform, getting the following error-

2020-06-30 18:29:24.307  INFO 23756 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup Error evaluating ($trackCountryOfOrigin = 0 or $trackCountryOfOrigin = "N" or $trackCountryOfOrigin = "") in xsl:when/@test on line 103 column 123 of WMOSToSC2020_Item.xsl:   FORG0001: Cannot convert string "N" to double ; SystemID: file:/C:/SCPP20/scpp-sc2020-interface-migration-master@3ec266adf36/./xslt/WMOSToSC2020_Item.xsl; Line#: 103 ValidationException: Cannot convert string "N" to double         at net.sf.saxon.type.ValidationFailure.makeException(ValidationFailure.java:392)         at net.sf.saxon.type.ValidationFailure.asAtomic(ValidationFailure.java:417)         at net.sf.saxon.expr.sort.UntypedNumericComparer.quickComparison(UntypedNumericComparer.java:158)         at net.sf.saxon.expr.sort.UntypedNumericComparer.quickCompare(UntypedNumericComparer.java:58)         at net.sf.saxon.expr.GeneralComparison.compare(GeneralComparison.java:829)         at net.sf.saxon.expr.GeneralComparison.evaluateManyToOne(GeneralComparison.java:704)         at net.sf.saxon.expr.GeneralComparison.effectiveBooleanValue(GeneralComparison.java:651)         at net.sf.saxon.expr.OrExpression.effectiveBooleanValue(OrExpression.java:133)         at net.sf.saxon.expr.OrExpression.effectiveBooleanValue(OrExpression.java:133)         at net.sf.saxon.expr.instruct.Choose.choose(Choose.java:917)         at net.sf.saxon.expr.instruct.Choose.processLeavingTail(Choose.java:892)         at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)         at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:721)         at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)         at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:721)         at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)         at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:721)         at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)         at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:721)         at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)         at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132)         at net.sf.saxon.expr.LetExpression.process(LetExpression.java:608)         at net.sf.saxon.expr.instruct.ForEach.lambda$processLeavingTail$0(ForEach.java:484)         at net.sf.saxon.om.SequenceIterator.forEachOrFail(SequenceIterator.java:128)         at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:484)         at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)         at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:349)         at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:485)         at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:733)         at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:348)         at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:341) 

Here is my xsl Statement-

<xsl:variable name="trackCountryOfOrigin" select="LotReq"/>     <xsl:choose><xsl:when test="$trackCountOfOrg=0 or $trackCountOfOrg='N' or $trackCountOfOrg=''">"trackCountOfOrg": 0,&#xa;</xsl:when></xsl:choose> 

Here is input xml-

<LotReq>N</LotReq> 

Note- – this tag can have N or 0 populated. We are using Saxon processor to transform this XML using XSL.

Add Comment
1 Answer(s)

In XPath 2.0+, the operands of "=" must be of comparable types: you get an error (as here) if one operand is a string and the other is a number. You should either convert the number to a string, or the string to a number.

That’s different from XPath 1.0, which did an implicit conversion (though it’s so long ago, I’ve forgotten the exact conversion rules).

In 2.0+ you still get implicit conversion if one of the arguments is of type xs:untypedAtomic – which in practice means, if it is a node and there is no schema. In this situation the string value of the node will be converted to the type of the other operand.

Answered on July 17, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.