logolineright
bottomhttp://xml.apache.org/http://www.apache.org/http://www.w3.org/
join
Home
separator
Xalan-J 2.7.1
Charter
separator
What's New
Release Notes
separator
Overview
Download/Build
Getting Started
Using XSLTC
separator
FAQs
separator
Sample Apps
Command Line
separator
Features
Transform API
XPath API
Usage Patterns
separator
Xalan-J API
Public APIs
DTM
separator
Extensions
Extensions Library
XSLTC Exts
separator
Xalan 2 Design
XSLTC Design
separator
Building a release
Testing
Bug Reporting
separator
Contact us
close
Introduction
 

XSLTC supports the use of extension functions implemented in external Java classes. It also supports the nodeset, output/redirect and EXSLT extension functions. Extension support in XSLTC is still under development. It is currently not as complete as the extension support in the Xalan-Java Interpretive processor. There are constraints in some areas.


Constraints
 

In addition to the constraints listed below for each particular extension, extension support in XSLTC also has the following limitations:

  1. Extension element is not supported. The extension element mechanism is closely related to the internal implementation of the XSLT processor. The current extension element mechansim is designed for the Xalan-Java Interpretive processor. It does not work with XSLTC.
  2. The xalan:component and xalan:script extension elements are not supported at the moment. This has the implication that you cannot use scripting languages (e.g. javascript) with XSLTC.
  3. The SQL extension is not supported in XSLTC at the moment.

Java extension
 

Java extension is supported in XSLTC. Constructors, static and instance methods are all supported. You can use any of the three namespace formats (Java, package and class) in your stylesheet.

The official namespace for the Java extension is http://xml.apache.org/xalan/java. The old XSLTC Java namespace http://xml.apache.org/xalan/xsltc/java and the old Xalan-Java namespace http://xml.apache.org/xslt/java are also supported for backward compatibility.

All usage syntax for the Xalan-Java Interpretive processor also applies to XSLTC with only one exception: XSLTC does not support the notion of default object in class format namespace. When using instance methods, you should always specify the class instance as the first argument to the extension function.

The following example shows you how to call constructors, static, and nonstatic functions, using different namespace formats:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:date="http://xml.apache.org/xalan/java/java.util.Date"
    xmlns:java_lang="http://xml.apache.org/xalan/java/java.lang"
    exclude-result-prefixes="date java_lang">

  <!--
  * test: construction of Date object using a parameter calculated
  *       by a static call to the java.lang.Math object. Then call
  *       a non-static method (getTime()) on the newly created Date
  *       object. Demonstrates calling constructors, static functions
  *       (Math.max) and non-static functions (getTime()).
  *
  * Output:
  *   <?xml version="1.0" encoding="UTF-8"?>
  *     Date of object: Sat Nov 30 17:32:41 EST 2002
  *     Time of object: 1038695561000
  *
  -->

  <xsl:template match="/">
   <!-- create Date object with calculated parameter -->
   <xsl:variable name="dateObject"
     select="date:new(
         java_lang:Math.max(1027695561000,1038695561000)
     )"/>
   Date of object: <xsl:value-of select="$dateObject"/>
   Time of object: <xsl:value-of select="date:getTime($dateObject)"/>
  </xsl:template>

  </xsl:stylesheet>
  
NoteAlways use the abbreviated syntax for Java extension, because the xalan:component/xalan:script constructs are not supported in XSLTC.

EXSLT extensions
 

The following EXSLT extension modules are supported in XSLTC:

The functions in the dynamic module (e.g. evaluate) are not supported because of the XSLTC design limitation. Work is currently underway on user defined EXSLT functions (with the function and result elements).

The nodeset and objectType extension functions in the common module are implemented natively in XSLTC. For all other EXSLT extension functions, XSLTC uses the same implementation as the Xalan-Java Interpretive processor. The implementation classes are under org.apache.xalan.lib. Depending on the packaging, these classes can be in a separate jar file (e.g. xalan.jar) from the XSLTC classes. In this case you need to add the jar file containing the EXSLT classes to your classpath in order to use EXSLT extensions in XSLTC.


nodeset
 

XSLTC also supports the nodeset() extension function for transforming an RTF (result tree fragment) into a node set.

The nodeset extension can be used as an XSLTC extension function in the namespace http://xml.apache.org/xalan/xsltc, a Xalan-Java extension function in the namespace http://xml.apache.org/xalan, an EXSLT extension function in the namespace http://exslt.org/common or as a standard XPATH function. When it is used as an EXSLT extension function, you need to refer to the nodeset extension function as node-set.

The following exmaple shows you how to use the nodeset extension function in different namespaces:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"        
  xmlns:xsltc-extension="http://xml.apache.org/xalan/xsltc"
  xmlns:xalan="http://xml.apache.org/xalan"
  xmlns:exslt="http://exslt.org/common"
  version="1.0">
  <xsl:template match="/">
    <xsl:variable name="rtf">
      <docelem>
        <elem1>elem1</elem1>
        <elem2>elem2</elem2>
      </docelem>
    </xsl:variable>
    <!-- Use nodeset as an XSLTC extension function -->
    <xsl:value-of select="xsltc-extension:nodeset($rtf)/docelem/elem1"/>
    <!-- Use nodeset as a Xalan-Java extension function -->
    <xsl:value-of select="xalan:nodeset($rtf)/docelem/elem1"/>
    <!-- Use nodeset as an EXSLT extension function -->
    <xsl:value-of select="exslt:node-set($rtf)/docelem/elem1"/>
    <!-- Use nodeset as standard function -->
    <xsl:value-of select="nodeset($rtf)/docelem/elem1"/>
  </xsl:template> 
</xsl:stylesheet>

NoteThe preferred solution is to use the EXSLT node-set function so that it can work with multiple XSLT processors.

output/redirect
 

XSLTC supports the output extension element for redirecting the output to one or more files. The output extension element is also aliased to the write extension element in the namespace http://xml.apache.org/xalan/redirect. Therefore you can use it in the same way as the redirect extension in Xalan-Java.

You can use the file and append attributes with the output/redirect extension. The value of the file attribute is an attribute value template. If the value of the append attribute is true or yes, the output is appended to the file rather than overwriting the file.

The following example shows you how to use the output/redirect extension:

 <xsl:stylesheet 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xsltc="http://xml.apache.org/xalan/xsltc"
   xmlns:redirect="http://xml.apache.org/xalan/redirect"
   extension-element-prefixes="xsltc redirect"
   version="1.0">
   <xsl:template match="/">
     <xsl:text>This goes to standard output</xsl:text>
     <xsltc:output file="blob.xml">
       <xsl:text>This ends up in the file 'blob.xml'</xsl:text>
     </xsltc:output>
     <redirect:write file="blob2.xml">
       <xsl:text>This ends up in the file 'blob2.xml'</xsl:text>
     </redirect:write>
   </xsl:template>
</xsl:stylesheet>


dot
Copyright © 2006 The Apache Software Foundation. All Rights Reserved.