I tried a for-each and check position() mod 5 to insert a <div> but that got me nowhere. I'm kind off XLS blinded right now so i hope somebody has a solution for this. probably easy to do... i hope ...
The $currentPage works there because that's the page that you are currently on. My code was intended to be in it's own template, which you call using $currentPage, so it's essentially the same thing. I'm not sure of your knowledge of XSLT, so I can explain this further if you like?
The second for-each loop works pretty much the way your pseudo code says. The pipe acts as an OR, and we go through the nodes, starting with the current one that you're 'talking about' (i.e the item from the first loop (items 1, 6, 11, 16...)), and choosing each node along from that, as long as it's not more than 5 places along from it.
It's a little confusing, even for me, but your pseudo code seems to show that you get the gist of it.
Need some help with a loop in xslt
I need some help because I've been staring at the screen and searching the internet for too long. Maybe I'm just thinking too difficult...
I have a setup like this
node1
|_node2
|_sub1
|_sub2
|_etc.
I need to loop through the children of node2 so I get the sub nodes. I need them in "chunks" of 5 subnodes.
The output needs to be something like this:
I tried a for-each and check position() mod 5 to insert a <div> but that got me nowhere. I'm kind off XLS blinded right now so i hope somebody has a solution for this. probably easy to do... i hope ...
thanks
This was a fun one to work on!!! I had no idea where to start with this... but I found the answer...
You want to loop over the nodes that require the <div> first. This will be 1, 6, 11, 16.... so position() mod 5 = 1 will get you those indexes.
Then within that loop, you want to go from that node, to the next 5 nodes. Do this using the 'following-sibling' feature in XSLT.
Your code will look like this:-
<xsl:for-each select="./item[position() mod 5 = 1]">
<div>
<xsl:for-each select=". | following-sibling::*[not(position() >= 5)]">
<xsl:value-of select="@nodeName" /><br />
</xsl:for-each>
</div>
</xsl:for:each>
Enjoy.
- Sean
haha, i'm glad somebody had fun with this ;-)
thanks! i'm gonna try it right away...
hmm.. should this code work "out of the box", or does it need some modifcations?
when i put this in a macro on "node2" (or "node1", but should be inserted at node2), I don't get any results...
here's what i did:
on the site it will only output "start".
what does item[] do? is this the same as for example: $currentPage/ancestor-or-self [position()=2] ?
Why don't you use $currentPage here: xsl:for-each select="./item[position() mod 5 = 1]"> or is a "." the same as currentPage?
I change the first for-each to:
Which seems to work!
Still not sure what the second for-each loop reads in pseudo.. for example:
because i'd like to understand what the code does...
thanks
The $currentPage works there because that's the page that you are currently on. My code was intended to be in it's own template, which you call using $currentPage, so it's essentially the same thing. I'm not sure of your knowledge of XSLT, so I can explain this further if you like?
The second for-each loop works pretty much the way your pseudo code says. The pipe acts as an OR, and we go through the nodes, starting with the current one that you're 'talking about' (i.e the item from the first loop (items 1, 6, 11, 16...)), and choosing each node along from that, as long as it's not more than 5 places along from it.
It's a little confusing, even for me, but your pseudo code seems to show that you get the gist of it.
- Sean
is working on a reply...