• 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

Iterating over a number

 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Is there some XSLT equivalent to "for i = 0; i < max; i++", even without having access to the index inside the loop? I'm trying to transform an xml file representing a nested lists into html, and have the HTML output for each element indented based on the depth of the element. For a quick example,



With indentation set at 4 spaces per level, the HTML output would have b indented 4 spaces, c and d indented 8 spaces, and so on. The stylesheet should have no idea what to expect aside from categories under categories, some of them containing documents. The indentation should be done based on how deep in the tree the categories and documents are encountered.

Currently I keep track of the depth by passing parameters to templates, but the actual indentation is a terrible hack which noticeably slows down the transformation (iterating over dummy nodes in the XML, writing the spaces if position() < $indentLevel). Is there a better way to do this?

Note that the output will probably be presented using tables, so the natural indentation of HTML lists cannot be used.

Thank you,
Yuriy
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I solved the indentation issue without iteration, but I would still like to know if there's a way to loop over a number.

Thanks,
Yuriy
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yuriy,
To my knowledge, we cannot do that in XSL because variables are read only and we can assign values only once. If someone can give us a way it would be really helpful.
reply
    Bookmark Topic Watch Topic
  • New Topic