Stylesheet first won't compile under Java 1.5, then can't find function tokenize

PurpleSlade used Ask the Experts™
OK, I had a stylesheet that was working fine in Java 1.4, but when I tried and compile it in 1.5 I was getting a FATAL ERROR: Cant' compile stylesheet.  So, I searched the net and found out that 1.5 is packaged with an old version of Java and that you need to override it by creating a directory called "endorsed" in the jre lib


SO ... I created C:\Program Files\Java\jdk1.5.0_05\jre\lib\endorsed
and put the following jars in it as it specifies (from Xalan 2.7)

and now I'm getting the following error:
SystemId Unknown; Line #79; Column #61; Could not find function: tokenize
SystemId Unknown; Line #79; Column #61; function token not found.
(Location of error unknown)java.lang.NullPointerException
Error: java.lang.NullPointerException

So basically I'm at my wits end.  The stylesheet works fine when I am running it in Oxygen XML editor using Saxon 8B.

So I guess my question becomes, how do I make the program use Saxon 8B, or do you know of a way that I can fix this?

This is how i set up the transformer
                  Transformer transformer = TransformerFactory.newInstance().newTransformer();
                  transformer.setOutputProperty(OutputKeys.METHOD, "xml");
                  transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                  transformer.setOutputProperty("{}indent-amount", "4");
                  transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                  transformer.transform(source, result);
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®


Additionally, I am quite confused about all the different versions of Java that I have on my machine.  When I type in Java -version, it says:
java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode)

However, when I try and compile things at the command prompt using verbose, it is stating that it is getting things from 1.4.2_06:

[loading C:\j2sdk1.4.2_06\jre\lib\rt.jar(org/xml/sax/InputSource.class)]
[loading C:\j2sdk1.4.2_06\jre\lib\rt.jar(org/xml/sax/SAXException.class)]
[loading C:\j2sdk1.4.2_06\jre\lib\rt.jar(java/lang/Object.class)]
[loading C:\j2sdk1.4.2_06\jre\lib\rt.jar(java/lang/String.class)]

In my IDE, it is compiling with JDK version 1.5.0_05


Also, when I go to the Java Control Panel and see what my Runtime Settings I see that I have 9 different versions and that they are all checked as enabled.  Is that OK?
Top Expert 2007
I understand that you're trying to move to Java 1.5. You're using Windows I see and JAVA_HOME is set to 1.5.0_11. So any program that uses $JAVA_HOME will use 1.5. What command do you use when you compile stuff?

I would move all the different versions of Java to another folder, i.e. C:\dump\. You can move them back later. Just keep 1.5. Then you will get errors along the way and you'll see what versions are actually used. You can even reinstall 1.5 to be sure.

You say the stylesheet worked in 1.4, but not in 1.5 and that 1.5 uses an old version of "java"? I would think that everything in 1.5 is newer or at least not older. In 1.5 some functions are not supported.
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.


Hello R7AF - I misspoke about the old version of Java - I meant that apparently Java 1.5 ships with an older version of Xalan-Java, thus the need to create the override directory.  It works to the extent that when I compile, it now does look in that directory.

I also figured out what my problem was with the version of java.  I had set the path variable to contain a direct path to the 1.4 version of java, so even though I had JAVA_HOME set to the 1.5 version it was still compiling from 1.4 via javac command.

At runtime with the stylesheet, I get the following error:
ERROR:  'Error checking type of the expression 'funcall(tokenize, [step("self",
-1), literal-expr(\^)])'.'
FATAL ERROR:  'Could not compile stylesheet'
javax.xml.transform.TransformerConfigurationException: Could not compile stylesh

However, this stylesheet worked just fine in version 1.4.


OK, so now I seem to have found that the problem is that my stylesheet uses xslt 2.0 language, whereas xalan is a 1.0 processor.  So how do I get it to work with a 2.0 processor?
Top Expert 2007

I don't understand this. How can it be XSLT 2.0 when it worked with Java 1.4? With what xslt processor did it work then?


I really don't understand it either.  Somehow it must have been using something that was 2.0 compliant, but possibly with 1.5 they made it default to xalan.  I am guessing that I have to specify the processor now, whereas I didn't before.  I have classpaths configured to hit xerces, but maybe now 1.5 overrides that unless you explicitly state which processor it should use.  At any rate, do you know of a way to specify which processor it uses?  I have been searching for examples but am not finding many.


OK, I figured it out.  I'm not sure what changed in my versions, but I was able to explicitly specify Saxon's parser by replacing:

//                  TransformerFactory tFactory = TransformerFactory.newInstance();

                  TransformerFactory tFactory = new net.sf.saxon.TransformerFactoryImpl();
Top Expert 2007

Glad you solved it!


Thanks, me too - hey I have another question - when using external jar files, like saxon8.jar, I usually just put it in a folder called "jars" and then set my classpath to hit that jar.  Is there a more eloquant way to do it, like putting it in another directory where I don't have to set my classpath?  How do you organize your jar files?
Top Expert 2007

Hey, you just said it: that's another question. ;-)
Java 1.4 used Xalan as the default.
Java 1.5 uses XSLTC as the default.

You want to use Saxon for XSLT 2.0, since you're using the tokenize function, correct?
Instead of including xalan.jar, include saxon8.jar in your classpath.

The reason why you're getting the error is probably because xalan doesn't support tokenize, since it's XSLT 2.0.


Well I was trying to throw you another easy question R7AF since I basically answered my own question, rather than asking them to be refunded.  :/  

But yes, jkmyoung, that pretty much sums up what I figured out.  I think that what confused me the most is that my stylesheet didn't work once I was using 1.5, but that was probably due to minor configuration changes, rather than me assuming that it was xalan.  Xalan in fact had nothing to do with it since it is a 1.0 processor.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial