You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Vadim Zaliva <lo...@us.matranet.com> on 2000/10/20 02:36:38 UTC
cascading processors
Hi!
I need to pass some XML through several transformations sequentaly. I
reworked code from Pipe example and come up with following method:
/**
* This method is working, but sometimes produce exceptions.
* We suspect bug in XERCES-J.
*/
public String veryFastGenerateHTML(String xml, String[]
xsl_name) throws XSLTException
{
int n=xsl_name.length, last=xsl_name.length-1;
if(n==0)
throw new XSLTException("Empty stylesheets list provided");
if(n==1)
return fastGenerateHTML(xml, xsl_name[0]);
StylesheetRoot sh[]=new StylesheetRoot[n];
for(int i=0;i<n;i++)
{
sh[i] = (StylesheetRoot)compiled.get(xsl_name[i]);
if(sh[i]==null)
{
throw new XSLTException("Stylesheet: '"+xsl_name[i]+"' not
found!");
}
}
XSLTProcessor processor[] = new XSLTProcessor[n];
for(int i=0; i<n; i++)
{
processor[i] = (XSLTProcessor)pool.lease();
processor[i].reset();
}
try
{
for(int i=0; i<last; i++)
{
processor[i].setStylesheet(sh[i]);
processor[i].setDocumentHandler(processor[i+1]);
}
CharArrayWriter w = new CharArrayWriter();
processor[last].setStylesheet(sh[last]);
org.apache.xml.serialize.OutputFormat
of=sh[last].getOutputFormat();
of.setEncoding(Constants.Charset.UTF16);
processor[last].setDocumentHandler(sh[last].makeSAXSerializer(w, of));
processor[0].process(new XSLTInputSource(new
StringReader(xml)),
null,
new XSLTResultTarget(processor[1]));
return w.toString();
}
catch(IOException ex)
{
throw new XSLTException("HTML generation failed with following
IO exception: "+ex.getMessage());
}
catch(org.xml.sax.SAXException ex)
{
throw new XSLTException("HTML generation failed with following
SAX exception: "+ex.getMessage());
} finally
{
for(int i=0; i<n; i++)
pool.release(processor[i]);
}
}
It works fine, but from time to time produce exceptions
like this:
java.lang.NoSuchMethodError: org.w3c.dom.Attr: method
getOwnerElement()Lorg/w3c/dom/Element; not
found at
org.apache.xalan.xpath.xdom.XercesLiaison.getParentOfNode(XercesLiaison.java:395) at
org.apache.xalan.xpath.MutableNodeListImpl.isDOMNodeAfter(MutableNodeListImpl.java:499) at
org.apache.xalan.xpath.MutableNodeListImpl.isNodeAfter(MutableNodeListImpl.java:481) at
org.apache.xalan.xpath.MutableNodeListImpl.addNodeInDocOrder(MutableNodeListImpl.java:401) at
org.apache.xalan.xpath.MutableNodeListImpl.addNodeInDocOrder(MutableNodeListImpl.java:454) at
org.apache.xalan.xpath.MutableNodeListImpl.addNodesInDocOrder(MutableNodeListImpl.java:240) at
org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java:530) at
org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java:521) at
org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNodeLocator.java:321) at
org.apache.xalan.xpath.XPath.locationPath(XPath.java:964) at
org.apache.xalan.xpath.XPath.execute(XPath.java:1381) at
org.apache.xalan.xpath.XPath.execute(XPath.java:1354) at
org.apache.xalan.xpath.XPath.execute(XPath.java:311) at
org.apache.xalan.xslt.ElemValueOf.execute(ElemValueOf.java:186) at
org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateElement.java:661) at
org.apache.xalan.xslt.ElemLiteralResult.execute(ElemLiteralResult.java:254) at
org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateElement.java:661) at
org.apache.xalan.xslt.ElemLiteralResult.execute(ElemLiteralResult.java:254) at
org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateElement.java:661) at
org.apache.xalan.xslt.ElemLiteralResult.execute(ElemLiteralResult.java:254) at
org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateElement.java:661) at
org.apache.xalan.xslt.ElemTemplateElement.transformChild(ElemTemplateElement.java:1199) at
org.apache.xalan.xslt.ElemTemplateElement.processLocatedNode(ElemTemplateElement.java:1061) at
org.apache.xalan.xpath.SimpleNodeLocator.findChildren(SimpleNodeLocator.java:773) at
org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java:428) at
org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNodeLocator.java:321) at
org.apache.xalan.xpath.XPath.locationPath(XPath.java:964) at
org.apache.xalan.xpath.XPath.execute(XPath.java:1385) at
org.apache.xalan.xpath.XPath.execute(XPath.java:1354) at
org.apache.xalan.xpath.XPath.execute(XPath.java:311) at
org.apache.xalan.xslt.ElemTemplateElement.transformSelectedChildren(ElemTemplateElement.java:896)
at
org.apache.xalan.xslt.ElemApplyTemplates.execute(ElemApplyTemplates.java:176) at
org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateElement.java:661) at
org.apache.xalan.xslt.ElemTemplate.execute(ElemTemplate.java:145) at
org.apache.xalan.xslt.StylesheetRoot.process(StylesheetRoot.java:443) at
org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:647) at
com.matranet.MWC.webmodule.XSLTGeneratorImpl.fastGenerateHTML(XSLTGeneratorImpl.java:221) at
I suspect it is bug in XERCES-J. Please note, that I am using some
compiled stylesheet (StyleSheetRoot) from several threads simultaneously.
Could it be a problem?
Sincerely,
Vadim
--
;;-----------------------------------+-----------------------------------+
;; Vadim.Zaliva@us.matranet.com + Those who do not understand Unix +
;; Software Architect, Matranet Inc. + are condemned to reinvent it, +
;; http://www.matranet.com/ + poorly. (H. Spencer) +
;;-----------------------------------+-----------------------------------+