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>
|
 |
 |
 |
 |
 |
Always use the
abbreviated syntax for Java extension, because the
xalan:component/xalan:script constructs are not supported in
XSLTC. |
|