Subject: java.lang.ClassCastException: org.apache.xpath.obj
Posted By: ksskumar Post Date: 12/14/2006 5:08:40 AM
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!

Reply By: mhkay Reply Date: 12/14/2006 5:28:30 AM
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
Reply By: ksskumar Reply Date: 12/14/2006 9:39:48 AM
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  <!-- IBM Corporation-->

The Detailed StackTrace Exception is

java.lang.RuntimeException: java.lang.ClassCastException: org.apache.xpath.objects.XRTreeFrag
        at org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:3456)
        at org.apache.xalan.transformer.TransformerHandlerImpl.endDocument(TransformerHandlerImpl.java:389)
        at org.apache.xerces.parsers.AbstractSAXParser.endDocument(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentScannerImpl.endEntity(Unknown Source)
        at org.apache.xerces.impl.XMLEntityManager.endEntity(Unknown Source)
        at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
        at org.apache.xerces.impl.XMLEntityScanner.skipSpaces(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.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(TrAXFilter.java:153)
        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:432)
        at com.logistics.javalib.xml.XSLFilterChainTransformer.transform(XSLFilterChainTransformer.java:189)
        at com.logistics.messaging.router.translators.XMLToXMLTranslator.translateInbound(XMLToXMLTranslator.java:93)
        at RouterOperations.TranslateAndSend(RouterOperations.java:2610)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
        at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
        at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:322)
        at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:612)
        at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
        at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:226)
        at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:49)
        at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:198)
        at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:39)
        at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.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)

Reply By: mhkay Reply Date: 12/14/2006 10:25:12 AM
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
Reply By: ksskumar Reply Date: 12/15/2006 2:13:53 AM
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.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");


And now it works fine!

Thanks again!



Go to topic 53658

Return to index page 92
Return to index page 91
Return to index page 90
Return to index page 89
Return to index page 88
Return to index page 87
Return to index page 86
Return to index page 85
Return to index page 84
Return to index page 83