Reputation: 123
I am trying to format the below xml to the html format specified below. Basically the content needs to be separated to individual rows based on the tid. When tid is 1, 1.1 the projects should be shown in the same row.
My source xml:
<xml>
<projects>
<dept>
<emp>
<Name>Name1<Name>
<tid>1<tid>
<proj>Proj1<proj>
</emp>
<emp>
<Name>Name1<Name>
<tid>1.1<tid>
<proj>Proj2<proj>
</emp>
<emp>
<Name>Name2<Name>
<tid>2<tid>
<proj>Proj3<proj>
</emp>
<emp>
<Name>Name2<Name>
<tid>2.1<tid>
<proj>Proj4<proj>
</emp>
<emp>
<Name>Name2<Name>
<tid>2.2<tid>
<proj>Proj5<proj>
</emp>
<emp>
<Name>Name3<Name>
<tid>3<tid>
<proj>Proj6<proj>
</emp>
</dept>
</projects>
Expected format:
<table>
<tr>
<td>Name</td>
<td>tid</td>
<td>proj1</td>
<td>proj2</td>
<td>proj3</td>
</tr>
<tr>
<td>Name2</td>
<td>1</td>
<td>Proj1</td>
<td>Proj2</td>
</tr>
<tr>
<td>Name3</td>
<td>2</td>
<td>Proj3</td>
<td>Proj4</td>
<td>Proj5</td>
</tr>
<tr>
<td>Name1</td>
<td>3</td>
<td>Proj6</td>
<td></td>
<td></td>
</tr>
</table>
Upvotes: 0
Views: 62
Reputation: 163262
Looks like a standard grouping problem with
substring-before(concat(tid,'.') '.')
as the grouping key.
The solution to grouping problems depends very much on whether this is XSLT 1.0 or XSLT 2.0, but you can find examples in any XSLT textbook or tutorial once you know that "grouping" is the keyword to search for.
Upvotes: 1