Можете ли вы помочь мне, пожалуйста?
Если есть различия в «PackingslipId» - «LineItem» - «Lines», я не хотел бы иметь «PackingslipId» и «DeliveryDate» в «HeaderInformation».
Если "PackingslipId" всегда одинаков для "LineItem" - "Lines", чем для "HeaderInformation", выходные данные "PackingslipId" и "DeliveryDate" в порядке.
Обратите внимание: (не важно, если это важно; также может быть, что есть только одна статья ("LineItem" - "Lines" - с "OrderLineNum" 1) - в данном случае, "PackingslipId" это то же самое, что и «Lines» и «HeaderInformation», поэтому «PackingslipId» и «DeliveryDate» должны быть также в «HeaderInformation» и «LineItem»
Мой XML:
<?xml version="1.0" encoding="utf-8"?>
<SALESINVOICE>
<Interchange>
<Recipient></Recipient>
<Sender></Sender>
<CreationDate>2018-11-19:07:06:20</CreationDate>
<Test>No</Test>
<Interchange_Control_Number></Interchange_Control_Number>
<HeaderInformation>
<OrigInvoiceNumber>1</OrigInvoiceNumber>
<InvoiceType>INVOIC</InvoiceType>
<InvoiceDate>2018-11-19</InvoiceDate>
<InvoiceNumber>FV1800087</InvoiceNumber>
<CustomerOrderReference></CustomerOrderReference>
<SalesOrderReference></SalesOrderReference>
<SalesOrderDate>2018-11-15T07:22:01</SalesOrderDate>
<PackingslipId>AV1800097</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<Currency>EUR</Currency>
<TaxExempt></TaxExempt>
<Contact />
<TermsOfPayment>
<PaymTermDescription></PaymTermDescription>
<DueDate></DueDate>
</TermsOfPayment>
<CashDiscountConditions />
<WeightAndVolume>
<NetWeight></NetWeight>
<UnifOfWeight></UnifOfWeight>
</WeightAndVolume>
<SupplierAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<CoRegNum></CoRegNum>
<VATNum></VATNum>
</SupplierAddressInformation>
<BuyerAddressInformation>
<Name></Name>
<Country></Country>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</BuyerAddressInformation>
<InvoiceAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</InvoiceAddressInformation>
<DeliveryAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<State></State>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</DeliveryAddressInformation>
<TransportDetails>
<DeliveryTerms></DeliveryTerms>
</TransportDetails>
<LineItem>
<Lines>
<OrderLineNum>1</OrderLineNum>
<PackingslipId>AV1800097</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>2</OrderLineNum>
<PackingslipId>AV1800098</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>3</OrderLineNum>
<PackingslipId>AV1800099</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>4</OrderLineNum>
<PackingslipId>AV1800099</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
</LineItem>
<Totals>
<InvoiceTotal></InvoiceTotal>
<NetAmount></NetAmount>
<VATAmount></VATAmount>
<DiscountAmount></DiscountAmount>
<AllowanceOrChargeAmount></AllowanceOrChargeAmount>
<DueDate></DueDate>
<VAT>
<VATS>
<Percentage></Percentage>
<Type></Type>
<BaseAmount></BaseAmount>
<VATAmount></VATAmount>
</VATS>
</VAT>
</Totals>
</HeaderInformation>
</Interchange>
</SALESINVOICE>
Мой XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:key name="header_text" match="HeaderText" use="Text"/>
<xsl:key name="line_text" match="LineText" use="concat(../OrderLineNum, '|', Text)"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- no duplilcate on HeaderText and LineText -->
<xsl:template match="HeaderText[generate-id() != generate-id(key('header_text', Text)[1])]" />
<xsl:template match="LineText[generate-id() != generate-id(key('line_text', concat(../OrderLineNum, '|', Text))[1])]" />
<!-- delete PackingslipId on HeaderInformation, if different at Line -->
<xsl:template match="/salesinvoices/lineItem">
<xsl:choose>
<xsl:when test="
count(lines[not(PackingslipId = preceding-sibling::lines/PackingslipId)]) = 1">
<xsl:copy-of select="//HeaderInformation/PackingslipId"/>
<xsl:copy-of select="//HeaderInformation/DeliveryDate"/>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- delete empty nodes -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>
</xsl:stylesheet>
Правильный вывод должен быть: (без PackingslipId и без DeliveryDate для HeaderInformation, потому что в LineItem - PackingslipId есть различия)
<?xml version="1.0" encoding="utf-8"?>
<SALESINVOICE>
<Interchange>
<Recipient></Recipient>
<Sender></Sender>
<CreationDate>2018-11-19:07:06:20</CreationDate>
<Test>No</Test>
<Interchange_Control_Number></Interchange_Control_Number>
<HeaderInformation>
<OrigInvoiceNumber>1</OrigInvoiceNumber>
<InvoiceType>INVOIC</InvoiceType>
<InvoiceDate>2018-11-19</InvoiceDate>
<InvoiceNumber>FV1800087</InvoiceNumber>
<CustomerOrderReference></CustomerOrderReference>
<SalesOrderReference></SalesOrderReference>
<SalesOrderDate>2018-11-15T07:22:01</SalesOrderDate>
<Currency>EUR</Currency>
<TaxExempt></TaxExempt>
<Contact />
<TermsOfPayment>
<PaymTermDescription></PaymTermDescription>
<DueDate></DueDate>
</TermsOfPayment>
<CashDiscountConditions />
<WeightAndVolume>
<NetWeight></NetWeight>
<UnifOfWeight></UnifOfWeight>
</WeightAndVolume>
<SupplierAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<CoRegNum></CoRegNum>
<VATNum></VATNum>
</SupplierAddressInformation>
<BuyerAddressInformation>
<Name></Name>
<Country></Country>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</BuyerAddressInformation>
<InvoiceAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</InvoiceAddressInformation>
<DeliveryAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<State></State>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</DeliveryAddressInformation>
<TransportDetails>
<DeliveryTerms></DeliveryTerms>
</TransportDetails>
<LineItem>
<Lines>
<OrderLineNum>1</OrderLineNum>
<PackingslipId>AV1800097</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>2</OrderLineNum>
<PackingslipId>AV1800098</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>3</OrderLineNum>
<PackingslipId>AV1800099</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
<Lines>
<OrderLineNum>4</OrderLineNum>
<PackingslipId>AV1800099</PackingslipId>
<DeliveryDate>2018-11-19</DeliveryDate>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity></Quantity>
<PriceUnit></PriceUnit>
<FixedPrice></FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount></DiscAmount>
<DiscPercent></DiscPercent>
<SalesLinePercent1></SalesLinePercent1>
<SalesLinePercent2></SalesLinePercent2>
<MultiLnDisc></MultiLnDisc>
<MultiLnPercent></MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc></SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
</Lines>
</LineItem>
<Totals>
<InvoiceTotal></InvoiceTotal>
<NetAmount></NetAmount>
<VATAmount></VATAmount>
<DiscountAmount></DiscountAmount>
<AllowanceOrChargeAmount></AllowanceOrChargeAmount>
<DueDate></DueDate>
<VAT>
<VATS>
<Percentage></Percentage>
<Type></Type>
<BaseAmount></BaseAmount>
<VATAmount></VATAmount>
</VATS>
</VAT>
</Totals>
</HeaderInformation>
</Interchange>
</SALESINVOICE>
Большое спасибо,
С наилучшими пожеланиями
Julian