As far as I am aware, a JDOM document does not hold any information about line numbers. Therefore, a DocumentWrapper around such a document cannot deliver line numbers either. Saxon can only retain line numbers if it is provided with the information by the XML parser.
 
Saxon doesn't recognize a JDOMSource explicitly. It subclasses SAXSource, so Saxon will treat it as a SAXSource and ask it for a stream of SAX events. I've no idea whether this SAXSource provides any usable line number information - I would suspect not, because I don't think JDOM has retained enough information to provide this.
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Panthera 5000
Sent: 10 January 2008 22:00
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Saxon DocumentWrapper for JDOM

Hello,
 
I have some difficulties in getting the DocumentWrapper to work with JDOM. I hope you may be able to help me find the error.
 
I'm using Java Servlet to do XSLT transform using Saxon 8.7. I used JDOM to validate my XML and resolve DTD and all entities references.
 
I use the Saxon DocumentWrapper so I can make use of the line numbering feature. If I use this code:
transformer.transform(jin, new StreamResult(outputSystemID)); (method #2) it transformed okay but the linenumbering is not working. They show "-1" as the line number.
 
When I tried method #1, the transform stopped but reported no error messages. I couldn't catch any exception. Am I missing something that I didn't realized? Below is the code snippet:
 
Thanks for your help.
 
P. Corbetti
 
//Code snippet
 
  SAXBuilder builder = new SAXBuilder();
  builder.setFactory(domFactory);
  builder.setEntityResolver(entResolver);
  sourceDoc = (Document) builder.build(sourceSystemID);
  // Give it a Saxon wrapper
  DocumentWrapper docw = new DocumentWrapper(sourceDoc, sourceSystemID, new Configuration());
  net.sf.saxon.Configuration config = new net.sf.saxon.Configuration();
  // set the source documents to maintain line numbers,
  // for the benefit of the saxon:line-number() extension function as well as run-time tracing.
  config.setLineNumbering(true);
  docw.setConfiguration(config);
  jin = new JDOMSource(sourceDoc);
  jout = new JDOMResult();
  Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltSystemID));
  transformer.setParameter(paramname, paramvalue);
  try {
      transformer.transform(docw, new StreamResult(outputSystemID)); // method #1
      /* transformer.transform(jin, new StreamResult(outputSystemID)); */ // method #2
  } catch (net.sf.saxon.instruct.TerminationException terr) {
    System.out.println("Error: transform<" + terr);
  } catch (net.sf.saxon.trans.DynamicError dyerr) {
    System.out.println("Error: transform<" + dyerr);
  } catch (TransformerConfigurationException tcerr) {
    System.out.println("Error: transform<" + tcerr);
  } catch (TransformerFactoryConfigurationError tfcerr) {
    System.out.println("Error: transform<" + tfcerr);
  } catch (TransformerException err) {
    System.out.println("Error: transform<" + err);
  }