XSLT count

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samueln12
    New Member
    • Feb 2009
    • 28

    XSLT count

    Hi ALL,

    I want to count the character position from the root using Xpath expression and Line number

    For Eg

    Code:
    <book>
    <title>Modern Computers</title>
    <author><fnm>Samuel</fnm><snm>N</snm></author>
    <text>This book deals with </text>
    </book>
    Now i want to count the fnm position from root
    <charpos>53</charpos>
    and line no is

    Can anyone help how to get this value

    I am able to match the node

    Code:
    <xsl:template match="fnm">
    <lineno>??</lineno>
    <charpos>??</charpos>
    </xsl:template>
    Thanks
    Sam
    Last edited by Dormilich; Jul 26 '09, 10:22 AM. Reason: added [code] tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    neither line number* nor total character position have any meaning in XML. (though you probably can get the character position of a character in a text node)

    just treat the XML as string and compute the values using your favourite programming language.

    * the XML will remain the same even if you write all in one line (which would also change the character position since whitespace between tags is missing). the line numbers and tag indentation are just eye candy.

    Comment

    Working...