Hi, hätte wieder eine Frage zur fortlaufenden Berechnung.
Benötige ein neues Segment "LineNumSalesLine" - wenn nicht vorhanden.
Dieses Segment soll alle bestehenden "LineNumSalesLine" zählen und fortlaufend nummerieren. (mein Problem ist LineNum 4)
XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<OrderResponse>
<Interchange>
<Interchange_Control_Number>5637334332</Interchange_Control_Number>
</Interchange>
<HeaderInformation>
</HeaderInformation>
<LineInformation>
<Item>
<LineNum>1</LineNum>
<SupplierArticleNumber>test1</SupplierArticleNumber>
<OrigSupplierArticleNumber>test1</OrigSupplierArticleNumber>
<BuyerArticleNumber>abc</BuyerArticleNumber>
<LineNumSalesLine>1</LineNumSalesLine>
</Item>
<Item>
<LineNum>2</LineNum>
<SupplierArticleNumber>test2</SupplierArticleNumber>
</Item>
<Item>
<LineNum>3</LineNum>
<SupplierArticleNumber>test3</SupplierArticleNumber>
<OrigSupplierArticleNumber>def</OrigSupplierArticleNumber>
<LineNumSalesLine>3</LineNumSalesLine>
</Item>
<Item>
<LineNum>4</LineNum>
<SupplierArticleNumber>4</SupplierArticleNumber>
</Item>
</LineInformation>
</OrderResponse>
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:template match="Item[not(LineNumSalesLine)]">
<xsl:copy>
<!--copy all other nodes-->
<xsl:apply-templates select="@* | node()"/>
<LineNumSalesLine>
<xsl:value-of select="count(//Item/LineNumSalesLine) + 1"/>
</LineNumSalesLine>
</xsl:copy>
</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 sollte es so aussehen:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OrderResponse>
<Interchange>
<Interchange_Control_Number>5637334332</Interchange_Control_Number>
</Interchange>
<LineInformation>
<Item>
<LineNum>1</LineNum>
<SupplierArticleNumber>test1</SupplierArticleNumber>
<OrigSupplierArticleNumber>test1</OrigSupplierArticleNumber>
<BuyerArticleNumber>abc</BuyerArticleNumber>
<LineNumSalesLine>1</LineNumSalesLine>
</Item>
<Item>
<LineNum>2</LineNum>
<SupplierArticleNumber>test2</SupplierArticleNumber>
<LineNumSalesLine>3</LineNumSalesLine>
</Item>
<Item>
<LineNum>3</LineNum>
<SupplierArticleNumber>test3</SupplierArticleNumber>
<OrigSupplierArticleNumber>def</OrigSupplierArticleNumber>
<LineNumSalesLine>3</LineNumSalesLine>
</Item>
<Item>
<LineNum>4</LineNum>
<SupplierArticleNumber>4</SupplierArticleNumber>
<LineNumSalesLine>4</LineNumSalesLine>
</Item>
</LineInformation>
</OrderResponse>
Danke & LG
Julian