XSLT: Is there a way to โ€œinheritโ€ finished functions?

Again I need to build some XSLT to turn the generated XML into (and not just HTML creation).

This time I have a huge deja vu. I have to solve the main problems again, for example:

  • how to convert characters to valid html entity links
  • How to save spaces / carriage returns when converting to html
  • how to convert to HTML, not xhtml
  • how to convert dates from an XML format to a presentable format
  • how to break lines with substring

That is all that I decided many times before. But every time I return to XSLT, I have to start from scratch, each time inventing a wheel.

If it were a programming language, I would have a library of canned functions and procedures that I can call. I would have routines for performing frequently repeated tasks. I would inherit from a base class that already implements ugly patterns.

Is there any way in XSLT to grow, expand and improve the ecosystem with canned code?

+4
source share
1 answer

This is all that I decided many times before. But every time I get back to the XSLT, I have to start by scratching, reinventing the wheel every time.

This is optional, of course .

If it was a programming language

Yes, XSLT is a programming language .

I will have a library of canned functions and procedures that I can call. I will have routines to perform frequently repeated tasks.

Yes, you can do it in XSLT.

I would inherit from a base class that already implements ugly template material.

Yes, XSLT has something very similar .

Is there any way in XSLT to grow, expand, and improve the ecosystem using complete code?

Even in XSLT 1.0, there are powerful standard features that support reuse :

XSLT 2.0 adds several even more powerful features :

  1. <xsl:function>
  2. Parameters for <xsl:apply-imports>
  3. <xsl:next-match>

For some time there have been several XSLT libraries :

  • FXSL ( 1.x and 2.x ) implements higher order functions in XSLT 1.0 / 2.0
  • FunctX is a library of useful features from XSLT 2.0 and XQuery.

XPath 2.1 and XSLT 2.1 add higher-order functions as standard . Functions become first-class data types.

+3
source

Source: https://habr.com/ru/post/1308519/


All Articles