Grouping every 3 items in xslt 1.0

Posted by Piotr Czapla on Stack Overflow See other posts from Stack Overflow or by Piotr Czapla
Published on 2010-03-08T09:15:06Z Indexed on 2010/03/08 9:21 UTC
Read the original article Hit count: 626

Filed under:
|
|

I'm having troubles to figure out a way to group items xslt 1.0. I have a source xml similar to the one below:

<client name="client A">
    <project name = "project A1"/>
    <project name = "project A2"/>
    <project name = "project A3"/>
    <project name = "project A4"/>
</client>
<client name="client B">
    <project name = "project B1"/>
    <project name = "project B2"/>
</client>
<client name="client C">
    <project name = "project C1"/>
    <project name = "project C2"/>
    <project name = "project C3"/>
</client>

I'd like to select all projects, sort them and then group every 3 project in one boundle as in the example below:

<boundle>
  <project name="project A1">
  <project name="project A2">
  <project name="project A3">
</boundle>
<boundle>
  <project name="project A4">
  <project name="project B1">
  <project name="project B2">
</boundle>
<boundle>
  <project name="project C1">
  <project name="project C2">
  <project name="project C3">
</boundle>

Currently to do so I'm using to open a boundle tag and close it later. Can you think about any better solution?

© Stack Overflow or respective owner

Related posts about xslt

Related posts about xslt-1.0