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;
Thanks in advance...
[ December 03, 2008: Message edited by: Jeppe Sommer ] [ December 03, 2008: Message edited by: Jeppe Sommer ]
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.
Joined: Jan 07, 2004
Yes you are right. I was a bit unclear.
I want to wrap each group of ten rows into a <div> element.
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 ]