xsl 1.0 muenchian sum 对每个复合键的数量字段求和 [英] xsl 1.0 muenchian sum to sum quantity field per compound key

查看:25
本文介绍了xsl 1.0 muenchian sum 对每个复合键的数量字段求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 SAP PO xsl 1.0 映射,我需要映射来自我们仓库的异国情调"文件,我需要在行标识符 (MASTER_PO_LINE_NO) 和商品编号 (SKU).每行 (RECL) 位于标题 (RECH) 中.

For a SAP PO xsl 1.0 mapping I need to map an 'exotic' file coming from our warehouse where I need to group/sum per order (RECH) a QTY field on a combination of a line identifier (MASTER_PO_LINE_NO) and an Itemnumber (SKU). Each line (RECL) is in a header (RECH).

输入:

    <?xml version="1.0" encoding="UTF-8"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
   <ns0:Message1>
<MARCXML>
  <RCIC>
    <RECH>
      <SALESID>24000</SALESID>
      <RECL>
        <LINE_NO>1</LINE_NO>
        <QTY_EXPE>1592</QTY_EXPE>
        <SKU>11207-210</SKU>
        <MASTER_PO_LINE_NO>10</MASTER_PO_LINE_NO>
      </RECL>
      <RECL>
        <LINE_NO>2</LINE_NO>
        <QTY_EXPE>1000</QTY_EXPE>
        <SKU>11207-210</SKU>
        <MASTER_PO_LINE_NO>10</MASTER_PO_LINE_NO>
      </RECL>
      <RECL>
        <LINE_NO>3</LINE_NO>
        <QTY_EXPE>175</QTY_EXPE>
        <SKU>11207-210</SKU>
        <MASTER_PO_LINE_NO>20</MASTER_PO_LINE_NO>
      </RECL>
    </RECH>
    <RECH>
      <SALESID>25001</SALESID>
      <RECL>
        <LINE_NO>1</LINE_NO>
        <QTY_EXPE>440</QTY_EXPE>
        <SKU>20000-210</SKU>
        <MASTER_PO_LINE_NO>10</MASTER_PO_LINE_NO>
      </RECL>
    </RECH>
  </RCIC>
</MARCXML>
 </ns0:Message1>
</ns0:Messages>

所需的输出(11207-210 的数量 = 1592 + 1000):

Required OUTPUT (Qty for 11207-210 = 1592 + 1000):

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
   <ns0:Message1>
<MARCXML>
  <RCIC>
    <RECH>
      <SALESID>24000</SALESID>
      <RECL>
        <LINE_NO>1</LINE_NO>
        <QTY_EXPE>2592</QTY_EXPE>
        <SKU>11207-210</SKU>
        <MASTER_PO_LINE_NO>10</MASTER_PO_LINE_NO>
      </RECL>
      <RECL>
        <LINE_NO>3</LINE_NO>
        <QTY_EXPE>175</QTY_EXPE>
        <SKU>11207-210</SKU>
        <MASTER_PO_LINE_NO>20</MASTER_PO_LINE_NO>
      </RECL>
    </RECH>
    <RECH>
      <SALESID>25001</SALESID>
      <RECL>
        <LINE_NO>1</LINE_NO>
        <QTY_EXPE>440</QTY_EXPE>
        <SKU>20000-210</SKU>
        <MASTER_PO_LINE_NO>10</MASTER_PO_LINE_NO>
      </RECL>
    </RECH>
  </RCIC>
</MARCXML>
 </ns0:Message1>
</ns0:Messages>

有很多关于 muenchian 分组的例子,但我还没有设法解决我的要求.老实说,我做到了:

There are plenty of examples about muenchian grouping but I didn't manage to solve my requirement yet. To be honest I got as far as:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
   <ns0:Message1>
      <MARCXML>
         <RCIC>
            <RECH>5284</RECH>
            <RECH>5284</RECH>
            <RECH>5284</RECH>
         </RCIC>
      </MARCXML>
   </ns0:Message1>
</ns0:Messages>

使用以下 xsl:

<?xml version="1.0" encoding="UTF-8"?>


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


    <xsl:key name="kMSTR_PO_LN_SKU" match="RECL"
     use="concat(MASTER_PO_LINE_NO, '#', SKU)"/>


    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="RECH">
        <xsl:copy>
            <xsl:value-of select="sum(//MARCXML/RCIC/RECH/RECL/QTY_CHECKED_IN)" />

            <xsl:for-each select="/RECL[generate-id()=generate-id(key('kMSTR_PO_LN_SKU',concat(MASTER_PO_LINE_NO,'-',SKU))[1])]">
                <xsl:copy>
                    <SKU>
                        <xsl:value-of select="SKU"/>
                    </SKU>
                    <Quantity>
                        <xsl:value-of select="sum(key('kMSTR_PO_LN_SKU',concat(MASTER_PO_LINE_NO,'-',RECL))/QTY_EXPE)"/>
                    </Quantity>
                </xsl:copy>
            </xsl:for-each>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

希望有人能在我来这里的路上帮助我

Hope someone can help me on my way here

推荐答案

AFAICT,这会产生所需的输出 - 但只有一个示例,规则有些模糊,这可能是巧合.无论如何,它应该为您提供一个起点.

AFAICT, this produces the required output - but having only a single example with somewhat ambiguous rules it could be a coincidence. In any case, it should provide you with a starting point.

XSLT 1.0

<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="k1" match="RECL" use="concat(MASTER_PO_LINE_NO, '|', SKU)"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="RECH">
    <xsl:copy>
        <xsl:copy-of select="SALESID"/>
        <xsl:for-each select="RECL[generate-id()=generate-id(key('k1', concat(MASTER_PO_LINE_NO,'|',SKU))[1])]">
            <xsl:copy>
                <xsl:copy-of select="LINE_NO"/>
                <QTY_EXPE>
                    <xsl:value-of select="sum(key('k1', concat(MASTER_PO_LINE_NO,'|',SKU))/QTY_EXPE)" />
                </QTY_EXPE>
                <xsl:copy-of select="SKU | MASTER_PO_LINE_NO"/>
            </xsl:copy>
        </xsl:for-each>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

<小时>

添加:

为了分别汇总每个订单(RECH),您必须在key中添加订单的标识符:


Added:

In order to summarize every order (RECH) separately, you must add an identifier of the order to the key:

XSLT 1.0

<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="k1" match="RECL" use="concat(MASTER_PO_LINE_NO, '|', SKU, '|', generate-id(..))"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="RECH">
    <xsl:copy>
        <xsl:copy-of select="SALESID"/>
        <xsl:for-each select="RECL[generate-id()=generate-id(key('k1', concat(MASTER_PO_LINE_NO,'|',SKU, '|', generate-id(..)))[1])]">
            <xsl:copy>
                <xsl:copy-of select="LINE_NO"/>
                <QTY_EXPE>
                    <xsl:value-of select="sum(key('k1', concat(MASTER_PO_LINE_NO,'|',SKU, '|', generate-id(..)))/QTY_EXPE)" />
                </QTY_EXPE>
                <xsl:copy-of select="SKU | MASTER_PO_LINE_NO"/>
            </xsl:copy>
        </xsl:for-each>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

这篇关于xsl 1.0 muenchian sum 对每个复合键的数量字段求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆