Type Checking Is Much Stricter

XSLT 1.0 had a very simple type system. The support for XML Schema in XSLT 2.0 means type checking is much stricter. For example, in XSLT 1.0, this statement works:

<xsl;value-of select="substring-before(12345, 3)"/>

This returns the value 12, which causes a static error in XSLT 2.0. To get this function to work in XSLT 2.0, we have to write it like this:

<xsl;value-of select="substring-before(string(12345), string(3))"/>

As you migrate your stylesheets from XSLT 1.0 to 2.0, you’ll find yourself explicitly casting values such as this quite often.

Get XSLT, 2nd Edition 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.