XSLT transformation by grouping based on 3 elements/attributes
- by Daniel
This question is related to http://stackoverflow.com/questions/2863202/xslt-1-0-grouping-to-reformat-element-defined-by-date-into-element-defined-by-tas
Just to understand more clearly the trick behind.
How would the XSLT look like if we were to group by date, task and shift as below:
Input XML;
<Person>
<name>John</name>
<date>June12</date>
<shift tier=1>
<workTime taskID=1>34</workTime>
<workTime taskID=2>12</workTime>
</shift>
<shift tier=2>
<workTime taskID=1>3</workTime>
</shift>
</Person>
<Person>
<name>John</name>
<date>June13</date>
<shift tier=1>
<workTime taskID=1>21</workTime>
<workTime taskID=2>11</workTime>
</shift>
<shift tier=2>
<workTime taskID=1>2</workTime>
</shift>
</Person>
and similarly, the output would be
<Person>
<name>John</name>
<tier>1</tier>
<taskID>1</taskID>
<workTime>
<date>June12</date>
<time>34</time>
</worTime>
<workTime>
<date>June13</date>
<time>21</time>
</worTime>
</Person>
<Person>
<name>John</name>
<tier>1</tier>
<taskID>2</taskID>
<workTime>
<date>June12</date>
<time>12</time>
</worTime>
<workTime>
<date>June13</date>
<time>11</time>
</worTime>
</Person>
<Person>
<name>John</name>
<tier>2</tier>
<taskID>1</taskID>
<workTime>
<date>June12</date>
<time>3</time>
</worTime>
<workTime>
<date>June13</date>
<time>2</time>
</worTime>
</Person>