xsl-list
[Top] [All Lists]

Re: debugging source line numbers

2003-01-22 20:27:07
Dimitre - it works perfectly! Too bad it's so slow though (too slow for me to use). Please tell me, why should not this be equivalent?

<xsl:value-of select="count( (preceding::text() | preceding::comment() | preceding::processing-instruction())[contains(., '&#xA;')]) + 1"/>

simon

On Wednesday, January 22, 2003, at 03:36  AM, Dimitre Novatchev wrote:

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(., '&#xA;')]"/>

        <xsl:for-each select="preceding::comment()
                                 [contains(., '&#xA;')]">
          <xsl:value-of select="."/>
        </xsl:for-each>

        <xsl:for-each
         select="preceding::processing-instruction()
                                  [contains(., '&#xA;')]">
          <xsl:value-of select="."/>
        </xsl:for-each>
      </x>
    </xsl:variable>

    <xsl:variable name="vLineNo"
     select="string-length($vPrevText) + 1
            -
             string-length(translate($vPrevText, '&#xA;', ''))"/>

    <xsl:value-of select="concat(name(),
                                 ' : line ',
                                 $vLineNo,
                                 '&#xA;')"/>

    <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


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>