xslt 1.0中的嵌套分组

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xslt 1.0中的嵌套分组相关的知识,希望对你有一定的参考价值。

在我回到实际问题之前,我必须说出某些事情。我知道这个话题已在本论坛中进行了很多讨论。但我的情况仍然有点独特。

我必须在一个名为BMC atrium orchestrator版本7.9的工具中执行此转换,该工具不仅使用xslt 1.0,而且它使用的XSLT处理器也有点旧或者不那么友好。为什么我在乞讨时说的是

xslt 1.0 nested grouping

上面链接本身列出的这个非常简单的嵌套转换,无法在该工具中执行。只是复制并粘贴源xml和xslt它显示错误。

下面是源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>

下面是源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>

上面的xml和XSLT只是说我的工具出于某种原因这种简单的转换是行不通的。评论部分的屏幕截图。但这不是我的实际问题。正如我给出的背景,现在我正在转向实际的问题

我的源码xml

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <element>
      <credat>20180518</credat>
      <cretim>06:25:10</cretim>
      <docnum>1177016</docnum>
      <emailidCc>VIJAYMAHANTESH.PAWADI1@MERCK.COM</emailidCc>
      <emailidTo>RAJASHEKAR.ALETI@MERCK.COM;RAJNISH.SINHA@MERCK.COM</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>VIJAYMAHANTESH.PAWADI1@MERCK.COM</emailidCc>
      <emailidTo>RAJASHEKAR.ALETI@MERCK.COM;RAJNISH.SINHA@MERCK.COM</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>VIJAYMAHANTESH.PAWADI1@MERCK.COM</emailidCc>
      <emailidTo>RAJASHEKAR.ALETI@MERCK.COM;RAJNISH.SINHA@MERCK.COM</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>VIJAYMAHANTESH.PAWADI1@MERCK.COM</emailidCc>
      <emailidTo>RAJASHEKAR.ALETI@MERCK.COM;RAJNISH.SINHA@MERCK.COM</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>VIJAYMAHANTESH.PAWADI1@MERCK.COM</emailidCc>
      <emailidTo>RAJASHEKAR.ALETI@MERCK.COM;RAJNISH.SINHA@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@MERCK.COM</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>RAJASHEKAR.ALETI@MERCK.COM</emailidCc>
      <emailidTo>SREENIVAS.K@MERCK.COM</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>

我想要的结果:

        <root>
           <element>
              <rcvprn>SR1CLNT120</rcvprn>
              <mestype>MBGMCR</mestype>
              <emailidCc>RAJASHEKAR.ALETI@xx.COM</emailidCc>       <emailidTo>SREENIVAS.K@MERCK.COM;VIJAYMAHANTESH.PAWADI1@xx.COM</emailidTo>
                <docnum>
                    1177016
                    1177017
                    1177018
                    1177592
                    1177593
                    1178094
                    1178407
                    1178456
                    1178644
                    1178649
                    1178722
                    1178723
                    1178724
                    1178725
                    1178726
                    1178727
                    1178728
                  </docnum>
       </element>

        <element>
        <emailidCc>RAJASHEKAR.ALETI@xx.COM</emailidCc>                                                                        
   <emailidTo>SREENIVAS.K@xxx.COM;VIJAYMAHANTESH.PAWADI1@xx.COM</emailidTo>
        <rcvprn>SR1CLNT121</rcvprn>
        <mestype>MBGMCR</mestype>
                <docnum>
                    1178732
                    1178745
                    1180138
              </docnum>
        </element>


       <element>
        <emailidCc>RAJASHEKAR.ALETI@xx.COM</emailidCc>
 <emailidTo>SREENIVAS.K@xxx.COM;VIJAYMAHANTESH.PAWADI1@xx.COM</emailidTo>
        <rcvprn>SR1CLNT120</rcvprn>
        <mestype>MBGMCL</mestype>
                <docnum>
                     1180139
              </docnum>
        </element>
        </root>

现在我要说分组规则:

  1. docnum是要分组的元素
  2. 所有具有相同rcvprn和msgtyp值的docnum元素必须分组为一个,并且它们的电子邮件ID“to”和“cc”必须相互联合。

未来的未来要求可能还有其他几个领域可能会加入到docnum领域。

答案

我看不出你的XSLT有什么问题,所以如果它不支持xsl:key你的XSLT处理器必须真的老了。 (或者可能,它不喜欢concatgenerate-id。例如,您可以尝试将密钥定义为<xsl:key name="groups" match="item_type" use="."/>。虽然这对于获取输出没有好处,但它可能有助于缩小处理器的问题范围)

如果确实不支持xsl:key,你将不得不回到低效的做事方式,只需检查前面的兄弟姐妹

试试这个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>

编辑:要将此示例付诸实践,对于您的实际XML,它变得更加糟糕,但尝试这个(非常低效)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>

以上是关于xslt 1.0中的嵌套分组的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Muenchian 分组 XSLT 1.0 在每个目录中按标题分组

XSLT 1.0 中的分组和计数

如何在下面的 XSLT 1.0 代码中进行分组。需要按 TaxRateCode 分组

维护嵌套元素的分组方法 XSLT 2.0 - 分离多余的

使用 XSLT 1.0 对值进行分组

基于列表中的日期字段,在每一天对使用XSLT 1.0的列表进行分组