[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Upgrading version should lead to bug - right?

Subject: Re: [xsl] Upgrading version should lead to bug - right?
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Thu, 13 Sep 2012 08:38:51 +0100

On 13/09/2012 08:16, Ihe Onwuka wrote:
I have an XSLT 1.0 stylesheet that has been running on an XSLT 2.0
processor no problem but barfs when you upgrade the version attribute
(no other change to the code) to 2.0.

That shouldn't happen right?
No, it's entirely possible that it will happen. Once you set the version attribute to 2.0, you enable XSLT 2.0's stronger type checking. For example, in XSLT 1.0, contains(author, "abc") works fine if there is more than one author (it just takes the first, and ignores the others), while XSLT 2.0 gives you the type error that you are reporting.

If the stylesheet author's intent was to select the first item and ignore the others (a common example is contains(following-sibling::*, "xyz")) then the fix is to make this explicit: change it to contains(following-sibling::*[1], "xyz"). But sometimes, when you look at the code, you realize that the stylesheet author simply didn't take into account the possibility that the expression might select more than one node.

I've not pinned down the precise line of offending code but the error I am getting is

A sequence of more than one item is not allowed as the first argument
of contains() ("_IOS, _WEB, _CTV", "_IOS, _WEB, _CTV", ...)

Now the input XML has elements like this

<m__category>_IOS, _WEB, _CTV</m__category>

so I wonder if the processor is parsing that element as a sequence
instead of as a comma separated string.
No, your first argument to contains() has selected more than one string. The first string is "_IOS, _WEB, _CTV", the second string is exactly the same, and subsequent strings (if they exist) are not listed in the error message.

Michael Kay

Current Thread