I am trying to retrieve First Unique set of 2 attributes.
I am looking for each student name with his first unique group. If for a student first group is already taken for any student, next unique group should be listed. I have posted my XML and expected result XML.
I need XSLT statements to get this result (Version 1.0). Thanks.
Here’s my xml structure
<Socrates>
<Student name='Aristotle' group='1' />
<Student name='Aristotle' group='2' />
<Student name='Aristotle' group='3' />
<Student name='Aristotle' group='4' />
<Student name='Plato' group='1' />
<Student name='Plato' group='2' />
<Student name='Plato' group='3' />
<Student name='Xenophon' group='4' />
<Student name='Xenophon' group='5' />
<Student name='Xenophon' group='6' />
<Student name='Critias' group='1' />
<Student name='Critias' group='2' />
<Student name='Critias' group='3' />
<Student name='Critias' group='4' />
<Student name='Critias' group='5' />
<Student name='Critias' group='6' />
</Socrates>
Result XML
<Socrates>
<Student name='Aristotle' group='1' />
<Student name='Plato' group='2' />
<Student name='Xenophon' group='4' />
<Student name='Critias' group='3' />
</Socrates>
Another slightly different approach (although not necessarily a better approach) is to pass a parameter to each student match which contains a comma-delimited of group attributes that have already been output. Every time you match a student, you check whether their group is in his parameter, and if not output the student, and get the next one, appending the current group to the parameter.
Here is the XSLT, which I have commented to try and explain things better
When applied to your sample XML, the following is output
Note that this does assume the student elements are always ordered by name in the input XML.