Hi,
    I am doing the same thing, and in my test harness I reused the
Transformer several hundred times.
    After each transformation, you need to clear out the transformer. Look
at the javadoc, but I think the call is clearParameters()
    If you are working in a multithreaded enviroment, you will also need to
synchronize on the transformer.

for (Enumeration e=sources.elements(); e.hasMoreElements(); )
{
      String sourceID = (String)e.nextElement();
      System.out.println("\n=========" + sourceID + "\n");

    synchronized(transformer)
    {

      transformer.transform( new StreamSource(baseDir + sourceID),
              new StreamResult(destDir + sourceID));

       // clear here
       transformer.clearParameters();

    }

}

    easy,
    douglas d



----- Original Message -----
From: "Frank E. Weiss" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, February 02, 2002 2:31 PM
Subject: Reusing stylesheet more that 2 times raises exceptions


> This problem came from using Ant's Style task after I upgrading an
existing Ant project to use Xalan-J-2.2.0 after using
> 2.0.1. I isolated the problem by modifying the trax examples code (code
appended). The exceptions are sensitive to the
> order and number of input documents that are trying to be transformed with
a stylesheet reuse. Also, the stylesheet
> imports other stylesheets.
>
> I'm new to this list, but I did scan the bug reports for similar problems.
Anybody have suggestions as to how to solve
> this problem?
>
> Here are the exceptions that are encountered in the "community" test case:
>
> EXCEPTION:
> javax.xml.transform.TransformerException:
java.lang.ArrayIndexOutOfBoundsException
>         at
org.apache.xalan.transformer.TransformerImpl.transformToRTF(TransformerImpl.
java:1741)
> ...
> ---------
> java.lang.ArrayIndexOutOfBoundsException
>         at
org.apache.xalan.transformer.ResultTreeHandler.flushElem(ResultTreeHandler.j
ava:868)
> ...
> ---------
> java.lang.ArrayIndexOutOfBoundsException
>         at
org.apache.xml.utils.SuballocatedIntVector.elementAt(SuballocatedIntVector.j
ava:453)
>
>
> Here's the modified Trax Examples source code:
> ==========================
>  public static void exampleTransformerReuse(Vector sources, String xslID)
>  throws TransformerException, TransformerConfigurationException
>  {
>   TransformerFactory tfactory = TransformerFactory.newInstance();
>   Transformer transformer = tfactory.newTransformer(new
StreamSource(baseDir + xslID));
>   for (Enumeration e=sources.elements(); e.hasMoreElements(); )
>   {
>    String sourceID = (String)e.nextElement();
>    System.out.println("\n=========" + sourceID + "\n");
>    transformer.transform( new StreamSource(baseDir + sourceID),
>            new StreamResult(destDir + sourceID));
>
>   }
>  }
>
>
>

Reply via email to