[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:if with "and' in test expression triggers erro

Subject: Re: 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
xslt test expression
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.