juls_pro_37: XSLT 1.0 neuen Knoten mit Unterpunkte erstellen

Beitrag lesen

danke das funktioniert genau so wie gewünscht.

Wie kann ich das nun vor dem "LineText" stellen?

XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<SALESINVOICE>
<HeaderInformation>
<InvoiceDate>20200707</InvoiceDate>
<InvoiceNumber>201028006</InvoiceNumber>
</HeaderInformation>
<LineInformation>
<Item>
<LineNum>1</LineNum>
<CustomerPurchaseOrder>test1</CustomerPurchaseOrder>
<TotalQuantity>33.00</TotalQuantity>
<LineText>
<Qualifier>INV</Qualifier>
<Text>Text1</Text>
</LineText>    			  
</Item>
</LineInformation>
<LineInformation>
<Item>
<LineNum>2</LineNum>
<CustomerPurchaseOrder>test2</CustomerPurchaseOrder>
<TotalQuantity>55.00</TotalQuantity>
<LineText>
<Qualifier>INV</Qualifier>
<Text>Text2</Text>
</LineText>        		  
</Item>
</LineInformation>
</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>
    
        <!-- Erstellt den Knoten ItemDeliveryInformation (mit Unterpunkten) wenn dier fehlt -->
    <xsl:template match="Item[not(ItemDeliveryInformation)]"> 
    <xsl:apply-templates select="node()"/>
          <Item>        
            <ItemDeliveryInformation>            
              <LineNumDeliveryNote>0</LineNumDeliveryNote>
              <PackingSlipId>
                <xsl:value-of select="/SALESINVOICE/HeaderInformation/InvoiceNumber"/>
              </PackingSlipId>
              <DeliveryDate>
                <xsl:value-of select="/SALESINVOICE/HeaderInformation/InvoiceDate"/>
              </DeliveryDate>
              <DeliveredQuantity>
                <xsl:value-of select="TotalQuantity"/>
              </DeliveredQuantity>
            </ItemDeliveryInformation>
          </Item>
    </xsl:template>

</xsl:stylesheet>

Korrekt:

<?xml version="1.0" encoding="UTF-8"?>
<SALESINVOICE>
<HeaderInformation>
<InvoiceDate>20200707</InvoiceDate>
<InvoiceNumber>201028006</InvoiceNumber>
</HeaderInformation>
<LineInformation>
<LineNum>1</LineNum>
<CustomerPurchaseOrder>test1</CustomerPurchaseOrder>
<TotalQuantity>33.00</TotalQuantity>
<ItemDeliveryInformation>
<LineNumDeliveryNote>0</LineNumDeliveryNote>
<PackingSlipId>201028006</PackingSlipId>
<DeliveryDate>20200707</DeliveryDate>
<DeliveredQuantity>33.00</DeliveredQuantity>
</ItemDeliveryInformation>
<LineText>
<Qualifier>INV</Qualifier>
<Text>Text1</Text>
</LineText>    			  
<Item>
</Item>
</LineInformation>
<LineInformation>
<LineNum>2</LineNum>
<CustomerPurchaseOrder>test2</CustomerPurchaseOrder>
<TotalQuantity>55.00</TotalQuantity>
<ItemDeliveryInformation>
<LineNumDeliveryNote>0</LineNumDeliveryNote>
<PackingSlipId>201028006</PackingSlipId>
<DeliveryDate>20200707</DeliveryDate>
<DeliveredQuantity>55.00</DeliveredQuantity>
</ItemDeliveryInformation>
<LineText>
<Qualifier>INV</Qualifier>
<Text>Text2</Text>
</LineText>        		  
<Item>
</Item>
</LineInformation>
</SALESINVOICE>