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

Subject: Re: [xsl] Upgrading version should lead to bug - right?
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Thu, 13 Sep 2012 08:33:16 +0100
On 13 September 2012 08:16, Ihe Onwuka <ihe.onwuka@xxxxxxxxxxxxxx> 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?
>
> 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.

You are passing a sequence of more than one item to a function that
expects only 1.  When running xslt 1.0 'first item semantics' means in
that situation the first item in the sequence is used and the rest are
ignored.  In 2.0 thankfully that doesn't happen and you get the error.

It's hard to give an exact answer without seeing a small complete
runnable example, but the usual technique is to change

contains($foo, '...

to

for $x in $foo return contains($x, '....

or

$foo/contains(., '....




-- 
Andrew Welch
http://andrewjwelch.com

Current Thread