Scripting Extension Elements
Scripted extensions are very similar to Java extensions, except the
extension is implemented inside of the
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 return value is placed into the result tree, but
you return null
to disable this effect with
scripting languages. See Recipe 12.13 for an example.
Get XSLT Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.