how do i sort the elements based on "CorporationID" and group them..
I have an xml payload something like the below one ...
<corporationActions> <corporationAction> <ActionID>5530974</ActionID> <CorporationID>1044294</CorporationID> <ActionDate>2009-05-03</ActionDate> <ActionType>Articles of Organization2</ActionType> <ActionNotes></ActionNotes> <DocumentNumber>20110258775-68</DocumentNumber> <NumberofPages>4</NumberofPages> </corporationAction> <corporationAction> <ActionID>5530975</ActionID> <CorporationID>1044294</CorporationID> <ActionDate>2009-05-03</ActionDate> <ActionType>Miscellaneous</ActionType> <ActionNotes></ActionNotes> <DocumentNumber>20110258777-80</DocumentNumber> <NumberofPages>2</NumberofPages> </corporationAction> </corporationActions>
i need to first sort the elements based on CorporationID and then group them if the CorporationID s are repeating.. like the below paylaod
<corporationActions> <corporationAction> <CorporationID>1044294</CorporationID> <corporationActionDetails> <ActionID>5530974</ActionID> <ActionDate>2009-05-03</ActionDate> <ActionType>Articles of Organization2</ActionType> </corporationActionDetails> <corporationActionDetails> <ActionID>5530975</ActionID> <ActionDate>2009-05-03</ActionDate> <ActionType>Miscellaneous</ActionType> </corporationActionDetails> </corporationAction> </corporationActions>
Thanks & Regards, anvv sharma
This is an XSLT 1.0 grouping (Muenchian method) solution, that is mostly in push-style using templates and no
<xsl:for-each>
:When this transformation is applied to the provided XML document:
the wanted, correct result is produced:
Do note: The added flexibility due to the use and overriding of the identity template. In contrast of
<xsl:copy-of select="ActionID|ActionDate|ActionType"/>
we use:<xsl:apply-templates/>
and this assures that any of the children of the current node can be processed in any way we want (and further specify in separate templates).II. XSLT 2.0 solution:
Do note: the simplified grouping using
<xsl:for-each-group>
and thecurrent-group()
function.This solution uses Muenchian method: