Subject: Re: [xsl] debugging source line numbers From: S Woodside <sbwoodside@xxxxxxxxx> Date: Wed, 22 Jan 2003 22:27:07 -0500 |
Here's the transformation, which does what was initially intended:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="*"> <xsl:variable name="vPrevText"> <x> <xsl:copy-of select="preceding::text()[contains(., '
')]"/>
<xsl:for-each select="preceding::comment() [contains(., '
')]"> <xsl:value-of select="."/> </xsl:for-each>
<xsl:for-each select="preceding::processing-instruction() [contains(., '
')]"> <xsl:value-of select="."/> </xsl:for-each> </x> </xsl:variable>
<xsl:variable name="vLineNo" select="string-length($vPrevText) + 1 - string-length(translate($vPrevText, '
', ''))"/>
<xsl:value-of select="concat(name(), ' : line ', $vLineNo, '
')"/>
<xsl:apply-templates/> </xsl:template>
<xsl:template match="node()[not(self::*)]"/> </xsl:stylesheet>
It also takes care of multiline comments / processing-instructions.
When applied on this source.xml:
<root> <item>1</item> <!-- --> <!-- --> <item>5</item> <item>3</item> <item>2</item> <item>6</item> <item>4</item> </root>
The result is:
root : line 1 item : line 2 item : line 6 item : line 7 item : line 8 item : line 9 item : line 10
--- www.simonwoodside.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] debugging source line num, Dimitre Novatchev | Thread | Re: [xsl] debugging source line num, Dimitre Novatchev |
[xsl] Problem with document() two p, Girish Kumar | Date | Re: [xsl] top level params and xsl:, Dimitre Novatchev |
Month |