xsl-list
[Top] [All Lists]

RE: [xsl] XSLT 2.0: Saxon et. al.: Tracking XML source line numbers

2007-07-18 00:47:37
It would certainly be possible to implement such a mechanism by inserting a
SAX filter between the XML parser and the XSLT processor, and have the SAX
filter fabricate the line numbers. In fact, if the stylesheet generator is
feeding the generated stylesheet to the XSLT processor directly as a SAX
stream, then it takes full responsility for supplying the line numbers.

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

-----Original Message-----
From: Justin Johansson [mailto:procode(_at_)tpg(_dot_)com(_dot_)au] 
Sent: 18 July 2007 05:39
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] XSLT 2.0: Saxon et. al.: Tracking XML source 
line numbers

Hello all,

My last question for today, and thanks to all for your 
patience with, and responses to, this newcomer to your list.

Saxon has an XSLT extension function saxon:line-number($node) 
which returns the line number associated with a node in the 
XML source tree (though you need to use the -l option to 
enable line number tracking and perhaps other XSLT processors 
have a similar such function.  However, is there any way that 
one can achieve the same functionality as C's #line directive 
with an XSLT processor, even if it an XSLT extension, and 
tell the processor that line and file numbers for errors and 
warning associated with particular source node actually 
relate to another place earlier in chain of pipeline XML/XSLT 
processing.

The background and rationale for this question is as follows:

C and C++ preprocessors have long had the ability for the 
programmer to modify the file name and line numbers for which 
the compiler outputs errors and warnings associated with source code.

Quoting Visual Studio C++ help
<quote>
The #line directive lets you modify the line numbers and, 
optionally, the file name in the compiler output for errors 
and warnings. 
#line [ number ["file_name"] | hidden | default ] </quote>

Apparently some other languages, e.g. Perl, have a similar 
facility but what about XSLT?

A use case is the YACC processor from the C world.  This 
processor takes as input a BNF-like description of the 
grammar for particular language, say, cplusplus.y, and 
produces as output a file, cplusplus.c, which contains C 
source code for constructing a parser for the given language. 
 When a warning or error occurs in compiling cplusplus.c, the 
C compiler associates the same with a line number in 
cplusplus.y instead of cplusplus.c.

It would be useful to achieve a similar thing in XSLT to make 
the debugging of automatically generated stylesheets easier.

In response to my post on Jeni Tennison's blog re auto 
generating XSLT stylesheets,

      http://www.jenitennison.com/blog/node/13#comments ,

Jeni rightfully pointed out the problem of debugging such 
auto generated stylesheets.

      http://www.jenitennison.com/blog/node/13#comment-4040

Thanks to all in advance for the tips and tricks,


Justin Johansson
Freelance XML / XSLT / XQuery Developer
Australia

procode(at)tpg(dot)com(dot)au

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--