Jump to content

Recommended Posts

Posted

You have XSLT 1.0 in FileMaker built-in as well as in our plugin function to use XSLT (XML.ApplyStylesheet). With our Saxon functions you get XSLT 3.0 and you can enjoy all the 2.0 and 3.0 features in your FileMaker solution and 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(), and for-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 the try-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.

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 functions in your FileMaker solutions and enjoy XSLT 2.0. In the next week, we'll show you how to use this for electronic invoices.

Posted (edited)

This list is full of inaccurate, even downright false statements. For example, both xsl:key and xsl:message are available in XSLT 1.0.

Not to belittle the advantages of XSLT 2.0 and 3.0, it needs to be stated that XSLT 1.0 is Turing-complete - which means it can produce any output that depends solely on the input. True, some operations - such as grouping - are easier to perform in XSLT 2.0 +, but that's just a matter of convenience.

If I had to point out the main advantages of the later versions, I would focus on:

  • Dates: XSLT 2.0+ has dedicated functions to handle dates, times and dateTimes (what we call timestamps in FM), including the ability to generate the current date and time.
  • Random: XSLT 2.0+ can generate random numbers. The XSLT 3.0 random generator is especially powerful.
  • RegEx: XSLT 2.0+ supports processing text using Regular Expressions.
  • JSON: XSLT 3.0 can both parse JSON input data as well as produce a JSON output.

Still, even with this in mind it needs to be pointed out that many XSLT 1.0 processors support extensions that enhance their capabilities beyond pure XSLT 1.0. The processor embedded in FMP has always allowed producing the current date and time or generating a random number, as well as other goodies. And now, If you are using the latest versions of FMP, you also get access to a wide array of functions that manipulate dates. So really it's back to a question of convenience.

The crucial point here, IMHO, is this: as a database developer, your interest in XSLT is purely for input and output. So I'll be watching the next installment to see if it provides a way to replace the embedded processor during import and export. If not, then there is very little attraction to having this available in a plugin. You can always do as I have done for a long time now and use the standalone Saxon processor from the command line.

 

 

Edited by comment
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.