XSLT 1.0 Inhalt von XML unter Bedingungen löschen

- xml
- xsl
Hallo zusammen,
bitte um Hilfe.
Es soll ein XML ohne Inhalt generiert werden, wenn derselbe Wert im Item/SupplierArticleNumber mehrfach vorkommt UND der Wert im Item/SalesPrice unterschiedlich ist.
Beispiel XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<SALESINVOICE>
<Interchange>
<Interchange_Control_Number>1</Interchange_Control_Number>
</Interchange>
<HeaderInformation>
<OrigInvoiceNumber>1</OrigInvoiceNumber>
</HeaderInformation>
<LineInformation>
<Item>
<LineNum>1</LineNum>
<SupplierArticleNumber>860347</SupplierArticleNumber>
<SalesPrice>425.0000</SalesPrice>
</Item>
<Item>
<LineNum>2</LineNum>
<SupplierArticleNumber>860347</SupplierArticleNumber>
<SalesPrice>412.5000</SalesPrice>
</Item>
<Item>
<LineNum>3</LineNum>
<SupplierArticleNumber>881303</SupplierArticleNumber>
<SalesPrice>34.1300</SalesPrice>
</Item>
<Item>
<LineNum>4</LineNum>
<SupplierArticleNumber>881303</SupplierArticleNumber>
<SalesPrice>0.0000</SalesPrice>
</Item>
</LineInformation>
</SALESINVOICE>
Mein Ansatz:
<xsl:template match="/">
<xsl:choose>
<xsl:when test="Item[SupplierArticleNumber = SupplierArticleNumber and SalesPrice != SalesPrice]"></xsl:when>
<xsl:otherwise> <xsl:apply-templates select="@* | node()"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
Das komplette XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*" />
<xsl:template match="/">
<xsl:choose>
<xsl:when test="Item[SupplierArticleNumber = SupplierArticleNumber and SalesPrice != SalesPrice]"></xsl:when>
<xsl:otherwise> <xsl:apply-templates select="@* | node()"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:key name="item" match="Item" use="concat(LineNum, '|', GTIN, '|', Ordered, '|', LineNumSalesLine)"/>
<xsl:template match="Item[generate-id() != generate-id(key('item', concat(LineNum, '|', GTIN, '|', Ordered, '|', LineNumSalesLine))[1])]" />
<xsl:template match="Item">
<Item>
<xsl:apply-templates/>
<xsl:call-template name="process1"/>
</Item>
</xsl:template>
<xsl:template match="ItemDeliveryInformation"/>
<xsl:template name="process1">
<xsl:variable name="tempdoc">
<temproot>
<xsl:for-each select="ItemDeliveryInformation[generate-id() = generate-id(key('packing_slip', concat(LineNumDeliveryNote, '|', PackingSlipId, '|', DeliveryDate, '|', DeliveredQuantity, '|', RecId_InventTrans))[1])]">
<xsl:copy-of select="."/>
</xsl:for-each>
</temproot>
</xsl:variable>
<xsl:call-template name="process2">
<xsl:with-param name="nodes" select="exsl:node-set($tempdoc)"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="process2">
<xsl:param name="nodes"/>
<xsl:if test="$nodes//PackingSlipId != '' ">
<ItemDeliveryInformation>
<LineNumDeliveryNote>
<xsl:value-of select="$nodes//LineNumDeliveryNote[1]"/>
</LineNumDeliveryNote>
<PackingSlipId_Created>
<xsl:value-of select="$nodes//PackingSlipId_Created[1]"/>
</PackingSlipId_Created>
<PackingSlipId>
<xsl:value-of select="$nodes//PackingSlipId[1]"/>
</PackingSlipId>
<DeliveryDate>
<xsl:value-of select="$nodes//DeliveryDate[1]"/>
</DeliveryDate>
<DeliveredQuantity>
<xsl:value-of select="format-number(sum($nodes//DeliveredQuantity), '#.00')"/>
</DeliveredQuantity>
<ShipFromAddressInformation>
<xsl:copy-of select="$nodes//ShipFromAddressInformation/GLN[1]"/>
<xsl:copy-of select="$nodes//ShipFromAddressInformation/Name[1]"/>
<xsl:copy-of select="$nodes//ShipFromAddressInformation/Street[1]"/>
<xsl:copy-of select="$nodes//ShipFromAddressInformation/ZipCode[1]"/>
<xsl:copy-of select="$nodes//ShipFromAddressInformation/City[1]"/>
<xsl:copy-of select="$nodes//ShipFromAddressInformation/Country[1]"/>
<xsl:copy-of select="$nodes//ShipFromAddressInformation/State[1]"/>
<xsl:copy-of select="$nodes//ShipFromAddressInformation/VATNum[1]"/>
<xsl:copy-of select="$nodes//ShipFromAddressInformation/InternalNumber[1]"/>
</ShipFromAddressInformation>
</ItemDeliveryInformation>
</xsl:if>
</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>
Danke, lg Julian
Lösung:
<xsl:key name="item" match="Item" use="SupplierArticleNumber"/>
<xsl:template match="/">
<xsl:if test="not(SALESINVOICE/LineInformation/Item[SalesPrice != key('item', SupplierArticleNumber)/SalesPrice])">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>