Tuesday, December 23, 2008

Xalan, Java, XSLTC

What is difference in xalan XSLT processor and and SUN XSLTC compiler ?
They are completely different products. They are both XSLT processors, but they do the same job in very different ways: Xalan (like nearly all other XSLT processors) is in effect a stylesheet interpreter while XSLTC is a stylesheet compiler: it generates Java bytecodes which can be executed directly by the Java VM.

IBM's JDK includes XSLT4J which is based on Xalan. IBM JDK 1.5 it is based on Xalan Java 2.6.0. So there should be no issue moving from Xalan to the IBM JDK.

SUN's JDK 1.5 contains only XSLTC which does not have all of the features of the Xalan interpretive processor. The main differences are in extension support. XSLTC does not support the following extensions:
  • Dynamic EXSLT extensions
  • NodeInfo extension functions
  • SQL library extension
  • PipeDocument extension
  • Evaluate extension
  • Tokenize extension
  • JavaScript extensions
In addition to the above :
  • It does not support all of the XSLT type to Java type conversions that the interpreter supports. You may be able to work around this by adding an explicit cast (e.g. call to the boolean(), number(), etc. function).
  • It does not work well if you return a Boolean object instead of a boolean from a Java extension, or a Double object instead of a double, etc. You can work around this by returning the primitive types instead of objects.
  • It does not provide a default object when the method being called is not static and no object is provided in the extension call. You can work around this by providing the object in the extension call.
It only supports the abbreviated syntax for Java extension calls (see Using the abbreviated syntax for extensions implemented in Java)

So, when you use SUN's JDK 1.5 or later for Transformation on an XSL like this






You will get the following error:

ERROR: 'The first argument to the non-static Java function 'completeTaskOnExit' is not a valid object reference.'
FATAL ERROR: 'Could not compile stylesheet'
Exception in thread "main" javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(Unknown Source)
at Transform.main(Transform.java:29)


If you want to continue to use the Xalan interpreter with SUN's JDK you can use the endorsed standards override mechanism - Create the "endorsed" directory in "...\jre\lib\endorsed" and copy the Xalan 2.7 files into it.

If you are using Xalan 2.8, then extracting "xalan.jar" from 'Xerces-J-tools.2.8.1.zip' and copying it into the 'endorsed' directory solves the problem of not finding 'org.apache.xalan.processor.TransformerFactoryImpl'.

OR you can also force the SUN JDK to use Xalan by setting the System property :

System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl");

References:
Ad xslt-sample (not working on Java 1.5 & 1.6) ...
what is difference in xalan XSLT processor and and SUN XSLTC compiler
jdk1.5 and Xalan.jar differences?

Thursday, December 11, 2008

Argument with a stupid

Never argue with a stupid person. First they'll drag you down to their level, then they will beat you with experience.
Courtesy : Teja's Gtalk status message

Monday, December 1, 2008

Exception Details in JavaScript


function displayException(e,method)
{
if(method != null)
{
alert('Error occured in ' + method);
}
if(e instanceof EvalError)
{
alert('Eval function is used in an incorrect manner. Error name: ' + e.name + '. Error message: ' + e.message);
}
else if(e instanceof RangeError)
{
alert('A numeric variable exceeds its allowed range. Error name: ' + e.name + '. Error message: ' + e.message);
}
else if(e instanceof ReferenceError)
{
alert('An invalid reference is used. Error name: ' + e.name + '. Error message: ' + e.message);
}
else if(e instanceof SyntaxError)
{
alert('Syntax error occured while parsing JavaScript code. Error name: ' + e.name + '. Error message: ' + e.message);
}
else if(e instanceof TypeError)
{
alert('The type of a variable is not as expected. Error name: ' + e.name + '. Error message: ' + e.message);
}
else if(e instanceof URIError)
{
alert('encodeURI() or decodeURI() functions are used in an incorrect manner. Error name: ' + e.name + '. Error message: ' + e.message);
}
else
{
alert('An unspecified error occurred!. Error name: ' + e.name + '. Error message: ' + e.message);
}
}