Chapter 6. Strings, Numbers, Dates, and Times

This chapter looks more closely at some of the more useful XSLT elements and XPath functions that you can employ to manipulate string, numeric, and datetime values.

In this chapter you'll do the following:

  • Learn about codepoint conversion and more about collations.

  • Use functions that support pattern-matching techniques—such as regular expressions—to find and replace text, to normalize text values, and to escape URIs.

  • Generate simple and hierarchical numbering using <xsl:number> and format the generated values.

  • Use another pair of tools—the <xsl:decimal-format> declaration and the XSLT format-number() function—to convert and format numeric values in source data.

  • Work with dates and times generated from your system, which you can then process and format.

  • Learn how to apply durations and timezone values.

String Processing

Back in Chapter 2 you were given a quick look at some of the functions that are available to you when you want to handle text strings. This section expands on that subject with a set of working examples for typical use cases.

Pay close attention here, because as I mentioned then, you will likely use string functions more often than any other category in your stylesheets, because XML is fundamentally about handling text.

About Collations

Some operations on strings need to take into account the collation sequence in use by the processor. Examples include sorting, establishing equality, and using functions such as distinct-values()

Get Beginning XSLT and XPath: Transforming XML Documents and Data now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.