Project

Profile

Help

How to suppress "SXWN9000 Required item type of value..."?

Added by T Hata almost 8 years ago

This stylesheet generates a warning.




	
		
		
		
		
	

M:\>java -cp saxon9he.jar net.sf.saxon.Transform -it:main -t -xsl:test.xsl
Saxon-HE 9.7.0.14J from Saxonica
Java version 1.8.0_111
Warning at char 9 in xsl:variable/@select on line 11 column 28 of test.xsl:
  SXWN9000: Branch 1 of conditional will fail with a type error if executed. Required item
  type of value of variable $result is xs:string; supplied value has item type xs:integer
...
input= 1
result= Not an instance

What's the best way to suppress it? Replacing @$input@ after @then@ with @$input treat as xs:string@ doesn't. (It raises another warning) Obviously @$input cast as xs:string@ works, but just looks a bit redundant.


Replies (4)

Please register to reply

RE: How to suppress "SXWN9000 Required item type of value..."? - Added by Michael Kay almost 8 years ago

Why would you want to suppress this warning? The code is clearly wrong.

What are you actually trying to achieve?

It's true that the first branch of the conditional will never be executed, because ($input instance of xs:string) will always be false. And during the optimization phase, Saxon would reduce the whole expression to the second branch if it got that far. But the spec allows raising type errors at compile time if there is code that would always deliver a value of the wrong type, even if that code is never executed, and this is generally a helpful thing to do.

You could replace $input with "banana" - anything that evaluates to a string would do, since the code will never be executed.

RE: How to suppress "SXWN9000 Required item type of value..."? - Added by T Hata almost 8 years ago

The stylesheet above is a reduced one. Actually the stylesheet is generated dynamically by another stylesheet. It takes a form of



  

and we can't predict what goes there, so @if (...instance of...)@. In this case, it happened to be statically evaluated as xs:integer.

@cast as@ is fine. Just wondered if there'd be a better way.

RE: How to suppress "SXWN9000 Required item type of value..."? - Added by Michael Kay almost 8 years ago

Well, I guess the answer to your original question is that you can suppress all warnings by writing an ErrorListener.

But if you generate code with type errors in it, that's sometimes going to give you an error rather than a warning.

RE: How to suppress "SXWN9000 Required item type of value..."? - Added by T Hata almost 8 years ago

Ok, Saxon is helping out so I'll fix the expression by following it. Thanks for the advice.

    (1-4/4)

    Please register to reply