我的输入结构如下: 在Item之后,我们有delivery_Info段,它可以每个项目一个或多个,然后是另一个Item,然后是Delivery_Info。因此,我们将第一个项目及其后的Delivery_Info分组,然后将下一个项目及其后的Delivery_Info组。提供输入和输出结构以供更多了解。
DataSet
基数为1..n
EDI_Header
基数为1..n
Item
基数为1..n
Deliveryinfoset
基数1..1
Delivery_info
基数0..n
<?xml version="1.0" encoding="utf-8"?>
<ns:MM_FlatFile_CBOX_ORDRSP_Out xmlns:ns="urn:test:corp:pi:a:ecc:cbox:ordrsp:100">
<DataSet>
<EDI_Header>
<LineIdent>SIM</LineIdent>
<EDIPartnerNo>047866091</EDIPartnerNo>
<MessageType>ORDRSP01</MessageType>
<VersionNo>3A7V0</VersionNo>
<Mode>102</Mode>
</EDI_Header>
<Header>
<LineIdent>HO01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<CustomerOrderNo>0038283143</CustomerOrderNo>
<MessageFunction/>
<Reference1>6174625</Reference1>
<Reference2/>
<Reference3/>
<SoldToID>126919</SoldToID>
<Partner2>126919</Partner2>
<Partner3/>
<ShipToID>126919</ShipToID>
<ShipToName>XXXXX</ShipToName>
<ShipToAddress/>
<ShipToAddress2>XXXXX</ShipToAddress2>
<ShipToCity>XXXXX</ShipToCity>
<ShipToZIP>XXXXX</ShipToZIP>
<ShipToCountry>FI</ShipToCountry>
<CustContact>XXXXX</CustContact>
<CustContactTelNo>XXXXX</CustContactTelNo>
<TransportType>EUR</TransportType>
</Header>
<Item>
<LineIdent>PO01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1</LineItemNo>
<ActionCode>6</ActionCode>
<ItemNoCust>P380200</ItemNoCust>
<ItemNoSup>B39172B5364U410W 3</ItemNoSup>
<Quantity>D1L1</Quantity>
<Unit>PCE</Unit>
<Price>0.4000</Price>
<PriceType/>
<QuantityPriceUnit>1</QuantityPriceUnit>
<LineItemNoCust/>
</Item>
<Delivery_Info>
<LineIdent>TE01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1DI1</LineItemNo>
<Quantity>3000</Quantity>
<Unit>PCE</Unit>
<DelDateReq>20181130</DelDateReq>
<DelDate>20181212</DelDate>
<DateCode>C</DateCode>
<QuantityOrdered>3000</QuantityOrdered>
<DateCurrent>20181121</DateCurrent>
<SysVar/>
</Delivery_Info>
<Item>
<LineIdent>PO01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1</LineItemNo>
<ActionCode>6</ActionCode>
<ItemNoCust>P380200</ItemNoCust>
<ItemNoSup>B39172B5364U410W 3</ItemNoSup>
<Quantity>D1L1</Quantity>
<Unit>PCE</Unit>
<Price>0.4000</Price>
<PriceType/>
<QuantityPriceUnit>1</QuantityPriceUnit>
<LineItemNoCust/>
</Item>
<Delivery_Info>
<LineIdent>TE01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1DI1</LineItemNo>
<Quantity>3000</Quantity>
<Unit>PCE</Unit>
<DelDateReq>20181130</DelDateReq>
<DelDate>20181212</DelDate>
<DateCode>C</DateCode>
<QuantityOrdered>3000</QuantityOrdered>
<DateCurrent>20181121</DateCurrent>
<SysVar/>
</Delivery_Info>
</DataSet>
<DataSet>
<EDI_Header>
<LineIdent>SIM</LineIdent>
<EDIPartnerNo>047866091</EDIPartnerNo>
<MessageType>ORDRSP01</MessageType>
<VersionNo>3A7V0</VersionNo>
<Mode>102</Mode>
</EDI_Header>
<Header>
<LineIdent>HO01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<CustomerOrderNo>0038283143</CustomerOrderNo>
<MessageFunction/>
<Reference1>6174625</Reference1>
<Reference2/>
<Reference3/>
<SoldToID>126919</SoldToID>
<Partner2>126919</Partner2>
<Partner3/>
<ShipToID>126919</ShipToID>
<ShipToName>XXXXX</ShipToName>
<ShipToAddress/>
<ShipToAddress2>XXXXX</ShipToAddress2>
<ShipToCity>XXXXX</ShipToCity>
<ShipToZIP>XXXXX</ShipToZIP>
<ShipToCountry>FI</ShipToCountry>
<CustContact>XXXXX</CustContact>
<CustContactTelNo>XXXXX</CustContactTelNo>
<TransportType>EUR</TransportType>
</Header>
<Item>
<LineIdent>PO01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1</LineItemNo>
<ActionCode>6</ActionCode>
<ItemNoCust>P380200</ItemNoCust>
<ItemNoSup>B39172B5364U410W 3</ItemNoSup>
<Quantity>D1L1</Quantity>
<Unit>PCE</Unit>
<Price>0.4000</Price>
<PriceType/>
<QuantityPriceUnit>1</QuantityPriceUnit>
<LineItemNoCust/>
</Item>
<Delivery_Info>
<LineIdent>TE01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1DI1</LineItemNo>
<Quantity>3000</Quantity>
<Unit>PCE</Unit>
<DelDateReq>20181130</DelDateReq>
<DelDate>20181212</DelDate>
<DateCode>C</DateCode>
<QuantityOrdered>3000</QuantityOrdered>
<DateCurrent>20181121</DateCurrent>
<SysVar/>
</Delivery_Info>
<Delivery_Info>
<LineIdent>TE01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1DI1</LineItemNo>
<Quantity>3000</Quantity>
<Unit>PCE</Unit>
<DelDateReq>20181130</DelDateReq>
<DelDate>20181212</DelDate>
<DateCode>C</DateCode>
<QuantityOrdered>3000</QuantityOrdered>
<DateCurrent>20181121</DateCurrent>
<SysVar/>
</Delivery_Info>
<Delivery_Info>
<LineIdent>TE01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1DI1</LineItemNo>
<Quantity>3000</Quantity>
<Unit>PCE</Unit>
<DelDateReq>20181130</DelDateReq>
<DelDate>20181212</DelDate>
<DateCode>C</DateCode>
<QuantityOrdered>3000</QuantityOrdered>
<DateCurrent>20181121</DateCurrent>
<SysVar/>
</Delivery_Info>
</DataSet>
</ns:MM_FlatFile_CBOX_ORDRSP_Out>
目标结构应为->
<?xml version="1.0" encoding="utf-8"?>
<ns:MM_FlatFile_CBOX_ORDRSP_Out
xmlns:ns="urn:test:corp:pi:a:ecc:cbox:ordrsp:100">
<DataSet>
<EDI_Header>
<LineIdent>SIM</LineIdent>
<EDIPartnerNo>047866091</EDIPartnerNo>
<MessageType>ORDRSP01</MessageType>
<VersionNo>3A7V0</VersionNo>
<Mode>102</Mode>
</EDI_Header>
<Header>
<LineIdent>HO01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<CustomerOrderNo>0038283143</CustomerOrderNo>
<MessageFunction/>
<Reference1>6174625</Reference1>
<Reference2/>
<Reference3/>
<SoldToID>126919</SoldToID>
<Partner2>126919</Partner2>
<Partner3/>
<ShipToID>126919</ShipToID>
<ShipToName>XXXXX</ShipToName>
<ShipToAddress/>
<ShipToAddress2>XXXXX</ShipToAddress2>
<ShipToCity>XXXXX</ShipToCity>
<ShipToZIP>XXXXX</ShipToZIP>
<ShipToCountry>FI</ShipToCountry>
<CustContact>XXXXX</CustContact>
<CustContactTelNo>XXXXX</CustContactTelNo>
<TransportType>EUR</TransportType>
</Header>
<Item>
<LineIdent>PO01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1</LineItemNo>
<ActionCode>6</ActionCode>
<ItemNoCust>P380200</ItemNoCust>
<ItemNoSup>B39172B5364U410W 3</ItemNoSup>
<Quantity>D1L1</Quantity>
<Unit>PCE</Unit>
<Price>0.4000</Price>
<PriceType/>
<QuantityPriceUnit>1</QuantityPriceUnit>
<LineItemNoCust/>
<Deliveryinfoset>
<Delivery_Info>
<LineIdent>TE01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1DI1</LineItemNo>
<Quantity>3000</Quantity>
<Unit>PCE</Unit>
<DelDateReq>20181130</DelDateReq>
<DelDate>20181212</DelDate>
<DateCode>C</DateCode>
<QuantityOrdered>3000</QuantityOrdered>
<DateCurrent>20181121</DateCurrent>
<SysVar/>
</Delivery_Info>
</Deliveryinfoset>
</Item>
<Item>
<LineIdent>PO01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1</LineItemNo>
<ActionCode>6</ActionCode>
<ItemNoCust>P380200</ItemNoCust>
<ItemNoSup>B39172B5364U410W 3</ItemNoSup>
<Quantity>D1L1</Quantity>
<Unit>PCE</Unit>
<Price>0.4000</Price>
<PriceType/>
<QuantityPriceUnit>1</QuantityPriceUnit>
<LineItemNoCust/>
<Deliveryinfoset>
<Delivery_Info>
<LineIdent>TE01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1DI1</LineItemNo>
<Quantity>3000</Quantity>
<Unit>PCE</Unit>
<DelDateReq>20181130</DelDateReq>
<DelDate>20181212</DelDate>
<DateCode>C</DateCode>
<QuantityOrdered>3000</QuantityOrdered>
<DateCurrent>20181121</DateCurrent>
<SysVar/>
</Delivery_Info>
</Deliveryinfoset>
</Item>
</DataSet>
<DataSet>
<EDI_Header>
<LineIdent>SIM</LineIdent>
<EDIPartnerNo>047866091</EDIPartnerNo>
<MessageType>ORDRSP01</MessageType>
<VersionNo>3A7V0</VersionNo>
<Mode>102</Mode>
</EDI_Header>
<Header>
<LineIdent>HO01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<CustomerOrderNo>0038283143</CustomerOrderNo>
<MessageFunction/>
<Reference1>6174625</Reference1>
<Reference2/>
<Reference3/>
<SoldToID>126919</SoldToID>
<Partner2>126919</Partner2>
<Partner3/>
<ShipToID>126919</ShipToID>
<ShipToName>XXXXX</ShipToName>
<ShipToAddress/>
<ShipToAddress2>XXXXX</ShipToAddress2>
<ShipToCity>XXXXX</ShipToCity>
<ShipToZIP>XXXXX</ShipToZIP>
<ShipToCountry>FI</ShipToCountry>
<CustContact>XXXXX</CustContact>
<CustContactTelNo>XXXXX</CustContactTelNo>
<TransportType>EUR</TransportType>
</Header>
<Item>
<LineIdent>PO01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1</LineItemNo>
<ActionCode>6</ActionCode>
<ItemNoCust>P380200</ItemNoCust>
<ItemNoSup>B39172B5364U410W 3</ItemNoSup>
<Quantity>D1L1</Quantity>
<Unit>PCE</Unit>
<Price>0.4000</Price>
<PriceType/>
<QuantityPriceUnit>1</QuantityPriceUnit>
<LineItemNoCust/>
<Deliveryinfoset>
<Delivery_Info>
<LineIdent>TE01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1DI1</LineItemNo>
<Quantity>3000</Quantity>
<Unit>PCE</Unit>
<DelDateReq>20181130</DelDateReq>
<DelDate>20181212</DelDate>
<DateCode>C</DateCode>
<QuantityOrdered>3000</QuantityOrdered>
<DateCurrent>20181121</DateCurrent>
<SysVar/>
</Delivery_Info>
<Delivery_Info>
<LineIdent>TE01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1DI1</LineItemNo>
<Quantity>3000</Quantity>
<Unit>PCE</Unit>
<DelDateReq>20181130</DelDateReq>
<DelDate>20181212</DelDate>
<DateCode>C</DateCode>
<QuantityOrdered>3000</QuantityOrdered>
<DateCurrent>20181121</DateCurrent>
<SysVar/>
</Delivery_Info>
<Delivery_Info>
<LineIdent>TE01</LineIdent>
<SupplierOrderNo>6174625</SupplierOrderNo>
<LineItemNo>D1L1DI1</LineItemNo>
<Quantity>3000</Quantity>
<Unit>PCE</Unit>
<DelDateReq>20181130</DelDateReq>
<DelDate>20181212</DelDate>
<DateCode>C</DateCode>
<QuantityOrdered>3000</QuantityOrdered>
<DateCurrent>20181121</DateCurrent>
<SysVar/>
</Delivery_Info>
</Deliveryinfoset>
</Item>
</DataSet>
</ns:MM_FlatFile_CBOX_ORDRSP_Out>
我的XSLT代码在我们的交货信息中有多个项目时不起作用
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ns="urn:test:corp:pi:a:ecc:cbox:ordrsp:100" exclude-result-prefixes="ns">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<MM_FlatFile_CBOX_ORDRSP_Out>
<xsl:for-each select="/ns:MM_FlatFile_CBOX_ORDRSP_Out/DataSet">
<DataSet>
<EDI_Header>
<LineIdent>
<xsl:value-of select="./EDI_Header/LineIdent"/>
</LineIdent>
<EDIPartnerNo>
<xsl:value-of select="./EDI_Header/EDIPartnerNo"/>
</EDIPartnerNo>
<MessageType>
<xsl:value-of select="'ORDRSP01'"/>
</MessageType>
<VersionNo>
<xsl:value-of select="'3A7V0'"/>
</VersionNo>
<Mode>
<xsl:value-of select="'102'"/>
</Mode>
</EDI_Header>
<Header>
<LineIdent>
<xsl:value-of select="./Header/LineIdent"/>
</LineIdent>
<SupplierOrderNo>
<xsl:value-of select="./Header/SupplierOrderNo"/>
</SupplierOrderNo>
<CustomerOrderNo>
<xsl:value-of select="./Header/CustomerOrderNo"/>
</CustomerOrderNo>
<MessageFunction>
<xsl:value-of select="./Header/MessageFunction"/>
</MessageFunction>
<Reference1>
<xsl:value-of select="./Header/Reference1"/>
</Reference1>
<Reference2>
<xsl:value-of select="./Header/Reference2"/>
</Reference2>
<Reference3>
<xsl:value-of select="./Header/Reference3"/>
</Reference3>
<SoldToID>
<xsl:value-of select="./Header/SoldToID"/>
</SoldToID>
<Partner2>
<xsl:value-of select="./Header/Partner2"/>
</Partner2>
<Partner3>
<xsl:value-of select="./Header/Partner3"/>
</Partner3>
<ShipToID>
<xsl:value-of select="./Header/ShipToID"/>
</ShipToID>
<ShipToName>
<xsl:value-of select="./Header/ShipToName"/>
</ShipToName>
<ShipToAddress>
<xsl:value-of select="./Header/ShipToAddress"/>
</ShipToAddress>
<ShipToAddress2>
<xsl:value-of select="./Header/ShipToAddress2"/>
</ShipToAddress2>
<ShipToCity>
<xsl:value-of select="./Header/ShipToCity"/>
</ShipToCity>
<ShipToZIP>
<xsl:value-of select="./Header/ShipToZIP"/>
</ShipToZIP>
<ShipToCountry>
<xsl:value-of select="./Header/ShipToCountry"/>
</ShipToCountry>
<CustContact>
<xsl:value-of select="./Header/CustContact"/>
</CustContact>
<CustContactTelNo>
<xsl:value-of select="./Header/CustContactTelNo"/>
</CustContactTelNo>
<TransportType>
<xsl:value-of select="./Header/TransportType"/>
</TransportType>
</Header>
<xsl:for-each select="./Item">
<Item>
<LineIdent>
<xsl:value-of select="./LineIdent"/>
</LineIdent>
<SupplierOrderNo>
<xsl:value-of select="./SupplierOrderNo"/>
</SupplierOrderNo>
<LineItemNo>
<xsl:value-of select="./LineItemNo"/>
</LineItemNo>
<ActionCode>
<xsl:value-of select="./ActionCode"/>
</ActionCode>
<ItemNoCust>
<xsl:value-of select="./ItemNoCust"/>
</ItemNoCust>
<ItemNoSup>
<xsl:value-of select="./ItemNoSup"/>
</ItemNoSup>
<Quantity>
<xsl:value-of select="./Quantity"/>
</Quantity>
<Unit>
<xsl:value-of select="./Unit"/>
</Unit>
<Price>
<xsl:value-of select="./Price"/>
</Price>
<PriceType>
<xsl:value-of select="./PriceType"/>
</PriceType>
<QuantityPriceUnit>
<xsl:value-of select="./QuantityPriceUnit"/>
</QuantityPriceUnit>
<LineItemNoCust>
<xsl:value-of select="./LineItemNoCust"/>
</LineItemNoCust>
<xsl:for-each select="../Delivery_Info">
<DeliveryInfoSet>
<Delivery_Info>
<LineIdent>
<xsl:value-of select="./LineIdent"/>
</LineIdent>
<SupplierOrderNo>
<xsl:value-of select="./SupplierOrderNo"/>
</SupplierOrderNo>
<LineItemNo>
<xsl:value-of select="./LineItemNo"/>
</LineItemNo>
<Quantity>
<xsl:value-of select="./Quantity"/>
</Quantity>
<Unit>
<xsl:value-of select="./Unit"/>
</Unit>
<DelDateReq>
<xsl:value-of select="./DelDateReq"/>
</DelDateReq>
<DelDate>
<xsl:value-of select="./DelDate"/>
</DelDate>
<DateCode>
<xsl:value-of select="./DateCode"/>
</DateCode>
<QuantityOrdered>
<xsl:value-of select="./QuantityOrdered"/>
</QuantityOrdered>
<DateCurrent>
<xsl:value-of select="./DateCurrent"/>
</DateCurrent>
<SysVar>
<xsl:value-of select="./SysVar"/>
</SysVar>
</Delivery_Info>
</DeliveryInfoSet>
</xsl:for-each>
</Item>
</xsl:for-each>
</DataSet>
</xsl:for-each>
</MM_FlatFile_CBOX_ORDRSP_Out>
</xsl:template>
</xsl:stylesheet>
谢谢
我可以要求你们在这一要求上为我提供帮助
答案 0 :(得分:0)
给出格式良好的(!)输入,例如:
XML
<Root>
<Header>
<Header_No>XXX</Header_No>
</Header>
<Item>
<Item_No>1</Item_No>
<Price>XXX</Price>
</Item>
<Delivery_Info>
<Delivery_no>101</Delivery_no>
<Delivery_Date>XXXXX</Delivery_Date>
</Delivery_Info>
<Delivery_Info>
<Delivery_no>102</Delivery_no>
<Delivery_Date>XXXXX</Delivery_Date>
</Delivery_Info>
<Delivery_Info>
<Delivery_no>103</Delivery_no>
<Delivery_Date>XXXXX</Delivery_Date>
</Delivery_Info>
<Item>
<Item_No>2</Item_No>
<Price>XXX</Price>
</Item>
<Delivery_Info>
<Delivery_no>201</Delivery_no>
<Delivery_Date>XXXXX</Delivery_Date>
</Delivery_Info>
<Delivery_Info>
<Delivery_no>202</Delivery_no>
<Delivery_Date>XXXXX</Delivery_Date>
</Delivery_Info>
</Root>
以下样式表:
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="delivery" match="Delivery_Info" use="generate-id(preceding-sibling::Item[1])" />
<xsl:template match="/Root">
<xsl:copy>
<xsl:copy-of select="Header"/>
<xsl:for-each select="Item">
<xsl:copy>
<xsl:copy-of select="*"/>
<Deliveryinfoset>
<xsl:copy-of select="key('delivery', generate-id())"/>
</Deliveryinfoset>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
将返回:
结果
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Header>
<Header_No>XXX</Header_No>
</Header>
<Item>
<Item_No>1</Item_No>
<Price>XXX</Price>
<Deliveryinfoset>
<Delivery_Info>
<Delivery_no>101</Delivery_no>
<Delivery_Date>XXXXX</Delivery_Date>
</Delivery_Info>
<Delivery_Info>
<Delivery_no>102</Delivery_no>
<Delivery_Date>XXXXX</Delivery_Date>
</Delivery_Info>
<Delivery_Info>
<Delivery_no>103</Delivery_no>
<Delivery_Date>XXXXX</Delivery_Date>
</Delivery_Info>
</Deliveryinfoset>
</Item>
<Item>
<Item_No>2</Item_No>
<Price>XXX</Price>
<Deliveryinfoset>
<Delivery_Info>
<Delivery_no>201</Delivery_no>
<Delivery_Date>XXXXX</Delivery_Date>
</Delivery_Info>
<Delivery_Info>
<Delivery_no>202</Delivery_no>
<Delivery_Date>XXXXX</Delivery_Date>
</Delivery_Info>
</Deliveryinfoset>
</Item>
</Root>