You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Voytenko, Dimitry" <dv...@reveredata.com> on 2003/04/24 20:40:55 UTC
RE: Xalan/Xerces DOM implementation confusion. WAS: The test cond
itional doesn't seem to work
Hi,
While resolving issue below, I tried:
transformer.setParameter(paramName,doc.getDocumentElement().getChildNodes())
;
It didn't work as expected, b/c in the XObjectFactory.create(Object,
XPathContext) there's code:
// This next three instanceofs are a little worrysome, since a NodeList
// might also implement a Node!
else if (val instanceof org.w3c.dom.Node)
{
result = new XNodeSetForDOM((org.w3c.dom.Node)val, xctxt);
}
// This must come after org.w3c.dom.Node, since many Node
implementations
// also implement NodeList.
else if (val instanceof org.w3c.dom.NodeList)
{
result = new XNodeSetForDOM((org.w3c.dom.NodeList)val, xctxt);
}
As comments indicate, there's a confusion, b/c implementations of
org.w3c.dom.Node sometimes also implement NodeList interface. Thus, Xerces's
NodeImpl returns "this" for getChildNodes(), i.e. two calls will yield the
same result:
transformer.setParameter(paramName,doc.getDocumentElement());
and
transformer.setParameter(paramName,doc.getDocumentElement().getChildNodes())
;
Which is not very obvious from the usage stand-point.
I'm not sure this can be classified as a Xalan's bug. But there's definetely
confusion here. Probably this would be a good idea to document this feature
in the FAQ or known issues among with recommendations on how to deal with
this situation. B/c it seams that this is the only valid way to specify such
a parameter using javax interfaces.
Thanks,
Dimitry
-----Original Message-----
From: Voytenko, Dimitry [mailto:dvoytenko@reveredata.com]
Sent: Thursday, April 24, 2003 11:25
To: 'kroberts@mmm.com'; xalan-j-users@xml.apache.org
Subject: RE: The test conditional doesn't seem to work
Hi Keith,
>> XObject xObj = new XNodeSetForDOM(doc.getChildNodes(), new
XPathContext());
>> transformer.setParameter(paramName,xObj);
Try instead,
transformer.setParameter(paramName,doc.getDocumentElement());
and then
<xsl:copy-of select="$paramName"/>
This should work, I just tried this.
Xalan will convert doc.getDocumentElement() to node-set automatically. Your
exception is most probably being thrown b/c of another XPathContext you use
to initialize your XNodeSetForDOM.
The only problem here, is that you better avoid using getChildNodes() in the
transformer.setParameter() calls. There's confusion b/c Xerces Node's
implementation implements both Node and NodeList interfaces.
Thanks,
Dimitry
-----Original Message-----
From: kroberts@mmm.com [mailto:kroberts@mmm.com]
Sent: Wednesday, April 23, 2003 18:20
To: xalan-j-users@xml.apache.org
Subject: RE: The test conditional doesn't seem to work
Ok, It looks like this could be an issue with the way Java is setting the
params.
Here is the xalan-1 approach to setting params:
DOMParser dp = new DOMParser();
dp.parse(parameterData);
XObject xObj = new XNodeSet(dp.getDocument
().getChildNodes());
XSLTProcess xsltProcessor ....;
xsltProcessor.setStylesheetParam(paramName,xObj);
The new xalan-2 code sets params this way:
Document doc = XmlUtil.parseDocument(parameterData);
XObject xObj = new XNodeSetForDOM(doc.getChildNodes(),
new XPathContext());
Transformer transformer ....;
transformer.setParameter(paramName,xObj);
I wrote a test servlet to run a stylesheet that does a copy: here is the
stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version
="1.0">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1"/>
<xsl:param name="theParam"/>
<xsl:template match="/">
<xsl:copy-of select="$theParam"/>
</xsl:template>
</xsl:stylesheet>
When I ran it; I got an out of bounds exception on the copy-of line of
code.
Java must be passing in bad data or something.
Transformation failed: javax.xml.transform.TransformerException:
java.lang.Array
IndexOutOfBoundsException
; SystemID: http://pc034144.code3.com:80//public_xsl/debugparam.xsl; Line#:
12;
Column#: 42
javax.xml.transform.TransformerException:
java.lang.ArrayIndexOutOfBoundsExcepti
on
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Tr
ansformerImpl.java:2323)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResul
t.java:696)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Tr
ansformerImpl.java:2318)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResul
t.java:696)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Tr
ansformerImpl.java:2318)
at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(Tran
sformerImpl.java:2185)
at
org.apache.xalan.transformer.TransformerImpl.transformNode(Transforme
rImpl.java:1263)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp
l.java:671)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp
l.java:1179)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp
l.java:1157)
at com.mmm.ciws.xsl.StylesheetRoot.process(StylesheetRoot.java:74)
at com.mmm.ciws.xsl.XSLTProcessor.process(XSLTProcessor.java:186)
at com.mmm.ciws.xsl.TransformXSL.transform(TransformXSL.java:196)
at com.mmm.ciws.xsl.TransformXSL.transform(TransformXSL.java:157)
at com.mmm.ciws.TestTransform.service(TestTransform.java:125)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
(ServletStubImpl.java:1058)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:401)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:306)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
n.run(WebAppServletContext.java:5445)
at
weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
eManager.java:780)
at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
rvletContext.java:3105)
at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2588)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)
Any and all help would be greatly appreciated.
Thanks
Keith....
_____________________________________________________
Revere Data, LLC, formerly known as Sector Data, LLC, is not affiliated with
Sector, Inc., or SIAC.
_____________________________________________________
Revere Data, LLC, formerly known as Sector Data, LLC, is not affiliated with
Sector, Inc., or SIAC.