When you parse XML into a DOM, the DOM does not retain line number information from the source file. Saxon therefore has no access to the information.
 
It's not clear in this example why you are using a DOM. It's much more efficient (by a factor of 4 to 10) to let Saxon build the tree itself using its own native tree model (typically by using a StreamSource or SAXSource).
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Todd Gochenour [mailto:todd.gochenour@gmail.com]
Sent: 25 March 2010 23:51
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: [saxon] XSLT Trace Output Missing File and Line Number

I have the following code:

File template = new file("fully qualified file path");
Document templateDoc = parser.parse(template);
templateDoc.setDocumentURI(template.toURI().toString());
source =

new DOMSource( templateDoc );
tranFactory = new net.sf.saxon.TransformerFactoryImpl();
tranFactory.setErrorListener(listener);
tranFactory.setURIResolver(new
EditionURIResolver(this.getServletContext()));
aTransformer = tranFactory.newTransformer( source );
aTransformer.setErrorListener(listener);
((net.sf.saxon.Controller)aTransformer).addTraceListener(new
net.sf.saxon.trace.XSLTTraceListener());

which produces the following output in System.err:

 <trace saxon-version="9.1.0.6" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <source node="/" line="0" file="">
  <source node="/parameters/@lastUpdateDt" line="-1" file="">
  </source><!-- /parameters/@lastUpdateDt -->
  <source node="/parameters" line="-1" file="">
  </source><!-- /parameters -->
  <source node="/parameters" line="-1" file="">
  </source><!-- /parameters -->
  <source node="/parameters" line="-1" file="">
  </source><!-- /parameters -->
  <source node="/parameters/doc[1]" line="-1" file="">
   <source node="/parameters/doc[1]/text()[1]" line="-1" file="">
   </source><!-- /parameters/doc[1]/text()[1] -->
  </source><!-- /parameters/doc[1] -->
...
   </trace

 Question: what is missing in the configuration which will allow the trace to contain line number and file information?  There are imports embedded within where the URIResolver has calculated it's location.  The error listener will report the correct file and line numbers when syntax errors occur in the nested stylesheets so I don't think the URIResolver is is the problem yet I don't know what else to look at.

Todd Gochenour