> Hi > > I'm trying to use a dom4j tree as input for a XSLT transformation in SAXON > > First I tried using Xalan and SAXON to transform a DOM, but this broke the > id() function in XSLT (which we use a lot).
I would suggest switching from id() to key(). id() is very sensitive to the mechanism you use to build the document tree, the information can easily be lost. With key() you remove the dependency, it will always work. > > According to Michael Kay it's because SAXON doesn't work well with DOM. > > Next I tried to replace DOM with DOM4J and using the example from the dom4j > cookbook, but still the id() function was broken. > > Next I tried to use the SAXWriter functionality to create a SAX input for > SAXON. > > I use the following code: > > public void doTransform(org.dom4j.io.DocumentSource docSource, > javax.xml.transform.Transformer transformer, Writer pResultWriter > { > transformer.setParameter("xxx", "yyy"); > transformer.setParameter("zzz", "www"); > > org.dom4j.io.SAXWriter writer = new org.dom4j.io.SAXWriter(); > > org.dom4j.io.DocumentInputSource docInputSource = new > org.dom4j.io.DocumentInputSource(docSource.getDocument()) > > javax.xml.transform.sax.SAXSource source = new > javax.xml.sax.SAXSource((org.xml.sax.XMLReader) writer, docInputSource); > > javax.xml.transform.stream.StreamResult result = new > javax.xml.transform.stream.StreamResult(pResultWriter); > > transformer.transform(source, result); > } > > According to the API doc for SAXSource it takes a XMLReader (here a > XMLWriter) and a InputSource and calls XMLReader.parse(InputSource). > > Reading the API doc for SAXWriter it will only accept a parse(InputSource) if > the InputSource is of type DocumentInputSource. > > I found it in org.dom4j.io but the DocumentInputSource was default not > public. After making the class public the above code worked, but the id() > function was still broken....... I'm not familiar with DOM4J myself, I would think that interfacing it via SAX is the right approach, but I can't comment on the detailed problems. For example, it's anyone's guess whether it marks ID attributes as such in the SAX event stream. One day I would like to write a direct adapter for DOM4J, in the same way as the JDOM adapter. Michael Kay > > > > Does anyone know how to get a DOM representation into SAXON with the id() > function working?? > > Is the only way to serialize the DOM and reparse it?? > > Does anyone have experience with using dom4j and Xalan and whether the id() > function works in that configuration.. > > Looking through the source code for the JDOM adapter for SAXON shows that the > id() function might work with it. (It has some Id handling functions). Does > anyone have any experience with the JDOM Adapter and id() function. Is anyone > working on a DOM4J adapter?? > > /Christian Bjørnbak > > > > ------------------------------------------------------- > This sf.net email is sponsored by: Dice - The leading online job board > for high-tech professionals. Search and apply for tech jobs today! > http://seeker.dice.com/seeker.epl?rel_code1 > _______________________________________________ > saxon-help mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/saxon-help > ------------------------------------------------------- This sf.net email is sponsored by: Dice - The leading online job board for high-tech professionals. Search and apply for tech jobs today! http://seeker.dice.com/seeker.epl?rel_code=31 _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user