juls_pro_37: XSLT 1.0 count, remove

Hi,

komme hier leider nicht weiter.

Benötige eine Prüfung, ob der Knoten "ItemDeliveryInformation" mehrfach (>1) unter dem betroffenen Knoten "Item" vorkommt, falls ja, ob in einem der mehrfach vorhandenen Knoten "ItemDeliveryInformation" der Unterpunkt "PackingSlipId" mit dem Wert "ohne Lieferschein" befüllt ist.

Wenn dies zutrifft, soll der gesamte Knoten "ItemDeliveryInformation" (der den Wert "PackingSlipId = ohne Lieferschein" besitzt gelöscht werden. -> Alle weiteren Knoten "ItemDeliveryInformation" sollen bestehen bleiben.

    <xsl:template match="Item[count(./ItemDeliveryInformation &lt; 1)] and Item/ItemDeliveryInformation[./PackingSlipId = 'ohne Lieferschein']">   
        <xsl:choose>
            <xsl:when test="Item[count(./ItemDeliveryInformation &lt; 1)] and Item/ItemDeliveryInformation[./PackingSlipId = 'ohne Lieferschein']"></xsl:when>
                <xsl:otherwise> <xsl:apply-templates select="@* | node()"/></xsl:otherwise>
        </xsl:choose>
    </xsl:template>

XML:

<?xml version="1.0" encoding="utf-8"?>
<SALESINVOICE>
    <Interchange>
		<Test>No</Test>
	</Interchange>
	<HeaderInformation>
		<OrigInvoiceNumber>1</OrigInvoiceNumber>
	</HeaderInformation>
	<LineInformation>
		<Item>
			<LineNum>1000</LineNum>
			<GTIN>1234</GTIN>
			<ItemDeliveryInformation>
				<LineNumDeliveryNote>1000</LineNumDeliveryNote>
				<PackingSlipId_Created>2022-01-19T06:26:24</PackingSlipId_Created>
				<PackingSlipId>LS-0062820</PackingSlipId>
				<DeliveryDate>2022-01-19</DeliveryDate>
				<DeliveredQuantity>3.00</DeliveredQuantity>
				<ShipFromAddressInformation/>
			</ItemDeliveryInformation>
			<ItemDeliveryInformation>
				<LineNumDeliveryNote>1000</LineNumDeliveryNote>				
				<PackingSlipId>ohne Lieferschein</PackingSlipId>
				<DeliveryDate>2022-01-25</DeliveryDate>
				<DeliveredQuantity>3.00</DeliveredQuantity>
				<ShipFromAddressInformation/>
			</ItemDeliveryInformation>
                <ItemDeliveryInformation>
				<LineNumDeliveryNote>1000</LineNumDeliveryNote>
				<PackingSlipId_Created>2022-01-19T06:26:24</PackingSlipId_Created>
				<PackingSlipId>LS-0062822</PackingSlipId>
				<DeliveryDate>2022-01-19</DeliveryDate>
				<DeliveredQuantity>3.00</DeliveredQuantity>
				<ShipFromAddressInformation/>
			</ItemDeliveryInformation>
		</Item>
		<Item>
			<LineNum>1002</LineNum>
			<GTIN>4657</GTIN>
			<ItemDeliveryInformation>
				<LineNumDeliveryNote>1002</LineNumDeliveryNote>
				<PackingSlipId_Created>2022-01-25</PackingSlipId_Created>
				<PackingSlipId>ohne Lieferschein</PackingSlipId>
				<DeliveryDate>2022-01-25</DeliveryDate>
				<DeliveredQuantity>1.00</DeliveredQuantity>
				<ShipFromAddressInformation/>
			</ItemDeliveryInformation>
		</Item>
	</LineInformation>
</SALESINVOICE>

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="Item[count(./ItemDeliveryInformation &lt; 1)] and Item/ItemDeliveryInformation[./PackingSlipId = 'ohne Lieferschein']">   
        <xsl:choose>
            <xsl:when test="Item[count(./ItemDeliveryInformation &lt; 1)] and Item/ItemDeliveryInformation[./PackingSlipId = 'ohne Lieferschein']"></xsl:when>
                <xsl:otherwise> <xsl:apply-templates select="@* | node()"/></xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
  <!-- Identity-Template für die nicht explizit benannten Elemente -->
  <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>

korrekt:

<?xml version="1.0" encoding="UTF-8"?>
<SALESINVOICE>
   <Interchange>
      <Test>No</Test>
   </Interchange>
   <HeaderInformation>
      <OrigInvoiceNumber>1</OrigInvoiceNumber>
   </HeaderInformation>
   <LineInformation>
      <Item>
         <LineNum>1000</LineNum>
         <GTIN>1234</GTIN>
         <ItemDeliveryInformation>
            <LineNumDeliveryNote>1000</LineNumDeliveryNote>
            <PackingSlipId_Created>2022-01-19T06:26:24</PackingSlipId_Created>
            <PackingSlipId>LS-0062820</PackingSlipId>
            <DeliveryDate>2022-01-19</DeliveryDate>
            <DeliveredQuantity>3.00</DeliveredQuantity>
         </ItemDeliveryInformation>
         <ItemDeliveryInformation>
            <LineNumDeliveryNote>1000</LineNumDeliveryNote>
            <PackingSlipId_Created>2022-01-19T06:26:24</PackingSlipId_Created>
            <PackingSlipId>LS-0062822</PackingSlipId>
            <DeliveryDate>2022-01-19</DeliveryDate>
            <DeliveredQuantity>3.00</DeliveredQuantity>
         </ItemDeliveryInformation>
      </Item>
      <Item>
         <LineNum>1002</LineNum>
         <GTIN>4657</GTIN>
         <ItemDeliveryInformation>
            <LineNumDeliveryNote>1002</LineNumDeliveryNote>
            <PackingSlipId_Created>2022-01-25</PackingSlipId_Created>
            <PackingSlipId>ohne Lieferschein</PackingSlipId>
            <DeliveryDate>2022-01-25</DeliveryDate>
            <DeliveredQuantity>1.00</DeliveredQuantity>
         </ItemDeliveryInformation>
      </Item>
   </LineInformation>
</SALESINVOICE>

Ich hoffe, ich konnte es einigermaßen erklären worum es mir geht.

LG Julian

  1. <xsl:template match="Item/ItemDeliveryInformation">
      <xsl:if test="count(preceding-sibling::ItemDeliveryInformation|following-sibling::ItemDeliveryInformation)=0 or PackingSlipId/text() != 'ohne Lieferschein'">
        <xsl:copy><xsl:apply-templates select="@* | node()"/></xsl:copy>
      </xsl:if>
    </xsl:template>