我是如何使用XSLT的新手。任何人都可以提供有关如何使用XSLT将以下xml转换为另一种类型的xml输出的任何建议/输入/注释,如下所述 -
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<ShowShipment>
<ApplicationArea>
<Sender>
<LogicalID>012345678</LogicalID>
</Sender>
<ReceiverId>ABCDEF</ReceiverId>
</ApplicationArea>
<DataArea>
<Show/>
<Shipment>
<ShipmentHeader>
<DocumentID>
<ID>1700000494-17CCCCC</ID>
</DocumentID>
<DocumentReference type="OrderSource" >
<Type>0001</Type>
</DocumentReference>
<DocumentReference type="BillOfLading" >
<DocumentID>
<ID>17CCCCC</ID>
</DocumentID>
</DocumentReference>
<ActualShipDateTime>2017-03-29T19:18:01-05:00</ActualShipDateTime>
<Truck>
<ID>01</ID>
</Truck>
<TrailerNumber>U280</TrailerNumber>
</ShipmentHeader>
<ShipmentOrder>
<ShipmentHeader>
<DocumentReference type="OMSOrderInfo" >
<SalesOrderReference>
<DocumentID>
<ID>17CCCCC</ID>
</DocumentID>
<ReleaseNumber>1</ReleaseNumber>
</SalesOrderReference>
</DocumentReference>
<DocumentReference type="LegacyOrderNumber" >
<SalesOrderReference>
<DocumentID>
<ID>17CCCCC</ID>
</DocumentID>
</SalesOrderReference>
</DocumentReference>
<DocumentReference type="CustomerReference" >
<PurchaseOrderReference>
<AlternateDocumentID>
<ID schemeName="EDI" >Purchasing Dept</ID>
</AlternateDocumentID>
</PurchaseOrderReference>
</DocumentReference>
<DocumentReference type="ConsumerPOInfo" />
<DocumentReference type="DealerPO" >
<PurchaseOrderReference>
<DocumentID>
<ID>10000000</ID>
</DocumentID>
</PurchaseOrderReference>
</DocumentReference>
<HazardousMaterialIndicator>false</HazardousMaterialIndicator>
<MultiCartonIndicator>true</MultiCartonIndicator>
<PrimaryCustomerIndicator>false</PrimaryCustomerIndicator>
<QACheckIndicator>false</QACheckIndicator>
</ShipmentHeader>
<ShipmentUnit>
<TrackingID>1Z00000000000001</TrackingID>
<ContainerID>170111111113</ContainerID>
<DeclaredValueAmount currencyID="USD" >0</DeclaredValueAmount>
<ShipmentDateTime>2017-03-29T19:15:19</ShipmentDateTime>
<NetWeightMeasure unitCode="LB" >7</NetWeightMeasure>
<GrossWeightMeasure unitCode="LB" >7</GrossWeightMeasure>
<FreightChargeAmount currencyID="USD" >0</FreightChargeAmount>
<LoadingDateTime>2017-03-29T09:37:04</LoadingDateTime>
<LoadingWeightMeasure unitCode="LB" >7</LoadingWeightMeasure>
<Dimensions>
<WidthMeasure unitCode="IN" >7.75</WidthMeasure>
<LengthMeasure unitCode="IN" >4.5</LengthMeasure>
<HeightMeasure unitCode="IN" >11.56</HeightMeasure>
</Dimensions>
<ShipmentUnitContainer>
<ContainerID>ABCD</ContainerID>
</ShipmentUnitContainer>
<SSCCode>000005835235</SSCCode>
<ShipCode>Y</ShipCode>
<CODAmount currencyID="USD" >0</CODAmount>
<ShipmentUnitItem>
<ItemID>
<ID>900133</ID>
<RevisionID>900133</RevisionID>
<VariationID>900133</VariationID>
</ItemID>
<UPCID>00000000000000</UPCID>
<CountryOfOriginCode>US</CountryOfOriginCode>
<OrderQuantity>5</OrderQuantity>
<ShippedQuantity unitCode="CT" >1</ShippedQuantity>
<PurchaseOrderReference>
<LineNumber>00001</LineNumber>
</PurchaseOrderReference>
<SalesOrderReference>
<LineNumber>1</LineNumber>
<ScheduleLineNumber>1</ScheduleLineNumber>
<SubLineNumber>1</SubLineNumber>
</SalesOrderReference>
<UPCRetailID>814127852</UPCRetailID>
<ConfirmedQuantity>5</ConfirmedQuantity>
<CancelledQuantity>0</CancelledQuantity>
<ItemTypeCode>1</ItemTypeCode>
<ItemWeight unitCode="LB" >6.33</ItemWeight>
<HazardousMaterialIndicator>false</HazardousMaterialIndicator>
<SerialNumberIndicator>false</SerialNumberIndicator>
<CartonLineNumber>1</CartonLineNumber>
<PackingSlip>
<LineText sequence="1" >EDI|00001|20AN17|5|EA||</LineText>
</PackingSlip>
<PassThruData qualifier="II" >00001</PassThruData>
<PassThruData qualifier="KK" >5</PassThruData>
<PassThruData qualifier="JJ" >EA</PassThruData>
</ShipmentUnitItem>
<ShipmentUnitItem>
<ItemID>
<ID>900100</ID>
<RevisionID>900100</RevisionID>
<VariationID>900100</VariationID>
</ItemID>
<UPCID>00000000000000</UPCID>
<CountryOfOriginCode>US</CountryOfOriginCode>
<OrderQuantity>5</OrderQuantity>
<ShippedQuantity unitCode="CT" >1</ShippedQuantity>
<PurchaseOrderReference>
<LineNumber>00001</LineNumber>
</PurchaseOrderReference>
<SalesOrderReference>
<LineNumber>1</LineNumber>
<ScheduleLineNumber>1</ScheduleLineNumber>
<SubLineNumber>1</SubLineNumber>
</SalesOrderReference>
<UPCRetailID>814120000</UPCRetailID>
<ConfirmedQuantity>5</ConfirmedQuantity>
<CancelledQuantity>0</CancelledQuantity>
<ItemTypeCode>1</ItemTypeCode>
<ItemWeight unitCode="LB" >6.33</ItemWeight>
<HazardousMaterialIndicator>false</HazardousMaterialIndicator>
<SerialNumberIndicator>false</SerialNumberIndicator>
<CartonLineNumber>1</CartonLineNumber>
<PackingSlip>
<LineText sequence="1" >EDI|00001|20AN00|5|EA||</LineText>
</PackingSlip>
<PassThruData qualifier="II" >00001</PassThruData>
<PassThruData qualifier="KK" >5</PassThruData>
<PassThruData qualifier="JJ" >EA</PassThruData>
</ShipmentUnitItem>
<DropShipIndicator>BBB</DropShipIndicator>
<BulkItemLocation>301</BulkItemLocation>
<ListBaseFreightAmount currencyID="USD" >0</ListBaseFreightAmount>
</ShipmentUnit>
</ShipmentOrder>
</Shipment>
</DataArea>
</ShowShipment>
我需要输出如下 -
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<ShowShipment>
<ApplicationArea>
<Sender>
<LogicalID>012345678</LogicalID>
</Sender>
<ReceiverId>ABCDEF</ReceiverId>
</ApplicationArea>
<DataArea>
<Show/>
<Shipment>
<ShipmentHeader>
<DocumentID>
<ID>1700000494-17CCCCC</ID>
</DocumentID>
<DocumentReference type="OrderSource" >
<Type>0001</Type>
</DocumentReference>
<DocumentReference type="BillOfLading" >
<DocumentID>
<ID>17CCCCC</ID>
</DocumentID>
</DocumentReference>
<ActualShipDateTime>2017-03-29T19:18:01-05:00</ActualShipDateTime>
<Truck>
<ID>01</ID>
</Truck>
<TrailerNumber>U280</TrailerNumber>
</ShipmentHeader>
<ShipmentOrder>
<ShipmentHeader>
<DocumentReference type="OMSOrderInfo" >
<SalesOrderReference>
<DocumentID>
<ID>17CCCCC</ID>
</DocumentID>
<ReleaseNumber>1</ReleaseNumber>
</SalesOrderReference>
</DocumentReference>
<DocumentReference type="LegacyOrderNumber" >
<SalesOrderReference>
<DocumentID>
<ID>17CCCCC</ID>
</DocumentID>
</SalesOrderReference>
</DocumentReference>
<DocumentReference type="CustomerReference" >
<PurchaseOrderReference>
<AlternateDocumentID>
<ID schemeName="EDI" >Purchasing Dept</ID>
</AlternateDocumentID>
</PurchaseOrderReference>
</DocumentReference>
<DocumentReference type="ConsumerPOInfo" />
<DocumentReference type="DealerPO" >
<PurchaseOrderReference>
<DocumentID>
<ID>10000000</ID>
</DocumentID>
</PurchaseOrderReference>
</DocumentReference>
<HazardousMaterialIndicator>false</HazardousMaterialIndicator>
<MultiCartonIndicator>true</MultiCartonIndicator>
<PrimaryCustomerIndicator>false</PrimaryCustomerIndicator>
<QACheckIndicator>false</QACheckIndicator>
</ShipmentHeader>
<ShipmentUnit>
<TrackingID>1Z00000000000001</TrackingID>
<ContainerID>170111111113</ContainerID>
<DeclaredValueAmount currencyID="USD" >0</DeclaredValueAmount>
<ShipmentDateTime>2017-03-29T19:15:19</ShipmentDateTime>
<NetWeightMeasure unitCode="LB" >7</NetWeightMeasure>
<GrossWeightMeasure unitCode="LB" >7</GrossWeightMeasure>
<FreightChargeAmount currencyID="USD" >0</FreightChargeAmount>
<LoadingDateTime>2017-03-29T09:37:04</LoadingDateTime>
<LoadingWeightMeasure unitCode="LB" >7</LoadingWeightMeasure>
<Dimensions>
<WidthMeasure unitCode="IN" >7.75</WidthMeasure>
<LengthMeasure unitCode="IN" >4.5</LengthMeasure>
<HeightMeasure unitCode="IN" >11.56</HeightMeasure>
</Dimensions>
<ShipmentUnitContainer>
<ContainerID>ABCD</ContainerID>
</ShipmentUnitContainer>
<SSCCode>000005835235</SSCCode>
<ShipCode>Y</ShipCode>
<CODAmount currencyID="USD" >0</CODAmount>
<ShipmentUnitItem>
<ItemID>
<ID>900133</ID>
<RevisionID>900133</RevisionID>
<VariationID>900133</VariationID>
</ItemID>
<UPCID>00000000000000</UPCID>
<CountryOfOriginCode>US</CountryOfOriginCode>
<OrderQuantity>5</OrderQuantity>
<ShippedQuantity unitCode="CT" >1</ShippedQuantity>
<PurchaseOrderReference>
<LineNumber>00001</LineNumber>
</PurchaseOrderReference>
<SalesOrderReference>
<LineNumber>1</LineNumber>
<ScheduleLineNumber>1</ScheduleLineNumber>
<SubLineNumber>1</SubLineNumber>
</SalesOrderReference>
<UPCRetailID>814127852</UPCRetailID>
<ConfirmedQuantity>5</ConfirmedQuantity>
<CancelledQuantity>0</CancelledQuantity>
<ItemTypeCode>1</ItemTypeCode>
<ItemWeight unitCode="LB" >6.33</ItemWeight>
<HazardousMaterialIndicator>false</HazardousMaterialIndicator>
<SerialNumberIndicator>false</SerialNumberIndicator>
<CartonLineNumber>1</CartonLineNumber>
<PackingSlip>
<LineText sequence="1" >EDI|00001|20AN17|5|EA||</LineText>
</PackingSlip>
<PassThruData qualifier="II" >00001</PassThruData>
<PassThruData qualifier="KK" >5</PassThruData>
<PassThruData qualifier="JJ" >EA</PassThruData>
</ShipmentUnitItem>
<DropShipIndicator>BBB</DropShipIndicator>
<BulkItemLocation>301</BulkItemLocation>
<ListBaseFreightAmount currencyID="USD" >0</ListBaseFreightAmount>
</ShipmentUnit>
<ShipmentUnit>
<TrackingID>1Z00000000000001</TrackingID>
<ContainerID>170111111113</ContainerID>
<DeclaredValueAmount currencyID="USD" >0</DeclaredValueAmount>
<ShipmentDateTime>2017-03-29T19:15:19</ShipmentDateTime>
<NetWeightMeasure unitCode="LB" >7</NetWeightMeasure>
<GrossWeightMeasure unitCode="LB" >7</GrossWeightMeasure>
<FreightChargeAmount currencyID="USD" >0</FreightChargeAmount>
<LoadingDateTime>2017-03-29T09:37:04</LoadingDateTime>
<LoadingWeightMeasure unitCode="LB" >7</LoadingWeightMeasure>
<Dimensions>
<WidthMeasure unitCode="IN" >7.75</WidthMeasure>
<LengthMeasure unitCode="IN" >4.5</LengthMeasure>
<HeightMeasure unitCode="IN" >11.56</HeightMeasure>
</Dimensions>
<ShipmentUnitContainer>
<ContainerID>ABCD</ContainerID>
</ShipmentUnitContainer>
<SSCCode>000005835235</SSCCode>
<ShipCode>Y</ShipCode>
<CODAmount currencyID="USD" >0</CODAmount>
<ShipmentUnitItem>
<ItemID>
<ID>900100</ID>
<RevisionID>900100</RevisionID>
<VariationID>900100</VariationID>
</ItemID>
<UPCID>00000000000000</UPCID>
<CountryOfOriginCode>US</CountryOfOriginCode>
<OrderQuantity>5</OrderQuantity>
<ShippedQuantity unitCode="CT" >1</ShippedQuantity>
<PurchaseOrderReference>
<LineNumber>00001</LineNumber>
</PurchaseOrderReference>
<SalesOrderReference>
<LineNumber>1</LineNumber>
<ScheduleLineNumber>1</ScheduleLineNumber>
<SubLineNumber>1</SubLineNumber>
</SalesOrderReference>
<UPCRetailID>814120000</UPCRetailID>
<ConfirmedQuantity>5</ConfirmedQuantity>
<CancelledQuantity>0</CancelledQuantity>
<ItemTypeCode>1</ItemTypeCode>
<ItemWeight unitCode="LB" >6.33</ItemWeight>
<HazardousMaterialIndicator>false</HazardousMaterialIndicator>
<SerialNumberIndicator>false</SerialNumberIndicator>
<CartonLineNumber>1</CartonLineNumber>
<PackingSlip>
<LineText sequence="1" >EDI|00001|20AN00|5|EA||</LineText>
</PackingSlip>
<PassThruData qualifier="II" >00001</PassThruData>
<PassThruData qualifier="KK" >5</PassThruData>
<PassThruData qualifier="JJ" >EA</PassThruData>
</ShipmentUnitItem>
<DropShipIndicator>BBB</DropShipIndicator>
<BulkItemLocation>301</BulkItemLocation>
<ListBaseFreightAmount currencyID="USD" >0</ListBaseFreightAmount>
</ShipmentUnit>
</ShipmentOrder>
</Shipment>
</DataArea>
</ShowShipment>
XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- Need one <ShipmentUnit> for one <ShipmentUnitItem> -->
<xsl:template match="ShipmentUnitItem">
<ShipmentUnit>
<xsl:copy-of select="../TrackingID|../ContainerID|../DeclaredValueAmount|../hipmentDateTime|../NetWeightMeasure|../GrossWeightMeasure|../FreightChargeAmount|../LoadingDateTime|../LoadingWeightMeasure|../Dimensions|../ShipmentUnitContainer|../SSCCode|../ShipCode|../CODAmount|../DropShipIndicator|../BulkItemLocation|../ListBaseFreightAmount|." />
</ShipmentUnit>
</xsl:template>
</xsl:stylesheet>
我无法使用上述XSL为每个ShipmentUnitItem填充ShipmentUnit。我通过额外的ShipmentUnit获得如下输出。
<ShowShipment>
<ApplicationArea>
<Sender>
<LogicalID>012345678</LogicalID>
</Sender>
<ReceiverId>ABCDEF</ReceiverId>
</ApplicationArea>
<DataArea>
<Show/>
<Shipment>
<ShipmentHeader>
<DocumentID>
<ID>1700000494-17CCCCC</ID>
</DocumentID>
<DocumentReference type="OrderSource">
<Type>0001</Type>
</DocumentReference>
<DocumentReference type="BillOfLading">
<DocumentID>
<ID>17CCCCC</ID>
</DocumentID>
</DocumentReference>
<ActualShipDateTime>2017-03-29T19:18:01-05:00</ActualShipDateTime>
<Truck>
<ID>01</ID>
</Truck>
<TrailerNumber>U280</TrailerNumber>
</ShipmentHeader>
<ShipmentOrder>
<ShipmentHeader>
<DocumentReference type="OMSOrderInfo">
<SalesOrderReference>
<DocumentID>
<ID>17CCCCC</ID>
</DocumentID>
<ReleaseNumber>1</ReleaseNumber>
</SalesOrderReference>
</DocumentReference>
<DocumentReference type="LegacyOrderNumber">
<SalesOrderReference>
<DocumentID>
<ID>17CCCCC</ID>
</DocumentID>
</SalesOrderReference>
</DocumentReference>
<DocumentReference type="CustomerReference">
<PurchaseOrderReference>
<AlternateDocumentID>
<ID schemeName="EDI">Purchasing Dept</ID>
</AlternateDocumentID>
</PurchaseOrderReference>
</DocumentReference>
<DocumentReference type="ConsumerPOInfo"/>
<DocumentReference type="DealerPO">
<PurchaseOrderReference>
<DocumentID>
<ID>10000000</ID>
</DocumentID>
</PurchaseOrderReference>
</DocumentReference>
<HazardousMaterialIndicator>false</HazardousMaterialIndicator>
<MultiCartonIndicator>true</MultiCartonIndicator>
<PrimaryCustomerIndicator>false</PrimaryCustomerIndicator>
<QACheckIndicator>false</QACheckIndicator>
</ShipmentHeader>
<ShipmentUnit>
<TrackingID>1Z00000000000001</TrackingID>
<ContainerID>170111111113</ContainerID>
<DeclaredValueAmount currencyID="USD">0</DeclaredValueAmount>
<ShipmentDateTime>2017-03-29T19:15:19</ShipmentDateTime>
<NetWeightMeasure unitCode="LB">7</NetWeightMeasure>
<GrossWeightMeasure unitCode="LB">7</GrossWeightMeasure>
<FreightChargeAmount currencyID="USD">0</FreightChargeAmount>
<LoadingDateTime>2017-03-29T09:37:04</LoadingDateTime>
<LoadingWeightMeasure unitCode="LB">7</LoadingWeightMeasure>
<Dimensions>
<WidthMeasure unitCode="IN">7.75</WidthMeasure>
<LengthMeasure unitCode="IN">4.5</LengthMeasure>
<HeightMeasure unitCode="IN">11.56</HeightMeasure>
</Dimensions>
<ShipmentUnitContainer>
<ContainerID>ABCD</ContainerID>
</ShipmentUnitContainer>
<SSCCode>000005835235</SSCCode>
<ShipCode>Y</ShipCode>
<CODAmount currencyID="USD">0</CODAmount>
<ShipmentUnit>
<TrackingID>1Z00000000000001</TrackingID>
<ContainerID>170111111113</ContainerID>
<DeclaredValueAmount currencyID="USD">0</DeclaredValueAmount>
<NetWeightMeasure unitCode="LB">7</NetWeightMeasure>
<GrossWeightMeasure unitCode="LB">7</GrossWeightMeasure>
<FreightChargeAmount currencyID="USD">0</FreightChargeAmount>
<LoadingDateTime>2017-03-29T09:37:04</LoadingDateTime>
<LoadingWeightMeasure unitCode="LB">7</LoadingWeightMeasure>
<Dimensions>
<WidthMeasure unitCode="IN">7.75</WidthMeasure>
<LengthMeasure unitCode="IN">4.5</LengthMeasure>
<HeightMeasure unitCode="IN">11.56</HeightMeasure>
</Dimensions>
<ShipmentUnitContainer>
<ContainerID>ABCD</ContainerID>
</ShipmentUnitContainer>
<SSCCode>000005835235</SSCCode>
<ShipCode>Y</ShipCode>
<CODAmount currencyID="USD">0</CODAmount>
<ShipmentUnitItem>
<ItemID>
<ID>900133</ID>
<RevisionID>900133</RevisionID>
<VariationID>900133</VariationID>
</ItemID>
<UPCID>00000000000000</UPCID>
<CountryOfOriginCode>US</CountryOfOriginCode>
<OrderQuantity>5</OrderQuantity>
<ShippedQuantity unitCode="CT">1</ShippedQuantity>
<PurchaseOrderReference>
<LineNumber>00001</LineNumber>
</PurchaseOrderReference>
<SalesOrderReference>
<LineNumber>1</LineNumber>
<ScheduleLineNumber>1</ScheduleLineNumber>
<SubLineNumber>1</SubLineNumber>
</SalesOrderReference>
<UPCRetailID>814127852</UPCRetailID>
<ConfirmedQuantity>5</ConfirmedQuantity>
<CancelledQuantity>0</CancelledQuantity>
<ItemTypeCode>1</ItemTypeCode>
<ItemWeight unitCode="LB">6.33</ItemWeight>
<HazardousMaterialIndicator>false</HazardousMaterialIndicator>
<SerialNumberIndicator>false</SerialNumberIndicator>
<CartonLineNumber>1</CartonLineNumber>
<PackingSlip>
<LineText sequence="1">EDI|00001|20AN17|5|EA||</LineText>
</PackingSlip>
<PassThruData qualifier="II">00001</PassThruData>
<PassThruData qualifier="KK">5</PassThruData>
<PassThruData qualifier="JJ">EA</PassThruData>
</ShipmentUnitItem>
<DropShipIndicator>BBB</DropShipIndicator>
<BulkItemLocation>301</BulkItemLocation>
<ListBaseFreightAmount currencyID="USD">0</ListBaseFreightAmount>
</ShipmentUnit>
<ShipmentUnit>
<TrackingID>1Z00000000000001</TrackingID>
<ContainerID>170111111113</ContainerID>
<DeclaredValueAmount currencyID="USD">0</DeclaredValueAmount>
<NetWeightMeasure unitCode="LB">7</NetWeightMeasure>
<GrossWeightMeasure unitCode="LB">7</GrossWeightMeasure>
<FreightChargeAmount currencyID="USD">0</FreightChargeAmount>
<LoadingDateTime>2017-03-29T09:37:04</LoadingDateTime>
<LoadingWeightMeasure unitCode="LB">7</LoadingWeightMeasure>
<Dimensions>
<WidthMeasure unitCode="IN">7.75</WidthMeasure>
<LengthMeasure unitCode="IN">4.5</LengthMeasure>
<HeightMeasure unitCode="IN">11.56</HeightMeasure>
</Dimensions>
<ShipmentUnitContainer>
<ContainerID>ABCD</ContainerID>
</ShipmentUnitContainer>
<SSCCode>000005835235</SSCCode>
<ShipCode>Y</ShipCode>
<CODAmount currencyID="USD">0</CODAmount>
<ShipmentUnitItem>
<ItemID>
<ID>900100</ID>
<RevisionID>900100</RevisionID>
<VariationID>900100</VariationID>
</ItemID>
<UPCID>00000000000000</UPCID>
<CountryOfOriginCode>US</CountryOfOriginCode>
<OrderQuantity>5</OrderQuantity>
<ShippedQuantity unitCode="CT">1</ShippedQuantity>
<PurchaseOrderReference>
<LineNumber>00001</LineNumber>
</PurchaseOrderReference>
<SalesOrderReference>
<LineNumber>1</LineNumber>
<ScheduleLineNumber>1</ScheduleLineNumber>
<SubLineNumber>1</SubLineNumber>
</SalesOrderReference>
<UPCRetailID>814120000</UPCRetailID>
<ConfirmedQuantity>5</ConfirmedQuantity>
<CancelledQuantity>0</CancelledQuantity>
<ItemTypeCode>1</ItemTypeCode>
<ItemWeight unitCode="LB">6.33</ItemWeight>
<HazardousMaterialIndicator>false</HazardousMaterialIndicator>
<SerialNumberIndicator>false</SerialNumberIndicator>
<CartonLineNumber>1</CartonLineNumber>
<PackingSlip>
<LineText sequence="1">EDI|00001|20AN00|5|EA||</LineText>
</PackingSlip>
<PassThruData qualifier="II">00001</PassThruData>
<PassThruData qualifier="KK">5</PassThruData>
<PassThruData qualifier="JJ">EA</PassThruData>
</ShipmentUnitItem>
<DropShipIndicator>BBB</DropShipIndicator>
<BulkItemLocation>301</BulkItemLocation>
<ListBaseFreightAmount currencyID="USD">0</ListBaseFreightAmount>
</ShipmentUnit>
<DropShipIndicator>BBB</DropShipIndicator>
<BulkItemLocation>301</BulkItemLocation>
<ListBaseFreightAmount currencyID="USD">0</ListBaseFreightAmount>
</ShipmentUnit>
</ShipmentOrder>
</Shipment>
</DataArea>
</ShowShipment>
新测试数据。
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<us:ShowShipment xmlns:us='http://www.ussco.com/oagis/0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:oa='http://www.openapplications.org/oagis/9' releaseID="1.0" systemEnvironmentCode="Production" languageCode="en-US" >
<us:ApplicationArea>
<oa:Sender>
<oa:LogicalID>012345678</oa:LogicalID>
</oa:Sender>
<us:ReceiverId>ABCDEF</us:ReceiverId>
</us:ApplicationArea>
<us:DataArea>
<oa:Show/>
<us:Shipment>
<us:ShipmentHeader>
<oa:DocumentID>
<oa:ID>1700000494-17CCCCC</oa:ID>
</oa:DocumentID>
<oa:DocumentReference type="OrderSource" >
<oa:Type>0001</oa:Type>
</oa:DocumentReference>
<oa:DocumentReference type="BillOfLading" >
<oa:DocumentID>
<oa:ID>17CCCCC</oa:ID>
</oa:DocumentID>
</oa:DocumentReference>
<oa:ActualShipDateTime>2017-03-29T19:18:01-05:00</oa:ActualShipDateTime>
<us:Truck>
<oa:ID>01</oa:ID>
</us:Truck>
<us:TrailerNumber>U280</us:TrailerNumber>
</us:ShipmentHeader>
<us:ShipmentOrder>
<us:ShipmentHeader>
<oa:DocumentReference type="OMSOrderInfo" >
<oa:SalesOrderReference>
<oa:DocumentID>
<oa:ID>17CCCCC</oa:ID>
</oa:DocumentID>
<oa:ReleaseNumber>1</oa:ReleaseNumber>
</oa:SalesOrderReference>
</oa:DocumentReference>
<us:HazardousMaterialIndicator>false</us:HazardousMaterialIndicator>
<us:MultiCartonIndicator>true</us:MultiCartonIndicator>
<us:PrimaryCustomerIndicator>false</us:PrimaryCustomerIndicator>
<us:QACheckIndicator>false</us:QACheckIndicator>
</us:ShipmentHeader>
<us:ShipmentUnit>
<oa:TrackingID>1Z00000000000001</oa:TrackingID>
<oa:ContainerID>170111111113</oa:ContainerID>
<oa:DeclaredValueAmount currencyID="USD" >0</oa:DeclaredValueAmount>
<oa:ShipmentDateTime>2017-03-29T19:15:19</oa:ShipmentDateTime>
<oa:NetWeightMeasure unitCode="LB" >7</oa:NetWeightMeasure>
<oa:Dimensions>
<oa:WidthMeasure unitCode="IN" >7.75</oa:WidthMeasure>
<oa:LengthMeasure unitCode="IN" >4.5</oa:LengthMeasure>
<oa:HeightMeasure unitCode="IN" >11.56</oa:HeightMeasure>
</oa:Dimensions>
<oa:ShipmentUnitContainer>
<oa:ContainerID>ABCD</oa:ContainerID>
</oa:ShipmentUnitContainer>
<us:SSCCode>000005835235</us:SSCCode>
<us:ShipCode>Y</us:ShipCode>
<us:CODAmount currencyID="USD" >0</us:CODAmount>
<us:ShipmentUnitItem>
<oa:ItemID>
<oa:ID>900133</oa:ID>
<oa:RevisionID>900133</oa:RevisionID>
<oa:VariationID>900133</oa:VariationID>
</oa:ItemID>
<oa:PurchaseOrderReference>
<oa:LineNumber>00001</oa:LineNumber>
</oa:PurchaseOrderReference>
<oa:SalesOrderReference>
<oa:LineNumber>1</oa:LineNumber>
<oa:ScheduleLineNumber>1</oa:ScheduleLineNumber>
<oa:SubLineNumber>1</oa:SubLineNumber>
</oa:SalesOrderReference>
<us:UPCRetailID>814127852</us:UPCRetailID>
<us:ItemWeight unitCode="LB" >6.33</us:ItemWeight>
<us:CartonLineNumber>1</us:CartonLineNumber>
<us:PackingSlip>
<us:LineText sequence="1" >EDI|00001|20AN17|5|EA||</us:LineText>
</us:PackingSlip>
<us:PassThruData qualifier="II" >00001</us:PassThruData>
<us:PassThruData qualifier="KK" >5</us:PassThruData>
<us:PassThruData qualifier="JJ" >EA</us:PassThruData>
</us:ShipmentUnitItem>
<us:ShipmentUnitItem>
<oa:ItemID>
<oa:ID>900100</oa:ID>
<oa:RevisionID>900100</oa:RevisionID>
<oa:VariationID>900100</oa:VariationID>
</oa:ItemID>
<oa:PurchaseOrderReference>
<oa:LineNumber>00001</oa:LineNumber>
</oa:PurchaseOrderReference>
<oa:SalesOrderReference>
<oa:LineNumber>1</oa:LineNumber>
<oa:ScheduleLineNumber>1</oa:ScheduleLineNumber>
<oa:SubLineNumber>1</oa:SubLineNumber>
</oa:SalesOrderReference>
<us:ItemWeight unitCode="LB" >6.33</us:ItemWeight>
<us:HazardousMaterialIndicator>false</us:HazardousMaterialIndicator>
<us:SerialNumberIndicator>false</us:SerialNumberIndicator>
<us:CartonLineNumber>1</us:CartonLineNumber>
<us:PackingSlip>
<us:LineText sequence="1" >EDI|00001|20AN00|5|EA||</us:LineText>
</us:PackingSlip>
<us:PassThruData qualifier="II" >00001</us:PassThruData>
<us:PassThruData qualifier="KK" >5</us:PassThruData>
<us:PassThruData qualifier="JJ" >EA</us:PassThruData>
</us:ShipmentUnitItem>
<us:DropShipIndicator>BBB</us:DropShipIndicator>
<us:BulkItemLocation>301</us:BulkItemLocation>
<us:ListBaseFreightAmount currencyID="USD" >0</us:ListBaseFreightAmount>
</us:ShipmentUnit>
</us:ShipmentOrder>
</us:Shipment>
</us:DataArea>
</us:ShowShipment>
提前致谢。
答案 0 :(得分:-1)
(重写问题后重写)
很明显,您的基本需求是每个ShipmentUnitItem
都在其自己的ShipmentUnit
父级中。这需要重新处理输入结构,其中一个ShipmentUnit
可能包含多个ShipmentUnitItem
个孩子。
在您的XSLT代码中,ShipmentUnit
生成两次 - 一次由身份规则(第一个模板)生成,然后复制它然后将模板应用于其所有子项,然后您有一个特定的模板ShipmentUnitItem
上的匹配,然后也插入ShipmentUnit
元素,然后再次复制ShipmentUnit
个孩子。这就是你得到不必要的重复的原因。
为避免这种情况,您需要一个专门匹配ShipmentUnit
的模板,并指定不同的行为。
以下代码适用于XSLT 1.0,并生成与您的样本所需输出相同的输出XML。
<!-- An "identity" template.
"Identity" here means that the template copies over macthing elements,
without changing them. -->
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<!-- This rule matches on `ShipmentUnit`, and essentially duplicates the `ShipmentUnit`
structure for each of the `ShipmentUnitItem` children.
Since this rule specifically matches `ShipmentUnit`, this takes priority over
the less-specific `match="*"` identity template above. This means that the
`ShipmentUnit` element is processed specifically here, and *not* by the
identity template. -->
<xsl:template match="ShipmentUnit">
<xsl:for-each select="ShipmentUnitItem">
<ShipmentUnit>
<!-- Instead of manually listing each `ShipmentUnit` element to copy over,
we just select them in a group - we want to copy every `ShipmentUnit`
child *except for* any `ShipmentUnitItem` other than the current one.
The code below uses the `preceding-sibling` axis to grab all the
sibling elements (i.e., elements on the same level and belonging to
the same parent) that come before this `ShipmentUnitItem`, and the
`following-sibling` axis to then grab all the elements after it.
The `name()!=` test makes sure we only grab elements that *aren't*
`ShipmentUnitItem`, so we avoid unwanted duplication. -->
<xsl:copy-of select="./preceding-sibling::*[name()!='ShipmentUnitItem']"/>
<xsl:copy-of select="."/>
<xsl:copy-of select="./following-sibling::*[name()!='ShipmentUnitItem']"/>
</ShipmentUnit>
</xsl:for-each>
</xsl:template>