Skip to Content
XSLT Cookbook, 2nd Edition
book

XSLT Cookbook, 2nd Edition

by Sal Mangano
December 2005
Intermediate to advanced content levelIntermediate to advanced
774 pages
19h 30m
English
O'Reilly Media, Inc.
Content preview from XSLT Cookbook, 2nd Edition

Chapter 3. Numbers and Math

Arithmetic is being able to count up to 20 without taking off your shoes.

Mickey Mouse

Introduction

Chapter 2 lamented the absence of sophisticated string-processing facilities in native XSLT 1.0. By comparison, XSLT’s handling of numerical computation is truly “Mickey Mouse”! XSLT 1.0 gives you facilities for basic arithmetic, counting, summing, and formatting numbers, but the remaining mathematics is up to your sheer wit. Fortunately, as with strings, XSLT’s recursive powers permit reasonable mathematical feats with reasonable effort.

In XPath/XSLT 2.0, some of the more obvious math functions have been added including abs(), avg(), max(), min(), round-to-half-even(). Further, there are now more numerical types (xs:integer, xs:double, and the other numeric types defined in XML Schema datatypes) where XSLT 1.0 only had a single floating point numeric type. Thankfully, XPath 2.0 now recognizes scientific notation, whose absence was often a major inconvenience in 1.0.

However, whether you are using 1.0 or 2.0, do not expect to find matrix multiplication or Fast-Fourier transform recipes in this section. If you really need to perform sophisticated math on XML-encoded data, then XSLT is not the language for you. Instead, bring the data into a more mathematically inclined language using an XSLT front-end converter or native SAX or DOM interface. Nevertheless, a web page called “Gallery of Stupid XSL and XSLT Tricks” (http://www.incrementaldevelopment.com/xsltrick ...

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.
Start your free trial

You might also like

XSLT Cookbook

XSLT Cookbook

Sal Mangano
XSLT, 2nd Edition

XSLT, 2nd Edition

Doug Tidwell
XSLT for Dummies

XSLT for Dummies

Richard Wagner
XSLT

XSLT

Doug Tidwell

Publisher Resources

ISBN: 0596009747Supplemental ContentErrata Page