Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

do/while in XSLT

 
Sandeep Advani
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone

I have a XML in the following form..


Ofcourse, this XML has lots of presentation attributes which I have deleted in order to make things less complicated at this ranch. In the process of transforming this XML to another XML, I have a template which prints the text value in the 'Data' tag.

Way I am doing this in my XSL is calling the snippet below while looping through the 'Cell' nodes.



If you notice in the XML, my 4th cell node has an index=5. Under such situation, I would like to call my 'Data' template twice (index-position+1). Similarly, if my 10th node had an index=20, I would like to call this template (20-10+1 = 11) times. Can I achieve this using XSLT? None of apply-templates or call-templates seem to have an attribute which says 'number of times'. Nor can I find one something similar.

Your Input will be highly appreciated.

Thanks
Sandeep
 
David Patterson
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not TOO hard, but also not exactly simple.

In XSLT you can have variables, but they cannot be changed.

The trick is that you can call a template with parameters, and the template can call itself



You get the value of the parameter, do some processing (output whatever you
wish, then compute the variable for the number of remaining iterations,
and if it is over some value, you recursively call your same procedure with
the smaller number passed as the parameter.

This code has not been tested, but you should get the idea of what is needed.

Dave Patterson
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic