Thanks for your response Joseph and Franck.

The only problem is that i'm doing DOM to DOM transformation:

        Transformer transformer = getTransformer(xslFileName);

        // create empty output document.
        DocumentBuilderFactory dfactory = 
DocumentBuilderFactory.newInstance();
        dfactory.setNamespaceAware(true);
        DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
        Document outDocument = docBuilder.newDocument();

        // transform
        transformer.transform(new DOMSource(xmlDocument), new 
DOMResult(outDocument));

Setting output properties in stylesheet or transformer works only for DOM 
to stream transformations.
Output document has to be created and fed to transformer. I could create 
document with all the Document type information:

        Properties prop = transformer.getOutputProperties();
        DOMImplementation impl = docBuilder.getDOMImplementation();
        // Create document type
        DocumentType documentType = 
impl.createDocumentType(outDocument.getDocumentElement().getNodeName(), 
                prop.getProperty("doctype-public"), 
                prop.getProperty("doctype-system")); 
        Document outDocument = impl.createDocument(null, 
outDocument.getDocumentElement().getNodeName(), documentType); 
        // transform
        transformer.transform(new DOMSource(xmlDocument), new 
DOMResult(outDocument));

But unfortunatelly it also creates the root element of the outDocument 
which screwes up the transformation.

Does anybody know if it's possible to create a document with document type 
information in it without creating root element?
Is it possible to remove root element from the document? is there any 
other way to work around?

Regards,
Vlad



To:     xalan-j-users <[EMAIL PROTECTED]>
cc:     "Vlad.Epshtein" <[EMAIL PROTECTED]> 

Subject:        Re: DocumentType information lost while transforming DOM to DOM


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