You have XSLT 1.0 in Xojo built-in. With our Saxon functions you get XSLT 3.0 and you can enjoy all the 2.0 and 3.0 features in your Xojo applications.
XSLT 2.0 and 3.0 introduce several significant improvements and new features compared to XSLT 1.0. Here are the key benefits of XSLT 2.0 and 3.0 over XSLT 1.0:
1. Support for Sequences (XSLT 2.0 & 3.0)
- XSLT 1.0: It processes XML documents element by element, and only allows a single value (like a string or a node) as the result of an expression.
- XSLT 2.0/3.0: It supports sequences, meaning that an expression can return multiple values, which can be processed in a more flexible way. This makes handling lists of nodes or values much easier.
2. XPath 2.0 and XPath 3.0 Integration
- XSLT 1.0: Uses XPath 1.0, which has limited functions and data types.
- XSLT 2.0: Integrates XPath 2.0, which introduces features like:
- Support for sequences
- String handling functions like
substring-before
,substring-after
,replace
, etc. - Enhanced regular expression support (
matches()
,replace()
) - Better handling of data types (e.g., date, time, and duration types)
- Stronger support for functions like
distinct-values()
,sort()
, andfor-each()
.
- XSLT 3.0: Further enhances XPath with new functions and better handling of sequences.
3. More Data Types
- XSLT 1.0: Limited to a few basic types like strings, numbers, booleans, and nodes.
- XSLT 2.0/3.0: Supports additional data types such as:
xs:date
,xs:time
,xs:dateTime
,xs:duration
, and more.- Enables better handling of dates, times, and durations in XML data, making transformations involving temporal data easier and more accurate.
4. Grouping and Sorting
- XSLT 1.0: Sorting is very limited (only works on text nodes) and there is no built-in support for grouping elements.
- XSLT 2.0: Introduces the
<xsl:for-each-group>
instruction for grouping elements and allows sorting based on any criteria (not just text nodes). - XSLT 3.0: Continues to support enhanced grouping and sorting with even more sophisticated capabilities.
5. Better Error Handling (XSLT 2.0 & 3.0)
- XSLT 1.0: Error handling is rudimentary and often leaves the user with vague or no feedback.
- XSLT 2.0: Introduces the
<xsl:message>
element for better logging and thetry-catch
style handling with<xsl:try>
,<xsl:catch>
, and<xsl:finally>
for better control over errors.
6. Keys and Indexing
- XSLT 1.0: Allows the use of keys for indexing but is limited in terms of flexibility and efficiency.
- XSLT 2.0: Offers a more powerful key mechanism (
xsl:key
) that can be used more efficiently for indexing and searching.
7. Functions and Variables
- XSLT 1.0: Supports only a limited set of built-in functions and does not allow user-defined functions (UDFs).
- XSLT 2.0: Allows for user-defined functions and provides a rich set of built-in functions for manipulating strings, numbers, dates, etc.
- XSLT 3.0: Further improves the function capabilities, including the ability to write more complex, reusable functions and make better use of templates.
8. Better Output Control
- XSLT 1.0: Output formatting and structure are fairly limited.
- XSLT 2.0/3.0: Provides advanced output options:
- Supports
xsl:output
for controlling the format of the output (e.g., XML, HTML, text, etc.). - Supports generating multiple output documents or results in the form of a sequence, making it possible to generate complex output structures more efficiently.
- Supports
9. Streaming (XSLT 3.0)
- XSLT 1.0/2.0: Cannot process large documents efficiently because they need to be read into memory.
- XSLT 3.0: Introduces support for streaming (through XSLT Streaming), which allows the transformation of very large XML files in a memory-efficient way, processing data as it is read without having to load the entire document into memory.
10. Modularization (XSLT 3.0)
- XSLT 1.0/2.0: Stylesheets could be modularized using
<xsl:include>
and<xsl:import>
, but it was somewhat limited in XSLT 1.0. - XSLT 3.0: Enhances modularization by allowing a more structured approach to creating reusable modules and more control over namespaces and schema.
11. Package Management (XSLT 3.0)
- XSLT 1.0/2.0: Does not support package management or versioning.
- XSLT 3.0: Supports XSLT Packages, a system for bundling reusable components with version control. This improves maintenance and distribution of stylesheets.
12. Extensibility (XSLT 3.0)
- XSLT 1.0: Extending XSLT with custom functions or features is not easy.
- XSLT 2.0/3.0: Offers a more extensible architecture with support for custom functions and integration with external processors and libraries, enabling greater flexibility in creating complex transformations.
13. XPath 3.1 (in XSLT 3.0)
- XSLT 3.0: Includes XPath 3.1 support, which introduces further improvements such as:
- Support for higher-order functions.
- Enhanced regular expression capabilities.
- More functions for string manipulation, like
upper-case()
,lower-case()
, etc.
14. Compatibility and Standardization
- XSLT 2.0 and 3.0: Both are widely adopted as standard by major XML processing libraries (e.g., Saxon) and allow better compatibility with modern XML-based systems and tools.
- XSLT 1.0: Is quite old and may not be supported in some modern environments, though it still has legacy support.
You can use Saxon classes in Xojo projects and enjoy XSLT 2.0. In the next week, we’ll show you how to use this for electronic invoices