XML technologies / XSLT / XSLT Kochbuch / Extending and embedding XSLT / Script extension elements

(Excerpt from "XSLT Kochbuch" by Sal Mangano)

Script extensions are Java extensions, with the difference that these extensions are implemented within a xalan:script element:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" xmlns:MyExt="xalan://com.AcmeX.MyExtensionElement" extension-element-prefixes="MyExt">
  <xalan:component prefix="rep" elements="repeat">
    <xalan:script lang="javascript">
      function superExtension(ctx, elem)
      {
        /* ... */
        return null ;
      }
    </xalan:script>
  </xalan:component>
  <xsl:template match="*">
    <myExt:superExtension attr1="val1" attr2="val2">
      <!-- ... -->
    <myExt:superExtension>
  </xsl:template>
</xsl:stylesheet>

As with Java, the returned value is placed in the result tree, but here you return null to disable this effect for scripting languages. An example can be found in the recipe Extending XSLT with JavaScript.

XSLT 2.0

At present, I am not aware of any efforts to upgrade from Xalan to XSLT 2.0.

  

 

 

 

back to top