Split a list to three lists
This is an open discussion with 2 replies, filed under XSLT.
Search
Is there a way of doing the samething as my solution does except more elegantly?
I don’t know about more elegantly. I’ve had the same requirement before and achieved it in a similar way, just slightly different code.
But I’m sure there must be a more elegant solution using preceding/following-sibling axes, I just haven’t found it yet :-)
For what it’s worth, I can barely explain the code I wrote; I forget quite why I’m doing the subractions I’m doing. I do recall there being a lot of trial and error while testing it, but hopefully it is of use.
I had to do this once too. Can’t remember why, when, or how. So… that’s no help at all. But if it comes to me I’ll be sure to post back here :)
Create an account or sign in to comment.
Sorry for the poor title. I have a collection of elements, and I want to split them into three “collections” of equal size.
I have the following XML: pastebin
I’d like to generate the following HTML: pastebin
So the thing is that I want the first third in the first list item (with it’s elements as a sub-list), and the second in the second, etc.
The solution I have now works, but is far from elegant: pastebin
The difficult part was considering the situation when the number of xml elements was not divisible by three. Eg. if I have 13 elements, then I want it distributed between the list items like so:
Is there a way of doing the samething as my solution does except more elegantly? Thank you in advance.