Link to home
Start Free TrialLog in
Avatar of PurpleSlade
PurpleSlade

asked on

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

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

see:
http://xml.apache.org/xalan-j/faq.html#faq-N100D6

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)
serializer.jar
xalan.jar
xercesImpl.jar
xml-apis.jar

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("{http://xml.apache.org/xslt}indent-amount", "4");
                  transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                  transformer.transform(source, result);
Avatar of PurpleSlade
PurpleSlade

ASKER

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:

i.e.
[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?
SOLUTION
Avatar of R7AF
R7AF
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
eet

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?
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();

with:
                  TransformerFactory tFactory = new net.sf.saxon.TransformerFactoryImpl();
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?
Hey, you just said it: that's another question. ;-)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.