What I do is extract the doctype info from the document coming in, and pass
them to the transformer:



private static java.util.Properties
getOutputProperties(org.w3c.dom.Document iDocument, boolean iWithDocType)
     {
         java.util.Properties oprops= new java.util.Properties();
         oprops.put("method", "xml");
         oprops.put("omit-xml-declaration", "yes");

         if (iWithDocType)
         {
             org.w3c.dom.DocumentType docType= iDocument.getDoctype();
             if (docType != null)
             {
                 String publicID= docType.getPublicId();
                 String systemID= docType.getSystemId();
                 if (publicID != null)
                 {
                     oprops.put("doctype-public", publicID);
                 }
                 if (systemID != null)
                 {
                     oprops.put("doctype-system", systemID);
                 }
             }
         }// end of  if (iWithDocType)
         return oprops;
     }// end of getOutputProperties()


public static void transformDocument(javax.xml.transform.Transformer
iTransformer, org.w3c.dom.Document iDocument, java.io.Writer iWriter,
boolean iWithDocType)
          throws com.eFunds.portal.exception.XSLException
     {
          try
          {

iTransformer.setOutputProperties(getOutputProperties(iDocument,
iWithDocType));

               iTransformer.transform(
                    new javax.xml.transform.dom.DOMSource(iDocument),
                    new javax.xml.transform.stream.StreamResult(iWriter));
          }
          catch (javax.xml.transform.TransformerConfigurationException e)
          {
               throw new com.eFunds.portal.exception.XSLException("Failed
to transform document",e);
          }
          catch (javax.xml.transform.TransformerException e)
          {
               throw new com.eFunds.portal.exception.XSLException("Failed
to transform document",e);
          }
          catch (Throwable t)
          {
               throw new com.eFunds.portal.exception.XSLException("Failed
to transform document",t);
          }
     }//end of transformDocument()

Reply via email to