Subject: Re: [xsl] reading a document into a typed variable From: Georges Schmitz <georges.schmitz@xxxxxxxxx> Date: Fri, 02 Oct 2009 17:28:38 +0200 |
I don't understand the difference between two ways of loading an XML file into a variable (see A and B below). Case A used to work with old saxon 8.9, but with 9.2 only B is successful. With A I get following error message:
XTTE0570: Required item type of value of variable $global.setup is
document-node(element(global-setup, xs:anyType)); supplied value has item type xs:string
Saxon's type checking has improved between the two releases. Saxon 9.2
recognizes at compile time that if $global.setup.file is a string, then
trace($global-setup-file, x) will also be a string, and that this is
inconsistent with your declared type, which is document-node(). In earlier
releases this error would only have been detected at run-time, and only if
this branch of the if-then-else were selected. But Saxon's static
type-checking is not yet perfect: it seems it is failing to spot that if
trace($global-setup-file, x) is a string, then <xsl:copy-of
select="trace($global-setup-file, x)"/> will also be a string, and this is
why you get no compile-time error message for case B. I'll take a look at
this and try to improve it for the next release.
What you really want is to remove the error, of course, and to do that you need to ensure that the exception branch of your conditional delivers a result that is consistent with the type declaration of the variable.
<xsl:variable name="global.setup.doc" select="if (doc-available($global.setup.file)) then document($global.setup.file) else trace($global.setup.file,'Configuration File $global.setup.filewas not readable (missing or not valid)!')" />
<xsl:variable name="global.setup" select="$global.setup.doc" as="document-node(element(global-setup))"/>
Configuration File $global.setup.file.fixed was not readable (missing or not valid)! [1]: xs:string: ../../xml-resolved/GlobalSetup-resolved.xmlx Error on line 57 of profile-filter.xsl: XTTE0570: Required item type of value of variable $global.setup is document-node(element(global-setup, xs:anyType)); supplied value has item type xs:string
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] reading a document into a, Michael Kay | Thread | RE: [xsl] reading a document into a, Michael Kay |
RE: [xsl] RandomList.xsl from FXSL-, Michael Kay | Date | Re: [xsl] RandomList.xsl from FXSL-, Jesper Tverskov |
Month |