• 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

XSLT loop

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

I am trying to do a loop using XSLT and want to put a div tag around the content for each 10th row. I need the div tag around the content because I am going to use the content in a text scroller script.

I thought about doing something like this:

1) Increment parameter value (called counter) for each loop.

2) Test if position() = 1 or counter = 10. If true, then put a div start tag at the beginning and an end div tag at the end of the content.

3) If clause 2 is true, set counter variable to 0 and repeat above;

The code below doesn�t work as it isn�t valid html markup at runtime. Is there anyone who can correct the code below or do I have to use javascript to build up the code using a StringBuffer?


Thanks in advance...

[ December 03, 2008: Message edited by: Jeppe Sommer ]
[ December 03, 2008: Message edited by: Jeppe Sommer ]
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But if I understand that code correctly, it's more like wrapping each group of ten rows into a <div> element. It certainly doesn't wrap each tenth row with <div> and </div> tags because it precedes the first row with an opening tag and doesn't output the closing tag until after the tenth row.
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are right. I was a bit unclear.

I want to wrap each group of ten rows into a <div> element.

Thanks in advance.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you want to do "for (int i=0; i<max, i++)" in XSLT, you're going to need to do it recursively rather than iteratively. Let's start with a template to output some rows inside a <div> element:
Now add some code to call that for the first ten rows:
That goes in your main code, not inside the tenrows template. Now the recursive part: have the tenrows template call itself for the next ten rows:

Now this isn't quite good enough because we need to stop when we get to the end. We need to wrap that last bit in an <xsl:if> element which only executes it if there's more rows to come. So that I don't do the whole thing for you, can I leave that for you?

Note: only typed into this box, not even checked for validity ;)
[ December 03, 2008: Message edited by: Paul Clapham ]
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, it all works now. Great support ;-)
reply
    Bookmark Topic Watch Topic
  • New Topic