Connecting Tech Pros Worldwide Forums | Help | Site Map

XSLT count

Newbie
 
Join Date: Feb 2009
Posts: 15
#1: Jul 26 '09
Hi ALL,

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

For Eg

Expand|Select|Wrap|Line Numbers
  1. <book>
  2. <title>Modern Computers</title>
  3. <author><fnm>Samuel</fnm><snm>N</snm></author>
  4. <text>This book deals with </text>
  5. </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

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="fnm">
  2. <lineno>??</lineno>
  3. <charpos>??</charpos>
  4. </xsl:template>
Thanks
Sam

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,660
#2: Jul 26 '09

re: XSLT count


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.
Reply


Similar XML bytes