Recipe14.9.Java Extension Element


Recipe 14.9. Java Extension 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="MyExt" elements="superExtension">   <xalan:script lang="javasclass"                  src="/books/2/765/1/html/2/ xalan:// com.AcmeX.MyExtensionElement"/> </xalan:component>     <xsl:template match="*">      <myExt:superExtension attr1="val1" attr2="val2">         <!-- ... -->      <myExt:superExtension> </xsl:template>     </xsl:stylesheet>

The implementation must be via a Java class and method with the following signature:

public class com.AcmeX.MyExtensionElement {     public SomeType superExtension(           org.apache.xalan.extensions.XSLProcessorContext ctx,           org.apache.xalan.templates.ElemExtensionCall extensionElement)  {      //...  }     }

where SomeType designates the return type, ctx is an instance of the processing context, and extensionElement is the node corresponding to the stylesheet's extension element. In the method signature, you may also use the indicated types' superclasses. The com.AcmeX.MyExtensionElement base class can be anything you like, including none, as shown here.

Whatever the function returns is put into the result tree, so use void if you do not want this effect. See Recipe Recipe 14.15 for further details on the XSLProcessorContext and ElemExtensionCall classes.




XSLT Cookbook
XSLT Cookbook: Solutions and Examples for XML and XSLT Developers, 2nd Edition
ISBN: 0596009747
EAN: 2147483647
Year: 2003
Pages: 208
Authors: Sal Mangano

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net