Subject: RE: sax getLineNumber under saxon From: Kay Michael <Michael.Kay@xxxxxxx> Date: Tue, 26 Oct 1999 10:34:43 +0100 |
> I'm trying to output the line number of an 'error' > (according to schematrons definition) in the XML > source file (with a weak comprehension of java<grin/>) > A very reasonable request and one which really ought to be a core function in XSLT. > I think I'm nearly there with the following > <xsl:variable name="lineno" select="sax:getLineNumber()" > xmlns:sax="/org.xml.sax.Locator" > /> > > Saxon tells me > > At xsl:variable on line 21 of file:/f:/sgml/xsl/trash.xsl: Cannot > instantiate object for extension function getLineNumber The problem is that extension functions can't access an existing object with defined state: what your code is doing is to create a new Locator object: even if this succeeded (which it won't, because Locator is an interface not a class) its state would be quite unrelated to the state of the Locator used by SAXON to record position in the input file. With SAXON 4.5 this would actually have been rather easier, because extension functions had access to the Context object and hence to SAXON's internal state. The only way of getting this now is with extension elements, which are much trickier to code. An alternative you could consider, which would not be too hard at all, is to write a ParserFilter as a front end to SAXON, and use this to add a line-number attribute to every element node. You could then access this attribute happily from your XSL. I shall consider making line-number and system-id available as SAXON extension functions, and also extending the extension function API to make Context available. > > On the wish list, > given > > file root.xml > > <doc> > > &chap1; > > </doc> > > etc, I.e. documents which include others, > is Sax clever enough to tell me which file its > looking at as well? > SAXON's own error messages and trace output should identify the file/entity correctly, but the information isn't made available to your XSL code. Mike Kay XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
sax getLineNumber under saxon, DPawson | Thread | RE: sax getLineNumber under saxon, DPawson |
Why I want to change the value of a, Emmanuel.Leguy | Date | Re: <xsl:when> Problems (with IE5), Nikita Ogievetsky |
Month |