This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Counter Increment Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "Counter Increment" Watch "Counter Increment" New topic
Author

Counter Increment

Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Hello,
I am converting XML data into csv format. When I do this I need to add a counter to each of the addresses lines of a client (One client may contain more than one address).
Is there a way I can call a template name with a counter where by each call will be initiated with (counter + 1)?
Thanks
Suresh
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
If each address line his held as a child element of client
i.e.
<client>
<address></address>
<address></address>
<address></address>
<address></address>
</client>
then you can just use the position() function to get a sequential number.

HTH


Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Hi Andy,
I need to do bit different. If I use your example and assuming that I have 2 addresses for a client, the XML will look like following:
<client>
<address>Street1</address>
<address>City1</address>
<address>Prov1</address>
<address>PC1</address>
</client>
<client>
<address>Street2</address>
<address>City2</address>
<address>Prov2</address>
<address>PC2</address>
</client>
I need to translate this to
Street1|City1|Prov1|PC1|1
Street2|City2|Prov2|PC2|2
Thanks
Suresh
Sree Reddy
Greenhorn

Joined: Dec 20, 2002
Posts: 13
Hi,
You can get the count in the following way...
<xsl:value-of select="count(preceding-sibling::*) + number(1)" />
Basically, all the <Client> tags belogs to same parent. So we are using the sibling concept here.
-- Sree
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Counter Increment
 
Similar Threads
how do i call a method simultaneously using thread
synchronization quesion
using array list
Stateless session bean!!!
Confused with Stateless Session Bean