XSLT transformation by grouping based on 3 elements/attributes

Posted by Daniel on Stack Overflow See other posts from Stack Overflow or by Daniel
Published on 2010-05-19T18:20:14Z Indexed on 2010/05/19 18:40 UTC
Read the original article Hit count: 343

Filed under:
|
|

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>

© Stack Overflow or respective owner

Related posts about xslt

Related posts about grouping