• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Counter Increment

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Suresh Kanagalingam
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic