I think Saxon is behaving in a conformant way here. The spec (2.9) says:
Certain errors are classified as type errors. A type error occurs when the
value supplied as input to an operation is of the wrong type for that
operation, for example when an integer is supplied to an operation that
expects a node.] If a type error occurs in an instruction that is actually
evaluated, then it must be signaled in the same way as a non-recoverable
dynamic error. Alternatively, an implementation may signal a type error
during the analysis phase in the same way as a static error, even if it
occurs in part of the stylesheet that is never evaluated, provided it can
establish that execution of a particular construct would never succeed.
In this situation
would always fail with a type error at run time if evaluated, so the
processor is allowed to report the error at compile time.
Whether it's a good idea to do so is another question. Ideally I would only
report this error if the variable is explicitly declared as being of type
xs:string, rather than having a type that's inferred from the value. This
would require maintaining two static types for an expression, the declared
type (used for error reporting) and the inferred type (used for
optimization) - which would be a big change.
> -----Original Message-----
> From: saxon-help-admin@...
> [mailto:saxon-help-admin@...] On Behalf Of
> Norman Walsh
> Sent: 11 April 2005 14:09
> To: saxon-help@...
> Subject: [saxon] Bug or broken spec? :-)
> This stylesheet:
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:f="http://docbook.org/xslt/ns/extension"
> <xsl:template match="/">
> <xsl:variable name="result" select="'id'"/>
> <xsl:when test="$result instance of element()">
> <xsl:apply-templates select="$result" mode="tohtml"/>
> <xsl:value-of select="$result"/>
> fails to compile under Saxon 8.4:
> Error at xsl:apply-templates on line 13 of file:/tmp/test.xsl:
> XTTE0520: Required item type of @select attribute of
> xsl:apply-templates is node();
> supplied value has item type xs:string
> Is that a Saxon bug or a spec bug? :-) In this case, I can tell when I
> generate the code that $result will be a string literal, but that's
> not always the case.
> Be seeing you,
> Norman Walsh <ndw@...> | There has never been a perfect
> http://nwalsh.com/ | government, because men have passions;
> | and if they did not have passions,
> | there would be no need for
> | government.-- Voltaire