XSLT - Saxon error on updating from 9.4.0-9 to 9.7.0-14

174 Views Asked by At

In my xslt I got follow error when I update Saxon version from 9.4.0-9 to 9.7.0-14.

net.sf.saxon.trans.XPathException: Required item type of result of call to collection is node(); supplied value has item type xs:string

Whats the issue here ?

<xsl:variable name="file-uris" as="xs:string*"
  select="if (empty($symbol.mappings.folder.uri)) then () else
     for $f in collection(concat($symbol.mappings.folder.uri, '?select=*.txt&amp;unparsed=yes'))
  return string($f/base-uri())"/>
1

There are 1 best solutions below

0
On

There have been substantial changes to the collection() function in Saxon 9.7, triggered by changes to the spec in XPath 3.0 and 3.1 - unfortunately the generalisation to collections of any kind of resource (e.g. JSON files) made it very hard to retain 100% backwards compatibility.

The specific issue here is that with the "unparsed" option, earlier Saxon releases anticipated a way of handling non-document collections that proved incompatible with the way the specs subsequently evolved. The specific error occurs if collection() returns non-node values when XPath 3.0 is not enabled, because Saxon is now trying to comply with both the 2.0 and 3.0 rules depending which version of XSLT/XPath is active. With 3.0 enabled, and with default configuration settings, the file extension ".txt" is enough to cause resources in a collection to be returned as instances of xs:string, but this doesn't work if 3.0 is not enabled.

(A procedural note: you're welcome to raise Saxon questions here, but we find it easier to track them if you raise them on the support site at saxonica.plan.io - if you raise a question there then we try to ensure that it is closed with a satisfactory resolution, whereas with questions raised here it's more hit-and-miss.)