0
votes

Before i go to the actual question i must say certain things. i understand this topic is already discussed much in this forum. but still my situation is bit unique.

i have to perform this transform inside a tool called BMC atrium orchestrator version 7.9 , which uses not just xslt 1.0 but the XSLT processor it uses is also bit older or not that much friendly .why am saying this at the very begging is

xslt 1.0 nested grouping

this very simple nested transform listed above in the link itself , am not able to perform in that tool . just copying and pasting the source xml and xslt it showing error.

below is the source xml

 <root>
    <order>
        <item>
            <item_type>A</item_type>
            <item_type>A</item_type>
            <item_type>B</item_type>
            <item_type>C</item_type>
        </item>
    </order>
    <order>
        <item>
            <item_type>A</item_type>
            <item_type>B</item_type>
            <item_type>C</item_type>
            <item_type>C</item_type>
        </item>
    </order>
    <order>
        <item>
            <item_type>C</item_type>
            <item_type>C</item_type>
            <item_type>B</item_type>
        </item>
    </order>
 </root>

below is the source xslt

xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:key name="groups" match="item_type" use="concat(., '|', generate-id(ancestor::order))"/>

<xsl:template match="/root">
    <root>
        <xsl:for-each select="order">
            <order>                
                <xsl:for-each select="item/item_type[generate-id() = generate-id(key('groups', concat(., '|', generate-id(ancestor::order)))[1])]">
                    <item>
                        <xsl:value-of select="."/>
                    </item>
                </xsl:for-each>     
            </order>
        </xsl:for-each>     
    </root>
</xsl:template>

</xsl:stylesheet>

above xml & XSLT is solely given to say that such a simple transformation is not working for some reason with my tool. screen shots in comment section. but that is not my actual problem. as i gave the background , now am moving to actual question

my source xml

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <element>
      <credat>20180518</credat>
      <cretim>06:25:10</cretim>
      <docnum>1177016</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-039723</field1>
      <field14>ENTRY_QNT-150.000</field14>
      <field15>ENTRY_UOM-PK</field15>
      <field2>PLANT-GB20</field2>
      <field3>STGE_LOC-GB30</field3>
      <field4>BATCH-A012A02</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; &amp; : Original Batch &amp; differs from Confirmed Batch &amp;</statusMessage>
   </element>
   <element>
      <credat>20180518</credat>
      <cretim>06:26:30</cretim>
      <docnum>1177017</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-039723</field1>
      <field14>ENTRY_QNT-150.000</field14>
      <field15>ENTRY_UOM-PK</field15>
      <field2>PLANT-GB20</field2>
      <field3>STGE_LOC-GB30</field3>
      <field4>BATCH-A012A02</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; &amp; : Original Batch &amp; differs from Confirmed Batch &amp;</statusMessage>
   </element>
   <element>
      <credat>20180518</credat>
      <cretim>06:26:51</cretim>
      <docnum>1177018</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-039723</field1>
      <field14>ENTRY_QNT-150.000</field14>
      <field15>ENTRY_UOM-PK</field15>
      <field2>PLANT-GB20</field2>
      <field3>STGE_LOC-GB30</field3>
      <field4>BATCH-A012A02</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; &amp; : Original Batch &amp; differs from Confirmed Batch &amp;</statusMessage>
   </element>
   <element>
      <credat>20180604</credat>
      <cretim>12:21:35</cretim>
      <docnum>1177592</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-039723</field1>
      <field14>ENTRY_QNT-150.000</field14>
      <field15>ENTRY_UOM-PK</field15>
      <field2>PLANT-GB20</field2>
      <field3>STGE_LOC-GB30</field3>
      <field4>BATCH-A012A02</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; &amp; : Original Batch &amp; differs from Confirmed Batch &amp;</statusMessage>
   </element>
   <element>
      <credat>20180604</credat>
      <cretim>12:21:45</cretim>
      <docnum>1177593</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-039723</field1>
      <field14>ENTRY_QNT-150.000</field14>
      <field15>ENTRY_UOM-PK</field15>
      <field2>PLANT-GB20</field2>
      <field3>STGE_LOC-GB30</field3>
      <field4>BATCH-A012A02</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; &amp; : Original Batch &amp; differs from Confirmed Batch &amp;</statusMessage>
   </element>
   <element>
      <credat>20180614</credat>
      <cretim>16:04:13</cretim>
      <docnum>1178094</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180618</credat>
      <cretim>12:07:05</cretim>
      <docnum>1178407</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180619</credat>
      <cretim>09:08:31</cretim>
      <docnum>1178456</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180619</credat>
      <cretim>09:12:07</cretim>
      <docnum>1178644</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180619</credat>
      <cretim>10:13:17</cretim>
      <docnum>1178649</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180620</credat>
      <cretim>15:25:03</cretim>
      <docnum>1178722</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180620</credat>
      <cretim>15:27:48</cretim>
      <docnum>1178723</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180620</credat>
      <cretim>15:31:47</cretim>
      <docnum>1178724</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180620</credat>
      <cretim>15:35:49</cretim>
      <docnum>1178725</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180620</credat>
      <cretim>15:38:50</cretim>
      <docnum>1178726</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180620</credat>
      <cretim>15:42:36</cretim>
      <docnum>1178727</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180620</credat>
      <cretim>15:44:40</cretim>
      <docnum>1178728</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180620</credat>
      <cretim>16:01:54</cretim>
      <docnum>1178732</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT121</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180621</credat>
      <cretim>08:21:13</cretim>
      <docnum>1178745</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT121</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180628</credat>
      <cretim>10:17:25</cretim>
      <docnum>1180138</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected];[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCR</mestyp>
      <rcvprn>SR1CLNT121</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>&amp; exceeded by &amp; &amp; &amp;</statusMessage>
   </element>
   <element>
      <credat>20180628</credat>
      <cretim>10:19:32</cretim>
      <docnum>1180139</docnum>
      <emailidCc>[email protected]</emailidCc>
      <emailidTo>[email protected]</emailidTo>
      <field1>MATERIAL-111116</field1>
      <field14>ENTRY_QNT-20.000</field14>
      <field15>ENTRY_UOM-EA</field15>
      <field2>PLANT-RU20</field2>
      <field3>STGE_LOC-RU20</field3>
      <field4>BATCH-E979A01</field4>
      <field5>MOVE_TYPE-101</field5>
      <idocStatus>Business Input Needed</idocStatus>
      <mestyp>MBGMCL</mestyp>
      <rcvprn>SR1CLNT120</rcvprn>
      <statusCode>51</statusCode>
      <statusMessage>Posting only possible in periods &amp;1 and &amp;2 in company code &amp;3</statusMessage>
   </element>
</root>

my desired result :

        <root>
           <element>
              <rcvprn>SR1CLNT120</rcvprn>
              <mestype>MBGMCR</mestype>
              <emailidCc>[email protected]</emailidCc>       <emailidTo>[email protected];[email protected]</emailidTo>
                <docnum>
                    1177016
                    1177017
                    1177018
                    1177592
                    1177593
                    1178094
                    1178407
                    1178456
                    1178644
                    1178649
                    1178722
                    1178723
                    1178724
                    1178725
                    1178726
                    1178727
                    1178728
                  </docnum>
       </element>

        <element>
        <emailidCc>[email protected]</emailidCc>                                                                        
   <emailidTo>[email protected];[email protected]</emailidTo>
        <rcvprn>SR1CLNT121</rcvprn>
        <mestype>MBGMCR</mestype>
                <docnum>
                    1178732
                    1178745
                    1180138
              </docnum>
        </element>


       <element>
        <emailidCc>[email protected]</emailidCc>
 <emailidTo>[email protected];[email protected]</emailidTo>
        <rcvprn>SR1CLNT120</rcvprn>
        <mestype>MBGMCL</mestype>
                <docnum>
                     1180139
              </docnum>
        </element>
        </root>

Now i will say the grouping rules :

  1. docnum is the element to be grouped
  2. all docnum elements having same rcvprn and msgtyp values must be grouped in to one and their email id "to" and "cc" must be Unioned respectively with each other .

future requirement in future there may be couple of other feilds might get added to club the docnum feilds.

1
Well, if you get an error then at least tell us exactly which error you get.Martin Honnen
It might also help knowing which XSLT processor your tool uses. Although if it is not XSLT 1.0 conformant there's not much we can do to help, since we don't know which standard it does conform to.michael.hor257k
ibb.co/hR1LC1y in the above link right hand side u can see the error. left hand side you can see the options available in the builtin tool to build an xsltseetharaman
The screenshot and the error message suggest you are trying to use XSLT 2.0 for-each-group with an XSLT 1 processor so no idea why you link to an XSLT 1.0 article about nested grouping and claim it doesn't work, I don't see any for-each-group in the older post you linked to.Martin Honnen
ibb.co/5vVHLCQ -> please refer this sir. that was a wrong screen shot i uploaded. i applogies for that. this is a screen shot of a valid xslt 1 grouping. this is what not working . xml and xslt used are from the same above article i quoted.seetharaman

1 Answers

0
votes

I can't see anything wrong with your XSLT, so your XSLT processor must be really old if it does not support xsl:key. (Or possibly, it does not like concat or generate-id. You could try defining the key as <xsl:key name="groups" match="item_type" use="."/>, for example. Although that would be no good for getting your output, it may help narrow down the problem with the processor)

If xsl:key is indeed not supported, you would have to fall back to the inefficient way of doing things, and simply check preceding siblings

Try this XSLT:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/root">
    <root>
        <xsl:for-each select="order">
            <order>                
                <xsl:for-each select="item/item_type[not(. = preceding-sibling::item_type)]">
                    <item>
                        <xsl:value-of select="."/>
                    </item>
                </xsl:for-each>     
            </order>
        </xsl:for-each>     
    </root>
</xsl:template>
</xsl:stylesheet>

EDIT: To put this sample to practise, for your actual XML, it becomes much nastier, but try this (very inefficient) XSLT

<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:strip-space elements="*"/>

<xsl:template match="/">
  <root>
    <xsl:for-each select="/root/element[not(rcvprn = preceding-sibling::element/rcvprn)]">
      <xsl:variable name="rcvprn" select="rcvprn" />
      <xsl:variable name="rvcprngroup" select="../element[rcvprn = $rcvprn]" />

      <xsl:for-each select="$rvcprngroup[not(mestyp = preceding-sibling::element[rcvprn = $rcvprn]/mestyp)]">
        <xsl:variable name="mestyp" select="mestyp" />
        <xsl:variable name="mestypgroup" select="$rvcprngroup[mestyp = $mestyp]" />

        <element>
          <xsl:copy-of select="mestyp|rcvprn"/>
          <emailidTo>
            <xsl:for-each select="$mestypgroup">
              <xsl:value-of select="emailidTo" />
              <xsl:text>;</xsl:text>
            </xsl:for-each>
          </emailidTo>
          <docnum>
            <xsl:for-each select="$mestypgroup[not(docnum = preceding-sibling::element[rcvprn = $rcvprn and mestyp = $mestyp]/docnum)]">
              <xsl:value-of select="docnum" />
              <xsl:text>&#10;</xsl:text>
            </xsl:for-each>
          </docnum>
        </element>
      </xsl:for-each>
    </xsl:for-each>     
  </root>
</xsl:template>
</xsl:stylesheet>