File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes do/while in XSLT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "do/while in XSLT" Watch "do/while in XSLT" New topic
Author

do/while in XSLT

Sandeep Advani
Ranch Hand

Joined: Mar 11, 2004
Posts: 78
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

Joined: Jul 01, 2002
Posts: 65
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: do/while in XSLT