You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Ovidiu Predescu <ov...@cup.hp.com> on 2001/05/24 21:03:08 UTC
[Xalan2J PATCH] File, line, column number information for XML source document
Hi,
The following patch adds file, line and column number information of
XML source documents in Xalan2J.
This information is stored in a hash table and is generated only if
Xalan is run with the -L option in the command line. It can also be
setup programmatically by setting up a property on the TransformerImpl
instance. There is no runtime or memory overhead if this property is
not setup on a transformer.
There are two ways one can obtain XML source node information. The
first is from within a stylesheet, like below:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:nodeinfo="xalan://org.apache.xalan.lib.NodeInfo"
version="1.0">
<xsl:template match="*">
//node <xsl:value-of select="name()"/>
//file <xsl:value-of select="nodeinfo:systemId()"/>
//line <xsl:value-of select="nodeinfo:lineNumber()"/>
//column <xsl:value-of select="nodeinfo:columnNumber()"/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
If no arguments are passed to the systemId(), lineNumber() or
columnNumber() functions, the corresponding information of the current
context node is returned. A node can be passed as argument to the
above functions, in which case the corresponding information about
that node is returned. If a node set containing multiple nodes is
passed as argument, only the information of the first node in the set
is returned.
The second way of obtaining the position information of a source node
is programmatic. Given a Node instance, one could obtain the owner
document, which is an instance of DocumentImpl, and invoke the
getSourceLocatorFor() method. The following example extracted from the
modified PrintTraceListener shows this:
Node sourceNode = ev.m_sourceNode;
DocumentImpl owner = (DocumentImpl)sourceNode.getOwnerDocument();
SourceLocator locator = owner.getSourceLocatorFor(sourceNode);
There are two patches attached. The first contains the changes to the
Xalan2J source code relative to the CVS source code as of today. The
second patch contains an XML and an XSL stylesheet test files.
Please let me know if you find any problems with the source code. Of
course, I'm interested in seeing the code integrated with Xalan2 as I
want to make use of it in two projects immediately.
Best regards,
--
Ovidiu Predescu <ov...@cup.hp.com>
http://orion.nsr.hp.com/ (inside HP's firewall only)
http://www.geocities.com/SiliconValley/Monitor/7464/ (GNU, Emacs, other stuff)