Re: [xsl] xsl:if with "and' in test expression triggers error when running in xslt 2.0 mode?

Subject: Re: [xsl] xsl:if with "and' in test expression triggers error when running in xslt 2.0 mode?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 17 Jun 2003 13:36:24 +0100
Hi Taras,

> Running the stylesheet quoted below in Saxon 7.5.1 triggers the
> error: "A sequence of more than one item is not allowed here" at the
> line containing the xsl:if element.
>
> When I set the version attribute to "1.0" the sheet seems to work fine.
>
> What makes ik fail when running in xslt 2.0 mode?

The relevant code is the XPath 2.0 expression:

  count($rows) = 3 and normalize-space($rows)

The normalize-space() function expects an optional string as an
argument -- in other words, if you pass it a sequence, then the
sequence must either be empty or contain a single item. In your case,
$rows contains (usually) 3 items, which means that it isn't a valid
argument for the normalize-space() function.

In XSLT 1.0, when you pass a node-set that contains more than one node
to a function that expects a string as an argument, it's the same as
passing the first node of that node-set as the argument. So you can
get the same effect in XSLT 2.0 using:

  count($rows) = 3 and normalize-space($rows[1])

Given this, the fact that you're getting an error highlights for you
the fact that in XSLT 1.0 you're only testing the first of the rows
for content whereas you actually want to test if "all the cells are
empty" or, in other words, if any of the cells has content. For the
test to succeed when any of the $rows has content, you should use:

  count($rows) = 3 and $rows[normalize-space(.)]

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread