views:

42

answers:

1

i am once again having to cobble together a bit of XSLT into order to turn generated XML into (rather than simply generating HTML).

i'm having huge deja-vu this time again. i'm once again having to solve again basic problems, e.g.:

  • how to convert characters into valid html entity references
  • how to preserve whitespace/carriage returns when converting to html
  • how to convert to HTML as opposed to xhtml
  • how to convert dates from xml format into presentable format
  • how to tear apart strings with substring

This is all stuff that i've solved many times before. But every time i come back to XSLT i have to start from scratch, re-inventing the wheel every time.

If it were a programming language i would have a library of canned functions and procedures i can call. i would have subroutines to perform the commonly repeated tasks. i would inherit from a base class that already implements the ugly boilerplate stuff.

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

+1  A: 

This is all stuff that i've solved many times before. But every time i come back to XSLT i have to start from scratch, re-inventing the wheel every time.

This isn't necessary, of course.

If it were a programming language

Yes, XSLT is a programming language.

i would have a library of canned functions and procedures i can call. i would have subroutines to perform the commonly repeated tasks.

Yes, you can do this in XSLT.

i would inherit from a base class that already implements the ugly boilerplate stuff.

Yes, there is something quite similar in XSLT.

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

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

  1. <xsl:import>
  2. <xsl:include>
  3. <xsl:apply-templates>
  4. <xsl:call-template>
  5. <xsl:apply-imports>

XSLT 2.0 adds a few even more powerful features:

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

There have been several XSLT libraries for quite some time:

  1. FXSL (1.x and 2.x) implements Higher-Order Functions in XSLT 1.0/2.0
  2. FunctX -- a library of useful XSLT 2.0 and XQuery functions.

XPath 2.1 and XSLT 2.1 add Higher-Order Functions as standard. Functions become first-class datatypes.

Dimitre Novatchev
Whoever downvoted this answer, why are you afraid to point out the reasons? I pitty you, knowing what you most probably think of yourself.
Dimitre Novatchev