I'm aware of the Muenchian grouping method for XSLT, but all implementations I've seen rely on a single node as the value to group on. In this case I'd like to group on a node-set. In the input below I'd like to group on outputs/output part ref.
I've tried to construct keys such as
<xsl:key name="refsKey" match="/processes/process" use="outputs/output_part_ref"/>
Of course outputs/output_part_ref matches the first node and doesn't match the node-set.
Input
<?xml version="1.0" encoding="UTF-8"?>
<processes>
<process>
<name>ProcessA</name>
<input_qty>1200</input_qty>
<outputs>
<output_part_ref>1</output_part_ref>
<output_part_ref>2</output_part_ref>
<output_part_ref>3</output_part_ref>
</outputs>
</process>
<process>
<name>ProcessB</name>
<input_qty>1300</input_qty>
<outputs>
<output_part_ref>1</output_part_ref>
<output_part_ref>2</output_part_ref>
<output_part_ref>3</output_part_ref>
</outputs>
</process>
<process>
<name>ProcessC</name>
<input_qty>770</input_qty>
<outputs>
<output_part_ref>1</output_part_ref>
<output_part_ref>2</output_part_ref>
</outputs>
</process>
</processes>
Sample Output
<html>
...
<table>
<tr>
<td>2500</td>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>770</td>
<td>1</td>
<td>2</td>
</tr>
</table>
...
</html>
If the number of elements forming the key is not fixed then I agree with Michael, we need to compute the key first and use
exsl:node-set
or similar in XSLT 1.0: