Можете ли вы помочь мне, пожалуйста?
Если есть различия в "PackingslipId" - "LineInformation" - "Lines", я не хотел бы иметь "PackingslipId" и "DeliveryDate" в "HeaderInformation".
Если «PackingslipId» всегда одинаков для «LineInformation» - «Item», чем для «HeaderInformation», выходные данные «PackingslipId» и «DeliveryDate» в порядке.
Обратите внимание: (не важно, если это важно; возможно, есть только одна статья («LineInformation» - «Item» - с «OrderLineNum» 1) - в данном случае «PackingslipId» это то же самое, что и «Item» и «HeaderInformation», поэтому «PackingslipId» и «DeliveryDate» должны быть также в «HeaderInformation» и «LineItem»
Мой XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<SALESINVOICE>
<Interchange>
<Recipient></Recipient>
<Sender></Sender>
<CreationDate></CreationDate>
<Test></Test>
<Interchange_Control_Number></Interchange_Control_Number>
</Interchange>
<HeaderInformation>
<OrigInvoiceNumber>1</OrigInvoiceNumber>
<InvoiceType>INVOIC</InvoiceType>
<InvoiceDate>2019.01.23</InvoiceDate>
<InvoiceNumber></InvoiceNumber>
<PurchOrderReference>fddf</PurchOrderReference>
<SalesOrderReference></SalesOrderReference>
<CustomerOrderReference>fdgfdg</CustomerOrderReference>
<PackingslipId>1079304</PackingslipId>
<DeliveryDate>2019.01.23</DeliveryDate>
<Currency></Currency>
<WeightAndVolume />
<DeliveryAddressInformation>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
</DeliveryAddressInformation>
<InvoiceAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</InvoiceAddressInformation>
<BuyerAddressInformation />
<SupplierAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<VATNum></VATNum>
<Contact />
</SupplierAddressInformation>
</HeaderInformation>
<LineInformation>
<Item>
<OrderLineNum>1</OrderLineNum>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<PackingslipId>1079304</PackingslipId>
<DeliveryDate>2019.01.23</DeliveryDate>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity>1</Quantity>
<DeliveredQuantity>1</DeliveredQuantity>
</Item>
</LineInformation>
<LineInformation>
<Item>
<OrderLineNum>2</OrderLineNum>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<PackingslipId>1079305</PackingslipId>
<DeliveryDate>2019.01.23</DeliveryDate>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity>1</Quantity>
<DeliveredQuantity>1</DeliveredQuantity>
</Item>
</LineInformation>
<Totals />
</SALESINVOICE>
Мой XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- Delete PackingslipId and DeliveryDate on HeaderInformation, if PackingslipId on Line is different -->
<xsl:template match="HeaderInformation[PackingslipId != LineInformation/Item/PackingslipId]/*[self::PackingslipId or self::DeliveryDate]" />
<xsl:template match="LineInformation_TEMP">
<xsl:apply-templates select="node()"/>
</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()='']"/>
delete empty nodes -->
</xsl:stylesheet>
Правильный XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<SALESINVOICE>
<Interchange>
<Recipient></Recipient>
<Sender></Sender>
<CreationDate></CreationDate>
<Test></Test>
<Interchange_Control_Number></Interchange_Control_Number>
</Interchange>
<HeaderInformation>
<OrigInvoiceNumber>1</OrigInvoiceNumber>
<InvoiceType>INVOIC</InvoiceType>
<InvoiceDate>2019.01.23</InvoiceDate>
<InvoiceNumber></InvoiceNumber>
<PurchOrderReference>fddf</PurchOrderReference>
<SalesOrderReference></SalesOrderReference>
<CustomerOrderReference>fdgfdg</CustomerOrderReference>
<Currency></Currency>
<WeightAndVolume />
<DeliveryAddressInformation>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
</DeliveryAddressInformation>
<InvoiceAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<VATNum></VATNum>
<InternalNumber></InternalNumber>
</InvoiceAddressInformation>
<BuyerAddressInformation />
<SupplierAddressInformation>
<GLN></GLN>
<Name></Name>
<Street></Street>
<ZipCode></ZipCode>
<City></City>
<Country></Country>
<VATNum></VATNum>
<Contact />
</SupplierAddressInformation>
</HeaderInformation>
<LineInformation>
<Item>
<OrderLineNum>1</OrderLineNum>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<PackingslipId>1079304</PackingslipId>
<DeliveryDate>2019.01.23</DeliveryDate>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity>1</Quantity>
<DeliveredQuantity>1</DeliveredQuantity>
</Item>
</LineInformation>
<LineInformation>
<Item>
<OrderLineNum>2</OrderLineNum>
<GTIN></GTIN>
<GTINDescription>/GTINDescription>
<PackingslipId>1079305</PackingslipId>
<DeliveryDate>2019.01.23</DeliveryDate>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity>1</Quantity>
<DeliveredQuantity>1</DeliveredQuantity>
</Item>
</LineInformation>
<Totals />
</SALESINVOICE>
С наилучшими пожеланиями
Julian