2 Replies Latest reply: May 4, 2008 2:58 PM by DrClap RSS

    Using XSLT to enrich an XML document

    807591
      I would like to enrich an XML document. I want to do it by merging the result of a XSLT into it.
      I use the following code:
      javax.xml.transform.Transformer trans = TransformerFactory.newInstance().newTransformer(<xslt doc>);
      Result result = new DOMResult(<the xml doc that i want to enrich>);
      Source xmlSource = new DOMSource(<some other xml doc>);
      trans.transform(xmlSource,result);
      The problem is that I'm getting:
      org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted. 
      at org.apache.xerces.dom.CoreDocumentImpl.insertBefore(Unknown Source)
      at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
      at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.startElement(SAX2DOM.java:141)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.closeStartTag(ToXMLSAXHandler.java:205)
      at com.sun.org.apache.xml.internal.serializer.ToSAXHandler.flushPending(ToSAXHandler.java:291)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.startElement(ToXMLSAXHandler.java:646)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.startElement(ToXMLSAXHandler.java:508)
      at transform.template$dot$0()
      at transform.applyTemplates()
      at transform.transform()
      at com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet.transform(AbstractTranslet.java:594)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:644)
      Does anyone know how can I do it?

      Thanks,
      Daniel
        • 1. Re: Using XSLT to enrich an XML document
          807591
          Looks like your stylesheet is wrong. Probably you're outputting some text as the result of a select, but haven't output the actual tag the text belongs to. Without seeing the stylesheet, it's difficult to say
          • 2. Re: Using XSLT to enrich an XML document
            DrClap
            Yes, it's possible to use XSLT to generate something that isn't a well-formed XML document. For example you could have it output something with more than one root element. That isn't a problem if you output to a text file, but it would be a problem if you tried to output it to a DOM.

            You aren't trying to write to an existing DOM, are you?