I want to sort nodes base on attributes. Say there are three attributes A, B and C in element E1. I know that a sub-group of nodes have the same value of attribute A and B. How can I get this sub-group retrieve the node that has the max value of C? The tricky part here is that I don't know what value of A is. I just know that sub-group share the same value of A. Just like a dual-key index.
I am thinking to use for-each underneath for-each-group.
example
<masterNodes>
<Node>
<Element1 A="123" B="LEFT" C="1">
<Element2>...</Element2>
</Node>
<Node>
<Element1 A="123" B="DOWN" C="5">
<Element2>...</Element2>
</Node>
<Node>
<Element1 A="abc" B="RIGHT" C="2">
<Element2>...</Element2>
</Node>
<Node>
<Element1 A="123" B="LEFT" C="3">
<Element2>...</Element2>
</Node>
<Node>
<Element1 A="4XX" B="LEFT" C="4">
<Element2>...</Element2>
</Node>
<Node>
<Element1 A="abc" B="RIGHT" C="1">
<Element2>...</Element2>
</Node>
<Node>
<Element1 A="4XX" B="LEFT" C="5">
<Element2>...</Element2>
</Node>
<Node>
<Element1 A="4XX" B="UP" C="0">
<Element2>...</Element2>
</Node>
</masterNodes>
How can I only write out the max value of C for node with the same value of A and B?
Here is how I structure my code. But I never get it work.
<xsl:for-each-group select="/Node/Element1" group-by="@A">
<xsl:for-each select=".[@B='LEFT']">
<xsl:sort select="@C" data-type="number" order="descending"/>
<xsl:if test="position()=1"><xsl:value-of select="@C"/></xsl:if>
</xsl:for-each><xsl:text>
</xsl:text>
<xsl:for-each select=".[@B='RIGHT']">
<xsl:sort select="@C" data-type="number" order="descending"/>
<xsl:if test="position()=1"><xsl:value-of select="@C"/></xsl:if>
</xsl:for-each><xsl:text>
</xsl:text>
<same for other direction>
</xsl:for-each-group>
Anything wrong?