Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 14th, 2006, 06:08 AM
Authorized User
 
Join Date: Oct 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default java.lang.ClassCastException: org.apache.xpath.obj

Hi,

I have the following XSLT:

...
<xsl:variable name="NumberOfUnits">
<xsl:for-each select="../OrderItem">
<xsl:if test="normalize-space(ItemInfo/StdPack/@Qty) = ''">
<OrderItem name="{name()}" Units="{ItemQuantities/@OrderQty}"/>
</xsl:if>
<xsl:if test="normalize-space(ItemInfo/StdPack/@Qty) != ''">
<OrderItem name="{name()}" Units="{ItemQuantities/@OrderQty * ItemInfo/StdPack/@Qty}"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
...

Can I use the following path in my sum() function to access the NumberOfUnits variable (from above)?

...
<NbrOfUnits>
<xsl:value-of select="sum(($NumberOfUnits)/OrderItem/@Units)"/>
</NbrOfUnits>
...

When doing this, I get the following exception:
java.lang.ClassCastException: org.apache.xpath.objects.XRTreeFrag ...

Has anyone come across this situation?

I am using Saxon 8.6.1. I do not have access to the box which has the code jars, so I am not sure where the exception is being thrown from.

Thanks!

 
Old December 14th, 2006, 06:28 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Are you sure you are using Saxon? The exception suggests otherwise - it suggests you are using Xalan. Or it could be that you've done something with Xalan/Xerces in your application and have passed the result to Saxon. Try telling us more about how you are running the application, what's on the classpath, what the full stack trace looks like. In a working transformation, do <xsl:comment><xsl:value-of select="system-property('xsl:vendor')"/></xsl:comment> so there is no doubt about which processor you are running.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 14th, 2006, 10:39 AM
Authorized User
 
Join Date: Oct 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank for the response

Actually i have Saxon8.jar file in the classpath

I am running the transformation(Application) in webMethods Server


The Processor it is displaying in the translated XML is

The Detailed StackTrace Exception is

java.lang.RuntimeException: java.lang.ClassCastException: org.apache.xpath.objects.XRTreeFrag
        at org.apache.xalan.transformer.TransformerImpl.run(T ransformerImpl.java:3456)
        at org.apache.xalan.transformer.TransformerHandlerImp l.endDocument(TransformerHandlerImpl.java:389)
        at org.apache.xerces.parsers.AbstractSAXParser.endDoc ument(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentScannerImpl.endE ntity(Unknown Source)
        at org.apache.xerces.impl.XMLEntityManager.endEntity( Unknown Source)
        at org.apache.xerces.impl.XMLEntityScanner.load(Unkno wn Source)
        at org.apache.xerces.impl.XMLEntityScanner.skipSpaces (Unknown Source)
        at org.apache.xerces.impl.XMLDocumentScannerImpl$Trai lingMiscDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse( Unknown Source)
        at org.apache.xalan.transformer.TrAXFilter.parse(TrAX Filter.java:153)
        at org.apache.xalan.transformer.TransformerIdentityIm pl.transform(TransformerIdentityImpl.java:432)
        at com.logistics.javalib.xml.XSLFilterChainTransforme r.transform(XSLFilterChainTransformer.java:189)
        at com.logistics.messaging.router.translators.XMLToXM LTranslator.translateInbound(XMLToXMLTranslator.ja va:93)
        at RouterOperations.TranslateAndSend(RouterOperations .java:2610)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:85)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:58)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
        at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
        at com.wm.app.b2b.server.JavaService.baseInvoke(JavaS ervice.java:322)
        at com.wm.app.b2b.server.invoke.InvokeManager.process (InvokeManager.java:612)
        at com.wm.app.b2b.server.invoke.StatisticsProcessor.p rocess(StatisticsProcessor.java:44)
        at com.wm.app.b2b.server.invoke.ServiceCompletionImpl .process(ServiceCompletionImpl.java:226)
        at com.wm.app.b2b.server.invoke.ValidateProcessor.pro cess(ValidateProcessor.java:49)
        at com.wm.app.b2b.server.ACLManager.process(ACLManage r.java:198)
        at com.wm.app.b2b.server.invoke.DispatchProcessor.pro cess(DispatchProcessor.java:39)
        at com.wm.app.b2b.server.AuditLogManager.process(Audi tLogManager.java:411)
        at com.wm.app.b2b.server.invoke.InvokeManager.invoke( InvokeManager.java:521)
        at com.wm.app.b2b.server.invoke.InvokeManager.invoke( InvokeManager.java:369)

 
Old December 14th, 2006, 11:25 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Well, you're definitely running Xalan rather than Saxon. Which doesn't itself explain the exception, but if you're loading the wrong software then it's not that surprising. Because web servers do funny things with class loaders and classpaths, the best strategy for ensuring you load Saxon is probably to make a call of System.setProperty( "javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl") from your application code just before the newInstance() call; alternatively if you don't mind a compile-time dependency on Saxon in your code, just instantiate net.sf.saxon.TransformerFactoryImpl directly (it's a lot faster anyway).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 15th, 2006, 03:13 AM
Authorized User
 
Join Date: Oct 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Issues solved! That worked like a charm! Thanks!!

Here is what we were doing:
SAXParserFactory parser = SAXParserFactory.newInstance();
parser.setNamespaceAware(true);
XMLReader lastFilter = parser.newSAXParser().getXMLReader();
SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactory
                .newInstance();

and we thought this code would use the Saxon parser.
However, it was internally invoking Xalan (both Xalan and Saxon were in the classpath).

We made the change as per your suggestion and included this line just before the call to newInstance():
System.setProperty("javax.xml.transform.Transforme rFactory",
"net.sf.saxon.TransformerFactoryImpl");

And now it works fine!

Thanks again!







Similar Threads
Thread Thread Starter Forum Replies Last Post
"java.lang.classNotFound Exception:org.gjt.mm.mysq anwarraja Java Databases 4 September 12th, 2007 11:04 PM
org.apache.jasper.JasperException:The value for th Lijin Apache Tomcat 1 January 18th, 2007 08:05 PM
org.apache.struts.* bongo76 Apache Tomcat 1 April 18th, 2004 05:06 AM
org.apache.strut.util.GenericDataSource elbicho JSP Basics 1 August 23rd, 2003 03:55 AM
java.lang.NoClassDefFoundError: org/xml/sax/XMLRea kcheung XSLT 0 August 8th, 2003 08:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.