• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Add a Line Counter for Each XML Element in XSL?

 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have converted an XML file to a text file using XSL. The output is the value of each XML element. And I put a line break after each output value:

How do I put a line counter for each XML element, so that the output looks like

My XSL file looks like:

Thanks in advance.
 
Paul Clapham
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You pass the line numbers as another parameter to the "clip" template:


(By the way I hope that isn't medical information about a real person. Please edit your post as soon as possible if it is.)
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made up the data for a medical record. There is no patient name shown in my post.

I have tried what you suggested. But nothing happens - a number does not appear in front of the value of each XML element. The output still looks like:

The format that is desired to be displyed is 1. element count number + 2. caret symbol + 3. the value of the XML element; for example:

The XSL code now looks like (a counter number is not inserted in the front of each line of the output):

 
Paul Clapham
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do have to change the "clip" template to output the sequence number. Sorry, I thought that would be obvious so I didn't provide the full solution.
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not obvious to me. I am new to all XML related technologies. For adding a numbering, I am thinking along the line of:
but, I still have difficult time to figure it out.
 
Paul Clapham
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, no, no. The "clip" template should simply copy the sequence number parameter to the output.

There aren't any XSLT constructs which can work on nodes in the output. And there isn't anything in your input document which can be examined to produce a numbering system (at least not from what I can see from your input document). So the simplest thing is to produce your own sequence numbers, which is anyway trivially simple to do in the sample of XSLT which you posted. You already did half of that by choosing the sequence numbers. The second half is to use them.
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it. Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic