Skip to Content
XSLT, 2nd Edition
book

XSLT, 2nd Edition

by Doug Tidwell
June 2008
Intermediate to advanced
986 pages
27h 8m
English
O'Reilly Media, Inc.
Content preview from XSLT, 2nd Edition

Calling Some Functions with More Than One Node Causes an Error

In XSLT 1.0, there were a number of functions that took a node as an argument. If we passed more than one node to the function, it simply took the first node and ignored the rest. XSLT 2.0 is much more strict; passing more than one node to a function that requires a single node is a fatal error. You can certainly make the argument that using the argument /purchase-order/items/item when you really mean /purchase-order/items/item[1] is sloppy code. Whether you agree with that opinion or not, XSLT 2.0 forces you to pass a single node to the function.

The XSLT 1.0 and XPath 1.0 functions generate-id(), local-name(), name(), namespace-uri(), number(), and string() require a single node in XSLT 2.0. To avoid any problems, simply add the predicate [1] to your stylesheets as you migrate them. In addition, if you use an XPath expression to select nodes for the concat() function, that XPath expression cannot return more than a single node. The expression concat('#1. ', /report/brand/name) throws an error in XSLT 2.0 if more than one node matches the XPath expression. On the other hand, concat('#1. ', (/report/brand/name)[1]) always works.

This is a dynamic error. It can be difficult to catch if your XPath expressions typically select only one node. That means the error condition occurs in the rare case that the XPath expression returns more than one node. If you need only one node, changing your expression from x/y/z to (x/y/z)[1] ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

XSLT Cookbook, 2nd Edition

XSLT Cookbook, 2nd Edition

Sal Mangano
XSLT

XSLT

Doug Tidwell
XSLT for Dummies

XSLT for Dummies

Richard Wagner
XSLT Cookbook

XSLT Cookbook

Sal Mangano

Publisher Resources

ISBN: 9780596527211Errata Page