XSLT - Split the tag into group of 2 tags

Viewed 24

I'm trying to perform an XSL transformation on the XML below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:CommissionEvents xmlns="urn:tracelink:mapper:sl:canonical:commontypes" xmlns:ns2="urn:tracelink:mapper:sl:canonical:serialized_operations_manager">

<ns2:CommissionEvent>
       <NumberList>
        <Serial barcodeContent="(01)00355135132011(21)897883089643(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)">010035513513201121897883089643</Serial>
        </NumberList>
</ns2:CommissionEvent>
    <ns2:CommissionEvent>
       <NumberList>
        <Serial barcodeContent="(01)00355135132011(21)903131477120(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)">010035513513201121903131477120</Serial>
       </NumberList>
</ns2:CommissionEvent>
<ns2:CommissionEvent>
       <NumberList>
         <Serial barcodeContent="(01)00355135132011(21)189513222896(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)">010035513513201121189513222896</Serial>
            </NumberList>
</ns2:CommissionEvent>
<ns2:CommissionEvent>
       <NumberList>
         <Serial barcodeContent="(01)00355135132011(21)468091235492(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)">010035513513201121468091235492</Serial>
            </NumberList>
</ns2:CommissionEvent>
<ns2:CommissionEvent>
       <NumberList>
        <Serial barcodeContent="(01)00355135132011(21)704297270475(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)">010035513513201121704297270475</Serial>
       </NumberList>
</ns2:CommissionEvent>
<ns2:CommissionEvent>
       <NumberList>
        <Serial barcodeContent="(01)30355135132012(21)389170110454(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="3" format="AI(01)+AI(21)">013035513513201221389170110454</Serial>
       </NumberList>
</ns2:CommissionEvent>
<ns2:CommissionEvent>
       <NumberList>
        <Serial barcodeContent="(01)30355135132012(21)724826376009(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="3" format="AI(01)+AI(21)">013035513513201221724826376009</Serial>
       </NumberList>
</ns2:CommissionEvent>
<ns2:CommissionEvent>
       <NumberList>
        <Serial barcodeContent="(00)003551350000000907" companyPrefix="0355135" filterValue="0" format="AI(00)">00003551350000000907</Serial>
       </NumberList>
</ns2:CommissionEvent>
<ns2:CommissionEvent>
       <NumberList>
        <Serial barcodeContent="(00)003551350000000235" companyPrefix="0355135" filterValue="0" format="AI(00)">00003551350000000235</Serial>
       </NumberList>
</ns2:CommissionEvent>
</ns2:CommissionEvents>

Below is the attempt I made but did not get expected output--

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns2="urn:tracelink:mapper:sl:canonical:serialized_operations_manager"
xpath-default-namespace="urn:tracelink:mapper:sl:canonical:commontypes"
xmlns:ns0="urn:tracelink:mapper:sl:canonical:commontypes">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/ns2:CommissionEvents">
    <xsl:copy>
        <xsl:for-each-group select="ns2:CommissionEvent" group-by="NumberList/Serial/concat(@filterValue, '|', @format)">
            <ns2:CommissionEvent>
                <ns0:NumberList>
                    <xsl:for-each select="current-group()">
                        <ns0:Serial> 
                            <xsl:copy-of select="NumberList/Serial/(@*|text())"/>
                        </ns0:Serial> 
                    </xsl:for-each>
                </ns0:NumberList>
            </ns2:CommissionEvent> 
        </xsl:for-each-group>
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>

Output from above xslt --

<ns2:CommissionEvents>              
        <ns2:CommissionEvent>
           <ns0:NumberList>
            <ns0:Serial barcodeContent="(01)00355135132011(21)897883089643(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)" />
            <ns0:Serial barcodeContent="(01)00355135132011(21)903131477120(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)" />
            <ns0:Serial barcodeContent="(01)00355135132011(21)189513222896(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)" />
            <ns0:Serial barcodeContent="(01)00355135132011(21)468091235492(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)" />
            <ns0:Serial barcodeContent="(01)00355135132011(21)704297270475(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)" />
            </ns0:NumberList>
    </ns2:CommissionEvent>
    <ns2:CommissionEvent>
           <ns0:NumberList>
            <ns0:Serial barcodeContent="(01)30355135132012(21)389170110454(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="3" format="AI(01)+AI(21)" />
            <ns0:Serial barcodeContent="(01)30355135132012(21)724826376009(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="3" format="AI(01)+AI(21)" />
           </ns0:NumberList>
    </ns2:CommissionEvent>
    <ns2:CommissionEvent>
            <ns0:NumberList>
            <ns0:Serial barcodeContent="(00)003551350000000907" companyPrefix="0355135" filterValue="0" format="AI(00)" />
            <ns0:Serial barcodeContent="(00)003551350000000235" companyPrefix="0355135" filterValue="0" format="AI(00)" />
           </ns0:NumberList>
    </ns2:CommissionEvent>
    </ns2:CommissionEvents>

The output I'm trying to achieve is something like the below. I tried for each loop grouping based on @filterValue and @format. Could someone help me achieving this using xslt 2.0

<ns2:CommissionEvents>              
        <ns2:CommissionEvent>
           <ns0:NumberList>
            <ns0:Serial barcodeContent="(01)00355135132011(21)897883089643(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)" />
            <ns0:Serial barcodeContent="(01)00355135132011(21)903131477120(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)" />
            </ns0:NumberList>
    </ns2:CommissionEvent>
    <ns2:CommissionEvent>
           <ns0:NumberList>
            <ns0:Serial barcodeContent="(01)00355135132011(21)189513222896(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)" />
            <ns0:Serial barcodeContent="(01)00355135132011(21)468091235492(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)" />
            <ns0:Serial barcodeContent="(01)00355135132011(21)704297270475(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="0" format="AI(01)+AI(21)" />
            </ns0:NumberList>
    </ns2:CommissionEvent>
    <ns2:CommissionEvent>
           <ns0:NumberList>
            <ns0:Serial barcodeContent="(01)30355135132012(21)389170110454(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="3" format="AI(01)+AI(21)" />
            <ns0:Serial barcodeContent="(01)30355135132012(21)724826376009(17)230430(10)TLSMKTST" companyPrefix="0355135" filterValue="3" format="AI(01)+AI(21)" />
           </ns0:NumberList>
    </ns2:CommissionEvent>
    <ns2:CommissionEvent>
            <ns0:NumberList>
            <ns0:Serial barcodeContent="(00)003551350000000907" companyPrefix="0355135" filterValue="0" format="AI(00)" />
            <ns0:Serial barcodeContent="(00)003551350000000235" companyPrefix="0355135" filterValue="0" format="AI(00)" />
           </ns0:NumberList>
    </ns2:CommissionEvent>
    </ns2:CommissionEvents>
0 Answers
Related