juls_pro_37: XSLT 1.0 zwei Abfragen kombinieren

Beitrag lesen

ja, wenn ich auf Saxon 6.5.5 (http://xsltransform.net/jz1PuPz) stelle siehts gut aus danke!

Musste jetzt seit gestern einen Unterpunkt unter "ItemDeliveryInformation" einfügen und hätte das im Code ergänzt. Leider dürfte ich noch irgendwo einen Denkfehler haben.

Wieso erhalte ich unter ItemDeliveryInformation.ShipFromAddressInformation immer die Daten beider Artikel anstatt immer nur von einem? Wir haben doch unter

 <xsl:key name="packing_slip" match="ItemDeliveryInformation" use="concat(LineNumDeliveryNote, '|', PackingSlipId, '|', DeliveryDate, '|', DeliveredQuantity, '|', RecId_InventTrans)"/>

auf die unterschiedliche LineNum referenziert oder?

Order muss man auch die LineNum von "Item" mit einfließen lassen?

XML:

<?xml version="1.0" encoding="utf-8"?>
<SALESINVOICE>
  <Interchange>    
    <Interchange_Control_Number>5637411610</Interchange_Control_Number>
  </Interchange>
  <HeaderInformation>
    <OrigInvoiceNumber>1</OrigInvoiceNumber>
  </HeaderInformation>
  <LineInformation>
    <Item>
      <LineNum>1</LineNum>
      <GTIN>1</GTIN>
      <ItemDeliveryInformation>
        <LineNumDeliveryNote>1</LineNumDeliveryNote>
        <PackingSlipId_Created>2021-02-17T09:33:11</PackingSlipId_Created>
        <PackingSlipId>LS-0000069</PackingSlipId>
        <DeliveryDate>2021-02-17</DeliveryDate>
        <DeliveredQuantity>1.00</DeliveredQuantity>
        <ShipFromAddressInformation>
          <Name>Lagerort 1</Name>
          <Street>Straße 1</Street>
        </ShipFromAddressInformation>
      </ItemDeliveryInformation>
    </Item>
    <Item>
      <LineNum>2</LineNum>
      <GTIN>2</GTIN>
      <ItemDeliveryInformation>
        <LineNumDeliveryNote>2</LineNumDeliveryNote>
        <PackingSlipId_Created>2021-02-17T09:33:11</PackingSlipId_Created>
        <PackingSlipId>LS-0000069</PackingSlipId>
        <DeliveryDate>2021-02-17</DeliveryDate>
        <DeliveredQuantity>1.00</DeliveredQuantity>
        <ShipFromAddressInformation>
          <Name>Lagerort 2</Name>
          <Street>Straße 2</Street>
        </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:key name="packing_slip" match="ItemDeliveryInformation" use="concat(LineNumDeliveryNote, '|', PackingSlipId, '|', DeliveryDate, '|', DeliveredQuantity, '|', RecId_InventTrans)"/>

  
  <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"/>
    <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="//ShipFromAddressInformation/GLN"/>
        <xsl:copy-of select="//ShipFromAddressInformation/Name"/>      
        <xsl:copy-of select="//ShipFromAddressInformation/Street"/>
        <xsl:copy-of select="//ShipFromAddressInformation/ZipCode"/>
        <xsl:copy-of select="//ShipFromAddressInformation/City"/>
        <xsl:copy-of select="//ShipFromAddressInformation/Country"/>
        <xsl:copy-of select="//ShipFromAddressInformation/State"/>
        <xsl:copy-of select="//ShipFromAddressInformation/VATNum"/> 
        <xsl:copy-of select="//ShipFromAddressInformation/InternalNumber"/>    
    </ShipFromAddressInformation>
    </ItemDeliveryInformation>
  </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>

Richtig wäre:

<?xml version="1.0" encoding="UTF-8"?>
<SALESINVOICE>
   <Interchange>    
      <Interchange_Control_Number>5637411610</Interchange_Control_Number>
   </Interchange>
   <HeaderInformation>
      <OrigInvoiceNumber>1</OrigInvoiceNumber>
   </HeaderInformation>
   <LineInformation>
      <Item>
         <LineNum>1</LineNum>
         <GTIN>1</GTIN>
         <ItemDeliveryInformation>
            <LineNumDeliveryNote>1</LineNumDeliveryNote>
            <PackingSlipId_Created>2021-02-17T09:33:11</PackingSlipId_Created>
            <PackingSlipId>LS-0000069</PackingSlipId>
            <DeliveryDate>2021-02-17</DeliveryDate>
            <DeliveredQuantity>1.00</DeliveredQuantity>
            <ShipFromAddressInformation>
               <Name>Lagerort 1</Name>        
               <Street>Straße 1</Street>
               <Street>Straße 2</Street>
            </ShipFromAddressInformation>
         </ItemDeliveryInformation>
      </Item>
      <Item>
         <LineNum>2</LineNum>
         <GTIN>2</GTIN>  
         <ItemDeliveryInformation>
            <LineNumDeliveryNote>2</LineNumDeliveryNote>
            <PackingSlipId_Created>2021-02-17T09:33:11</PackingSlipId_Created>
            <PackingSlipId>LS-0000069</PackingSlipId>
            <DeliveryDate>2021-02-17</DeliveryDate>
            <DeliveredQuantity>1.00</DeliveredQuantity>
            <ShipFromAddressInformation>
               <Street>Straße 1</Street>
               <Street>Straße 2</Street>
            </ShipFromAddressInformation>
         </ItemDeliveryInformation>
      </Item> 
   </LineInformation>
</SALESINVOICE>

Ist das jetzt problematisch mit der Erweiterung von ShipAddressInformation unter ItemDeliveryInformation oder lässt sich das schnell lösen?

Bzw. wäre dieser Aufbau richtig?:

<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>

LG Julian