我有一个XSL转换(XSLT 1.0),它获取以下数据:
<?xml version="1.0" encoding="UTF-8" ?>
<PsWeIni025StgCollection xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/top/DB_SEL_MSR_PPLSFT">
<PsWeIni025Stg>
<origOprid>TL47695</origOprid>
<orderNo>MSR0144232</orderNo>
<orderIntLineNo>1</orderIntLineNo>
<invItemId>0085400</invItemId>
<businessUnit>10TOC</businessUnit>
<distribType></distribType>
<operatingUnit>10000</operatingUnit>
<actionFlg>A</actionFlg>
</PsWeIni025Stg>
<PsWeIni025Stg>
<origOprid>TL47695</origOprid>
<orderNo>MSR0144232</orderNo>
<orderIntLineNo>2</orderIntLineNo>
<invItemId>0074255</invItemId>
<businessUnit>10TOC</businessUnit>
<distribType></distribType>
<operatingUnit>10000</operatingUnit>
<actionFlg>A</actionFlg>
</PsWeIni025Stg>
<PsWeIni025Stg>
<origOprid>TL47695</origOprid>
<orderNo>MSR0144232</orderNo>
<orderIntLineNo>3</orderIntLineNo>
<invItemId>0174400</invItemId>
<businessUnit>10TOC</businessUnit>
<distribType></distribType>
<operatingUnit>10000</operatingUnit>
<actionFlg>A</actionFlg>
</PsWeIni025Stg>
<PsWeIni025Stg>
<origOprid>TL47695</origOprid>
<orderNo>MSR0144232</orderNo>
<orderIntLineNo>4</orderIntLineNo>
<invItemId>0171400</invItemId>
<businessUnit>10TOC</businessUnit>
<distribType></distribType>
<operatingUnit>10000</operatingUnit>
<actionFlg>A</actionFlg>
</PsWeIni025Stg>
<PsWeIni025Stg>
<origOprid>TL47695</origOprid>
<orderNo>MSR0144232</orderNo>
<orderIntLineNo>5</orderIntLineNo>
<invItemId>0144000</invItemId>
<businessUnit>10TOC</businessUnit>
<distribType></distribType>
<operatingUnit>10000</operatingUnit>
<actionFlg>A</actionFlg>
</PsWeIni025Stg>
<PsWeIni025Stg>
<origOprid>TL47695</origOprid>
<orderNo>MSR0144233</orderNo>
<orderIntLineNo>1</orderIntLineNo>
<invItemId>0085400</invItemId>
<businessUnit>10TOC</businessUnit>
<distribType></distribType>
<operatingUnit>10000</operatingUnit>
<actionFlg>A</actionFlg>
</PsWeIni025Stg>
<PsWeIni025Stg>
<origOprid>TL47695</origOprid>
<orderNo>MSR0144233</orderNo>
<orderIntLineNo>2</orderIntLineNo>
<invItemId>0074255</invItemId>
<businessUnit>10TOC</businessUnit>
<distribType></distribType>
<operatingUnit>10000</operatingUnit>
<actionFlg>A</actionFlg>
</PsWeIni025Stg>
<PsWeIni025Stg>
<origOprid>TL47695</origOprid>
<orderNo>MSR0144233</orderNo>
<orderIntLineNo>3</orderIntLineNo>
<invItemId>0144000</invItemId>
<businessUnit>10TOC</businessUnit>
<distribType></distribType>
<operatingUnit>10000</operatingUnit>
<actionFlg>A</actionFlg>
</PsWeIni025Stg>
</PsWeIni025StgCollection>
基本上我们需要打破PsWeIni025Stg元素并将orderNo组合在一起。因此,第一个订单号MSR0144232有5个条目,第二个订单号MSR0144233有3个条目。这是一个精简版。
INVUSE
INVUSELINE
INVRESERVE
INVUSELINE
INVRESERVE
INVUSELINE
INVRESERVE
INVUSELINE
INVRESERVE
INVUSELINE
INVRESERVE
INVUSE
INVUSELINE
INVRESERVE
INVUSELINE
INVRESERVE
INVUSELINE
INVRESERVE
这是我们输出所需的更详细的版本。
<?xml version="1.0" encoding="UTF-8"?>
<SyncZXQINVRESERVE xmlns="http://www.ibm.com/maximo" xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/" xmlns:ns2="http://xmlns.Company.com/Common/Logging/V1.0" xmlns:ns1="http://xmlns.oracle.com/pcbpel/adapter/db/EAM_MaterialStockRequests/PPLSFT_MaterialStockRequest_ABCS_req/DB_SEL_MSR_PPLSFT" xmlns:ns4="http://xmlns.Company.com/Common/Errors/V1.0" xmlns:ns3="http://xmlns.Company.com/core/CommonTypes/V1.0" xmlns:mxws="http://www.ibm.com/maximo/wsdl/ZXQWSPS_ZXQMXINVRESInterface" xmlns:tns="http://www.ibm.com/maximo" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:pc="http://xmlns.oracle.com/pcbpel/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
<tns:ZXQINVRESERVESet>
<tns:INVUSE>
<tns:AUTOCREATED>TL47695</tns:AUTOCREATED>
<tns:DESCRIPTION>MSR:MSR0144234 3101100028</tns:DESCRIPTION>
<tns:ZXQMSRNUM>MSR0144234</tns:ZXQMSRNUM>
<tns:INVUSELINE>
<tns:FROMSTORELOC>10TOC</tns:FROMSTORELOC>
<tns:INVUSELINENUM>1</tns:INVUSELINENUM>
<tns:ITEMNUM>0085400</tns:ITEMNUM>
<tns:INVRESERVE action="Add">
<tns:ACTUALQTY>0</tns:ACTUALQTY>
<tns:EXTERNALREFID>MSR0144234</tns:EXTERNALREFID>
<tns:ITEMNUM>0085400</tns:ITEMNUM>
</tns:INVRESERVE>
</tns:INVUSELINE>
<tns:INVUSELINE>
<tns:FROMSTORELOC>10TOC</tns:FROMSTORELOC>
<tns:INVUSELINENUM>2</tns:INVUSELINENUM>
<tns:ITEMNUM>0074255</tns:ITEMNUM>
<tns:INVRESERVE action="Add">
<tns:ACTUALQTY>0</tns:ACTUALQTY>
<tns:EXTERNALREFID>MSR0144234</tns:EXTERNALREFID>
<tns:ITEMNUM>0074255</tns:ITEMNUM>
</tns:INVRESERVE>
</tns:INVUSELINE>
<tns:INVUSELINE>
<tns:FROMSTORELOC>10TOC</tns:FROMSTORELOC>
<tns:INVUSELINENUM>3</tns:INVUSELINENUM>
<tns:ITEMNUM>0174400</tns:ITEMNUM>
<tns:INVRESERVE action="Add">
<tns:ACTUALQTY>0</tns:ACTUALQTY>
<tns:EXTERNALREFID>MSR0144234</tns:EXTERNALREFID>
<tns:ITEMNUM>0174400</tns:ITEMNUM>
</tns:INVRESERVE>
</tns:INVUSELINE>
</tns:INVUSE>
<tns:INVUSE>
<tns:AUTOCREATED>TL47695</tns:AUTOCREATED>
<tns:DESCRIPTION>MSR:MSR0144235 3101100028</tns:DESCRIPTION>
<tns:ZXQMSRNUM>MSR0144235</tns:ZXQMSRNUM>
<tns:INVUSELINE>
<tns:FROMSTORELOC>10TOC</tns:FROMSTORELOC>
<tns:INVUSELINENUM>1</tns:INVUSELINENUM>
<tns:ITEMNUM>0085400</tns:ITEMNUM>
<tns:INVRESERVE action="Add">
<tns:ACTUALQTY>0</tns:ACTUALQTY>
<tns:EXTERNALREFID>MSR0144235</tns:EXTERNALREFID>
<tns:ITEMNUM>0085400</tns:ITEMNUM>
</tns:INVRESERVE>
</tns:INVUSELINE>
<tns:INVUSELINE>
<tns:FROMSTORELOC>10TOC</tns:FROMSTORELOC>
<tns:INVUSELINENUM>2</tns:INVUSELINENUM>
<tns:ITEMNUM>0162801</tns:ITEMNUM>
<tns:INVRESERVE action="Add">
<tns:ACTUALQTY>0</tns:ACTUALQTY>
<tns:EXTERNALREFID>MSR0144235</tns:EXTERNALREFID>
<tns:ITEMNUM>0162801</tns:ITEMNUM>
</tns:INVRESERVE>
</tns:INVUSELINE>
<tns:INVUSELINE>
<tns:FROMSTORELOC>10TOC</tns:FROMSTORELOC>
<tns:INVUSELINENUM>3</tns:INVUSELINENUM>
<tns:ITEMNUM>0171400</tns:ITEMNUM>
<tns:INVRESERVE action="Add">
<tns:ACTUALQTY>0</tns:ACTUALQTY>
<tns:EXTERNALREFID>MSR0144235</tns:EXTERNALREFID>
<tns:ITEMNUM>0171400</tns:ITEMNUM>
</tns:INVRESERVE>
</tns:INVUSELINE>
</tns:INVUSE>
<tns:INVUSE>
<tns:AUTOCREATED>TL47695</tns:AUTOCREATED>
<tns:DESCRIPTION>MSR:MSR0144236 3101100028</tns:DESCRIPTION>
<tns:ZXQMSRNUM>MSR0144236</tns:ZXQMSRNUM>
<tns:INVUSELINE>
<tns:FROMSTORELOC>10TOC</tns:FROMSTORELOC>
<tns:INVUSELINENUM>1</tns:INVUSELINENUM>
<tns:ITEMNUM>0085400</tns:ITEMNUM>
<tns:INVRESERVE action="Add">
<tns:ACTUALQTY>0</tns:ACTUALQTY>
<tns:EXTERNALREFID>MSR0144236</tns:EXTERNALREFID>
<tns:ITEMNUM>0085400</tns:ITEMNUM>
</tns:INVRESERVE>
</tns:INVUSELINE>
<tns:INVUSELINE>
<tns:FROMSTORELOC>10TOC</tns:FROMSTORELOC>
<tns:INVUSELINENUM>2</tns:INVUSELINENUM>
<tns:ITEMNUM>0110900</tns:ITEMNUM>
<tns:INVRESERVE action="Add">
<tns:ACTUALQTY>0</tns:ACTUALQTY>
<tns:EXTERNALREFID>MSR0144236</tns:EXTERNALREFID>
<tns:ITEMNUM>0110900</tns:ITEMNUM>
</tns:INVRESERVE>
</tns:INVUSELINE>
<tns:INVUSELINE>
<tns:FROMSTORELOC>10TOC</tns:FROMSTORELOC>
<tns:INVUSELINENUM>3</tns:INVUSELINENUM>
<tns:ITEMNUM>0114300</tns:ITEMNUM>
<tns:INVRESERVE action="Add">
<tns:ACTUALQTY>0</tns:ACTUALQTY>
<tns:EXTERNALREFID>MSR0144236</tns:EXTERNALREFID>
<tns:ITEMNUM>0114300</tns:ITEMNUM>
</tns:INVRESERVE>
</tns:INVUSELINE>
</tns:INVUSE>
对于一个小组来说,这是一个很好的案例吗?或者是否应该使用另一种操作来实现所需的结果。我也在寻找for-each-groups,也许我可以使用它。我可以在订单上分组。我猜是否应该将其转换为XSLT 2.0?
答案 0 :(得分:0)
我能够解决每个组的问题。这是我终于开始工作的解决方案的缩小版本。
<xsl:template match="/">
<tns:SyncZXQINVRESERVE>
<tns:ZXQINVRESERVESet>
<xsl:for-each-group select="/ns0:PsWeIni025StgCollection/ns0:PsWeIni025Stg" group-by="ns0:orderNo">
<tns:INVUSE>
<tns:AUTOCREATED>
<xsl:value-of select="ns0:origOprid"/>
</tns:AUTOCREATED>
<tns:CHANGEBY>
<xsl:value-of select="ns0:origOprid"/>
</tns:CHANGEBY>
<tns:CHANGEDATE>
<xsl:value-of select="ns0:demandDate"/>
</tns:CHANGEDATE>
<xsl:for-each select="current-group()">
<xsl:sort select="ns0:orderIntLineNo"/>
<xsl:variable name="action">
<xsl:choose>
<xsl:when test="ns0:cancelDttm != ''">Delete</xsl:when>
<xsl:when test="string-length(ns0:actionFlg)> 0 and ns0:actionFlg = 'A'">Add</xsl:when>
<xsl:otherwise>AddChange</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tns:INVUSELINE>
<tns:ACTUALDATE>
<xsl:value-of select="ns0:demandDate"/>
</tns:ACTUALDATE>
<tns:INVUSELINENUM>
<xsl:value-of select="ns0:orderIntLineNo"/>
</tns:INVUSELINENUM>
<tns:ITEMNUM>
<xsl:value-of select="ns0:invItemId"/>
</tns:ITEMNUM>
<tns:ITEMSETID>SHARE</tns:ITEMSETID>
<tns:LINETYPE>ITEM</tns:LINETYPE>
<tns:LOCATION>
<xsl:value-of select="ns0:businessUnit"/>
</tns:LOCATION>
<tns:QUANTITY>
<xsl:value-of select="ns0:qtyRequested"/>
</tns:QUANTITY>
<tns:USETYPE>ISSUE</tns:USETYPE>
<tns:INVRESERVE action="{$action}">
<tns:ACTUALQTY>0</tns:ACTUALQTY>
<tns:EXTERNALREFID>
<xsl:value-of select="ns0:orderNo"/>
</tns:EXTERNALREFID>
</tns:INVRESERVE>
</tns:INVUSELINE>
</xsl:for-each>
</tns:INVUSE>
</xsl:for-each-group>
</tns:ZXQINVRESERVESet>
</tns:SyncZXQINVRESERVE>
</xsl:template>
</xsl:stylesheet>