XSL循环在每个级别上均无法正确进行

时间:2019-07-16 16:32:34

标签: loops xslt unique

我需要循环访问此SAP IDOC以报告货运数据。我需要中断G07节点(包装)中E2EDT37_KDMAT(零件号),E2EDT37_VHILM_KU(包装类型)和E2EDT37_QUANTITY的每次更改。当前的代码似乎一直有效,直到G01(SHIPMENT)节点中有多个G16(DELIVERY)节点为止。

此代码段不会产生XML输出,并且在消息输出中会看到该问题。

我认为我尝试的方法无效,我会找到另一种方法。但是我不明白为什么。我已经尝试了在前同级而不是在前,只是得到了不同的错误输出。

每个循环使用与最后一个相同的谓词,并添加一个或多个条件,以标识所有与E2EDT37记录匹配的内容,并对E2EDT37_KDMAT,E2EDT37_VHILM_KU和最后的E2EDT37_QUANTITY的每个唯一值执行一次下一条语句。它似乎非常接近,但是永远无法解决问题。我对E2EDT37_KDMAT [not(。= preceding :: E2EDT37_KDMAT)]在这里工作的方式有何误解?

代码:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.1"   xmlns:exsl="http://exslt.org/common"  
                                            xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                                            xmlns:XmlTransform="java:de.axway.converter.xml.xsltextensions.XsltExtensions" exclude-result-prefixes="XmlTransform xsl exsl">
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>

    <xsl:template match="/ACTIS">
        <xsl:message></xsl:message>
        <xsl:call-template name="DESADV_D96A"/>
    </xsl:template>

    <xsl:template name="DESADV_D96A">
        <xsl:for-each select="//G16">
            <xsl:variable name="current-delivery" select="E2EDL20/E2EDL20_VBELN "/>
            <xsl:choose>
                <xsl:when test="/ACTIS/G01/G07[@PACK_TYPE='OUTER']/E2EDT37[contains(E2EDT37_DELIVERIES, $current-delivery)]">
                    <xsl:call-template name="Create_Outer_PAC">
                        <xsl:with-param name="current-delivery" select=" $current-delivery "/>
                    </xsl:call-template>
                </xsl:when>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>

    <xsl:template name="Create_Outer_PAC">
        <xsl:param name="current-delivery"/>

        <xsl:message>In Create_Outer_PACK Delivery: <xsl:value-of select="$current-delivery"/></xsl:message>

        <xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='OUTER'][contains(E2EDT37_DELIVERIES, $current-delivery)]">
            <xsl:variable name="Pallet" select="current()"/>

            <xsl:message>For each Outer_PAC : <xsl:value-of select="$Pallet/E2EDT37_EXIDV"/></xsl:message>

            <xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery]/E2EDT37_KDMAT[not(.=preceding::E2EDT37_KDMAT)]">
                <xsl:variable name="current-part" select="current()"/>

                <xsl:message>For each E2EDT37_KDMAT : <xsl:value-of select="$current-part"/></xsl:message>

                <xsl:message select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part]/E2EDT37_VHILM_KU"/>

                <xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part]/E2EDT37_VHILM_KU[not(.=preceding::E2EDT37_VHILM_KU)]">
                    <xsl:variable name="current-vhilm_ku" select="current()"/>

                    <xsl:message>For each E2EDT37_VHILM_KU: <xsl:value-of select="$current-vhilm_ku"/></xsl:message>

                    <xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part][E2EDT37_VHILM_KU=$current-vhilm_ku]/E2EDT37_QUANTITY[not(.=preceding::E2EDT37_QUANTITY)]">
                        <xsl:variable name="current-packqty" select="current()"/>
                        <xsl:message></xsl:message>
                        <xsl:message>For each E2EDT37_QUANTITY: <xsl:value-of select="$current-packqty"/></xsl:message>
                    </xsl:for-each>
                </xsl:for-each>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

数据

<?xml version="1.0" encoding="UTF-8"?>
<ACTIS>
   <EDI_DC>
      <EDI_DC_TABNAM>EDI_DC40</EDI_DC_TABNAM>
      <EDI_DC_CREDAT>20190702</EDI_DC_CREDAT>
      <EDI_DC_CRETIM>210325</EDI_DC_CRETIM>
      <EDI_DC_SERIAL>20190702210323</EDI_DC_SERIAL>
   </EDI_DC>
   <G01>
      <E2EDT20>
         <E2EDT20_SEGNAM>E2EDT20002</E2EDT20_SEGNAM>
         <E2EDT20_MANDT>100</E2EDT20_MANDT>
         <E2EDT20_DOCNUM>0000004250699555</E2EDT20_DOCNUM>
         <E2EDT20_SEGNUM>000001</E2EDT20_SEGNUM>
         <E2EDT20_PSGNUM>000000</E2EDT20_PSGNUM>
         <E2EDT20_HLEVEL>01</E2EDT20_HLEVEL>
         <E2EDT20_TKNUM>0049409223</E2EDT20_TKNUM>
      </E2EDT20>
      <G07 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
         <E2EDT37 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
            <E2EDT37_SEGNAM>E2EDT37006</E2EDT37_SEGNAM>
            <E2EDT37_MANDT>100</E2EDT37_MANDT>
            <E2EDT37_DOCNUM>0000004250699555</E2EDT37_DOCNUM>
            <E2EDT37_SEGNUM>000044</E2EDT37_SEGNUM>
            <E2EDT37_PSGNUM>000001</E2EDT37_PSGNUM>
            <E2EDT37_HLEVEL>02</E2EDT37_HLEVEL>
            <E2EDT37_EXIDV>00000000000505755236</E2EDT37_EXIDV>
            <E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
            <E2EDT37_PACK_TYPE>INNER</E2EDT37_PACK_TYPE>
            <E2EDT37_CHILDREN>0</E2EDT37_CHILDREN>
            <E2EDT37_PARENT>505059227</E2EDT37_PARENT>
            <E2EDT37_DELIVERY>0037371519</E2EDT37_DELIVERY>
            <E2EDT37_DELIVERY_POSITION>000010</E2EDT37_DELIVERY_POSITION>
            <E2EDT37_QUANTITY>8500.000</E2EDT37_QUANTITY>
            <E2EDT37_UOM>PCE</E2EDT37_UOM>
            <E2EDT37_KDMAT>6561111</E2EDT37_KDMAT>
            <E2EDT37_VBRST>1000</E2EDT37_VBRST>
         </E2EDT37>
      </G07>
      <G07 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
         <E2EDT37 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
            <E2EDT37_SEGNAM>E2EDT37006</E2EDT37_SEGNAM>
            <E2EDT37_MANDT>100</E2EDT37_MANDT>
            <E2EDT37_DOCNUM>0000004250699555</E2EDT37_DOCNUM>
            <E2EDT37_SEGNUM>000047</E2EDT37_SEGNUM>
            <E2EDT37_PSGNUM>000001</E2EDT37_PSGNUM>
            <E2EDT37_HLEVEL>02</E2EDT37_HLEVEL>
            <E2EDT37_EXIDV>00000000000505755237</E2EDT37_EXIDV>
            <E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
            <E2EDT37_PACK_TYPE>INNER</E2EDT37_PACK_TYPE>
            <E2EDT37_CHILDREN>0</E2EDT37_CHILDREN>
            <E2EDT37_PARENT>505059227</E2EDT37_PARENT>
            <E2EDT37_DELIVERY>0037371484</E2EDT37_DELIVERY>
            <E2EDT37_DELIVERY_POSITION>000010</E2EDT37_DELIVERY_POSITION>
            <E2EDT37_QUANTITY>7000.000</E2EDT37_QUANTITY>
            <E2EDT37_UOM>PCE</E2EDT37_UOM>
            <E2EDT37_KDMAT>6561143</E2EDT37_KDMAT>
            <E2EDT37_VBRST>1000</E2EDT37_VBRST>
         </E2EDT37>
      </G07>
      <G07 PACK_TYPE="OUTER" CHILDREN="2" MIXED="1">
         <E2EDT37 PACK_TYPE="OUTER" CHILDREN="2" MIXED="1">
            <E2EDT37_SEGNAM>E2EDT37006</E2EDT37_SEGNAM>
            <E2EDT37_MANDT>100</E2EDT37_MANDT>
            <E2EDT37_DOCNUM>0000004250699555</E2EDT37_DOCNUM>
            <E2EDT37_SEGNUM>000050</E2EDT37_SEGNUM>
            <E2EDT37_PSGNUM>000001</E2EDT37_PSGNUM>
            <E2EDT37_HLEVEL>02</E2EDT37_HLEVEL>
            <E2EDT37_EXIDV>505059227</E2EDT37_EXIDV>
            <E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
            <E2EDT37_CHILDREN>2</E2EDT37_CHILDREN>
            <E2EDT37_CONTENTS>00000000000505755236:00000000000505755237:</E2EDT37_CONTENTS>
            <E2EDT37_PACK_TYPE>OUTER</E2EDT37_PACK_TYPE>
            <E2EDT37_DELIVERIES>0037371519 0037371484</E2EDT37_DELIVERIES>
         </E2EDT37>
      </G07>
      <G16>
         <E2EDL20>
            <E2EDL20_SEGNAM>E2EDL20004</E2EDL20_SEGNAM>
            <E2EDL20_MANDT>100</E2EDL20_MANDT>
            <E2EDL20_DOCNUM>0000004250699555</E2EDL20_DOCNUM>
            <E2EDL20_SEGNUM>000077</E2EDL20_SEGNUM>
            <E2EDL20_PSGNUM>000001</E2EDL20_PSGNUM>
            <E2EDL20_HLEVEL>02</E2EDL20_HLEVEL>
            <E2EDL20_VBELN>0037371484</E2EDL20_VBELN>
            <E2EDL20_VSTEL>0016</E2EDL20_VSTEL>
            <E2EDL20_VKORG>0060</E2EDL20_VKORG>
            <E2EDL20_VKBUR>EUR</E2EDL20_VKBUR>
            <E2EDL20_LGNUM>D16</E2EDL20_LGNUM>
            <E2EDL20_ABLAD>JAG01</E2EDL20_ABLAD>
            <E2EDL20_INCO1>FCA</E2EDL20_INCO1>
            <E2EDL20_INCO2>NÜRNBERG</E2EDL20_INCO2>
            <E2EDL20_ROUTE>DES129</E2EDL20_ROUTE>
            <E2EDL20_VSBED>ST</E2EDL20_VSBED>
            <E2EDL20_BTGEW>107.000</E2EDL20_BTGEW>
            <E2EDL20_NTGEW>107.000</E2EDL20_NTGEW>
            <E2EDL20_GEWEI>KGM</E2EDL20_GEWEI>
            <E2EDL20_VOLUM>1036.427</E2EDL20_VOLUM>
            <E2EDL20_VOLEH>DMQ</E2EDL20_VOLEH>
            <E2EDL20_ANZPK>00000</E2EDL20_ANZPK>
            <E2EDL20_PARID>UNKNOWN</E2EDL20_PARID>
            <E2EDL20_PODAT>20190702</E2EDL20_PODAT>
            <E2EDL20_POTIM>210324</E2EDL20_POTIM>
         </E2EDL20>
         <G29>
            <E2EDL24>
               <E2EDL24_POSNR>000010</E2EDL24_POSNR>
               <E2EDL24_KDMAT>6561143</E2EDL24_KDMAT>
               <E2EDL24_LFIMG>7000.000</E2EDL24_LFIMG>
               <E2EDL24_VRKME>PCE</E2EDL24_VRKME>
               <E2EDL24_VBRST>1000</E2EDL24_VBRST>
               <E2EDL24_KDMAT35>6561143</E2EDL24_KDMAT35>
               <E2EDL24_POSEX>000000</E2EDL24_POSEX>
               <E2EDL24_DELIVERY>0037371484</E2EDL24_DELIVERY>
               <E2EDL24_PO>5500229851</E2EDL24_PO>
               <E2EDL24_PO_DATE>20150612</E2EDL24_PO_DATE>
            </E2EDL24>
         </G29>
         <G29>
            <E2EDL24>
               <E2EDL24_POSNR>900001</E2EDL24_POSNR>
               <E2EDL24_KDMAT>0000SON</E2EDL24_KDMAT>
               <E2EDL24_LFIMG>1.000</E2EDL24_LFIMG>
               <E2EDL24_VRKME>PCE</E2EDL24_VRKME>
               <E2EDL24_VBRST>1000</E2EDL24_VBRST>
               <E2EDL24_KDMAT35>0000SON</E2EDL24_KDMAT35>
               <E2EDL24_POSEX>000000</E2EDL24_POSEX>
               <E2EDL24_DELIVERY>0037371484</E2EDL24_DELIVERY>
            </E2EDL24>
         </G29>
      </G16>
      <G16>
         <E2EDL20>
            <E2EDL20_SEGNAM>E2EDL20004</E2EDL20_SEGNAM>
            <E2EDL20_MANDT>100</E2EDL20_MANDT>
            <E2EDL20_DOCNUM>0000004250699555</E2EDL20_DOCNUM>
            <E2EDL20_SEGNUM>000170</E2EDL20_SEGNUM>
            <E2EDL20_PSGNUM>000001</E2EDL20_PSGNUM>
            <E2EDL20_HLEVEL>02</E2EDL20_HLEVEL>
            <E2EDL20_VBELN>0037371519</E2EDL20_VBELN>
            <E2EDL20_VSTEL>0016</E2EDL20_VSTEL>
            <E2EDL20_VKORG>0060</E2EDL20_VKORG>
            <E2EDL20_VKBUR>EUR</E2EDL20_VKBUR>
            <E2EDL20_LGNUM>D16</E2EDL20_LGNUM>
            <E2EDL20_ABLAD>JAG01</E2EDL20_ABLAD>
            <E2EDL20_INCO1>FCA</E2EDL20_INCO1>
            <E2EDL20_INCO2>NÜRNBERG</E2EDL20_INCO2>
            <E2EDL20_ROUTE>DES129</E2EDL20_ROUTE>
            <E2EDL20_VSBED>ST</E2EDL20_VSBED>
            <E2EDL20_BTGEW>140.600</E2EDL20_BTGEW>
            <E2EDL20_NTGEW>127.500</E2EDL20_NTGEW>
            <E2EDL20_GEWEI>KGM</E2EDL20_GEWEI>
            <E2EDL20_VOLUM>42840.000</E2EDL20_VOLUM>
            <E2EDL20_VOLEH>CMQ</E2EDL20_VOLEH>
            <E2EDL20_ANZPK>00000</E2EDL20_ANZPK>
            <E2EDL20_PARID>UNKNOWN</E2EDL20_PARID>
            <E2EDL20_PODAT>20190702</E2EDL20_PODAT>
            <E2EDL20_POTIM>210325</E2EDL20_POTIM>
         </E2EDL20>
         <G29>
            <E2EDL24>
               <E2EDL24_POSNR>000010</E2EDL24_POSNR>
               <E2EDL24_KDMAT>6561111</E2EDL24_KDMAT>
               <E2EDL24_LFIMG>8500.000</E2EDL24_LFIMG>
               <E2EDL24_VRKME>PCE</E2EDL24_VRKME>
               <E2EDL24_VBRST>1000</E2EDL24_VBRST>
               <E2EDL24_KDMAT35>6561111</E2EDL24_KDMAT35>
               <E2EDL24_POSEX>000000</E2EDL24_POSEX>
               <E2EDL24_DELIVERY>0037371519</E2EDL24_DELIVERY>
               <E2EDL24_PO>5500229848</E2EDL24_PO>
               <E2EDL24_PO_DATE>20150612</E2EDL24_PO_DATE>
            </E2EDL24>
         </G29>
      </G16>
   </G01>
</ACTIS>

结果输出

1)在Create_Outer_PAC交货中:0037371484

2)对于每个Outer_PAC:505059227

3)对于每个E2EDT37_KDMAT:6561143独特的KDMAT在这里很不错

我在这里找到并显示了一个匹配的VHILM_KU,但是尝试在每个VHILM_KU处循环的下一行不会出现与xsl:message相同的Xpath

<xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part]/E2EDT37_VHILM_KU[not(.=preceding::E2EDT37_VHILM_KU)]">

<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>

    No For each E2EDT37_VHILM_KU break on E2EDT37_VHILM_KU=0000SON

1)在Create_Outer_PAC交货中:0037371519

2)对于每个Outer_PAC:505059227

3)对于每个E2EDT37_KDMAT:6561111

<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>

    This one breaks as expected.  You see we have an E2EDT37_VHILM_KU found with value 0000SON in the line above here.

尽管我们也找到并显示了与0000SON相同的E2EDT37_VHILM_KU,但我没有在上面的第一个for-each循环中看到此消息。

我们有两个E2EDT37段,其KDMAT值为6561143和6561141。第一个循环按预期在每个唯一的KDMAT处中断。

4)对于每个E2EDT37_VHILM_KU:0000SON

5)对于每个E2EDT37_QUANTITY:8500.000

在使用谓词[E2EDT37_PACK_TYPE ='INNER'] [E2EDT37_PARENT = $ Pallet / E2EDT37_EXIDV] [E2EDT37_DELIVERY = $当前交付] [E2EDT37_KDMAT = $当前部分]?我以为那是我错的地方,但是范式对我来说还不清楚。消息输出显示Xpath确实找到了一个VHILM_KU。下一个具有相同Xpath的for-each语句什么也找不到。

更清晰或更令人困惑吗?

0 个答案:

没有答案