I have an XML doc that looks like this.
<Results>
<Name>Lab Asst1 </Name>
<Subject> Math </Subject>
<Marks>96</Marks>
<Grade>A</Grade>
<Name>Student1</Name>
<Subject>Math</Subject>
<Marks>90</Marks>
<Grade>A</Grade>
<Name>Student1</Name>
<Subject>English</Subject>
<Marks>70</Marks>
<Grade>B</Grade>
<Name>Lab Asst1 </Name>
<Subject> Science</Subject>
<Marks>99</Marks>
<Grade>A</Grade>
<Name>Student2</Name>
<Subject>Science</Subject>
<Marks>70</Marks>
<Grade>B</Grade>
</Results>
Using XSL, what is the simplest way to display, without showing the <Name>
element twice? I would like to display the Lab Asst1 results first, assuming there is a text box that uses this value (comes in from C# code):
Basically, something that does this part first:
User: <Name>
Your results are:
<table>
<tr>
<td> Subject </td>
<td> Marks </td>
<td> Grade </td>
</tr>
then call another template etc. or do a for-each or something....
<tr>
<td> <xsl:value-of select="Subject"/> </td>
<td> <xsl:value-of select="Marks"/> </td>
<td> <xsl:value-of select="Grade"/> </td>
</tr>
Such that my results appear like this:
User: Lab Asst1
Your results are:
Subject | Marks | Grade
-------------------------------------
Science| 99 | A
Math | 96 | A
User:Student1
Your results are:
Subject | Marks | Grade
-----------------------------
Math | 95 | A
English | 70 | B
User:Student2
Your results are:
Subject | Marks | Grade
-----------------------------
Math | 70 | B
This transformation:
when applied to the provided XML document:
produces the wanted, correct results:
Do note:
The Muenchian method for grouping is used.
In XSLT 2.0 it is easier and more convenient to use the
<xsl:for-each-group>
instruction.