juls_pro_37: XSLT 1.0 Nummerierung (count)

Beitrag lesen

ok ich versuchs nochmal mit einem neuen XML und XSLT, bitte findest du die Lösung :)

XML:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<OrderResponse>
  <Interchange>    
    <Interchange_Control_Number>5637334349</Interchange_Control_Number>
  </Interchange>
  <HeaderInformation>
    <ConfirmDocNum>SO0001084-3</ConfirmDocNum>    
  </HeaderInformation>
  <LineInformation>
    <Item>
      <LineNum>1</LineNum>      
      <SupplierArticleNumber>P0003975A</SupplierArticleNumber>
      <OrigSupplierArticleNumber>P0003975A</OrigSupplierArticleNumber>
      <BuyerArticleNumber>S02754</BuyerArticleNumber>
      <LineNumSalesLine>1</LineNumSalesLine>
    </Item>
    <Item>
      <LineNum>2</LineNum>      
      <SupplierArticleNumber>P0090610</SupplierArticleNumber>
      <OrigSupplierArticleNumber>P0090610</OrigSupplierArticleNumber>
      <BuyerArticleNumber>S29648</BuyerArticleNumber>
      <LineNumSalesLine>2</LineNumSalesLine>
    </Item>
    <Item>
      <LineNum>3</LineNum>     
      <SupplierArticleNumber>P0090631</SupplierArticleNumber>
      <OrigSupplierArticleNumber>P0090631</OrigSupplierArticleNumber>
      <BuyerArticleNumber>S29649</BuyerArticleNumber>
      <LineNumSalesLine>3</LineNumSalesLine>
    </Item>
    <Item>
      <LineNum>4</LineNum>      
      <SupplierArticleNumber>P0090611</SupplierArticleNumber>
      <OrigSupplierArticleNumber>P0090611</OrigSupplierArticleNumber>
      <BuyerArticleNumber>S29652</BuyerArticleNumber>
      <LineNumSalesLine>4</LineNumSalesLine>
    </Item>
    <Item>
      <LineNum>5</LineNum>
      <SupplierArticleNumber>P0090615</SupplierArticleNumber>
      <OrigSupplierArticleNumber>P0090615</OrigSupplierArticleNumber>
      <BuyerArticleNumber>S29657</BuyerArticleNumber>
      <LineNumSalesLine>5</LineNumSalesLine>
    </Item>
    <Item>
      <LineNum>6</LineNum>
      <SupplierArticleNumber>P0090635</SupplierArticleNumber>
      <OrigSupplierArticleNumber>P0090635</OrigSupplierArticleNumber>
      <BuyerArticleNumber>S29664</BuyerArticleNumber>
      <LineNumSalesLine>6</LineNumSalesLine>
    </Item>
    <Item>
      <LineNum>7</LineNum>
      <SupplierArticleNumber>P0003200A</SupplierArticleNumber>
      <OrigSupplierArticleNumber>P0003200A</OrigSupplierArticleNumber>
      <LineNumSalesLine>7</LineNumSalesLine>
      <LineText />
    </Item>
    <Item>
      <LineNum>8</LineNum>
      <SupplierArticleNumber>P0001555</SupplierArticleNumber>
    </Item>
    <Item>
      <LineNum>9</LineNum>
      <SupplierArticleNumber>P0009051</SupplierArticleNumber>
    </Item>
    <Item>
      <LineNum>10</LineNum>
      <SupplierArticleNumber>P0009068</SupplierArticleNumber>
    </Item>
    <Item>
      <LineNum>11</LineNum>
      <SupplierArticleNumber>P0075511</SupplierArticleNumber>
    </Item>
    <Item>
      <LineNum>12</LineNum>
      <SupplierArticleNumber>P0001113</SupplierArticleNumber>
    </Item>
    <Item>
      <LineNum>13</LineNum>
      <SupplierArticleNumber>P00MESD2</SupplierArticleNumber>
      <OrigSupplierArticleNumber>EDIPER</OrigSupplierArticleNumber>
      <LineNumSalesLine>9</LineNumSalesLine>
      <LineText />
    </Item>
    <Item_001>
      <SupplierArticleNumber>EDIPER</SupplierArticleNumber>
      <BuyerArticleNumber>P00MESD2</BuyerArticleNumber>
      <LineNumSalesLine>9</LineNumSalesLine>
    </Item_001>
    <Item_002>
      <GTIN>3660965369511</GTIN>
      <SupplierArticleNumber>BKPROL150</SupplierArticleNumber>
      <LineNumSalesLine>8</LineNumSalesLine>
      <LineText_002 />
    </Item_002>
  </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_001"> 	   
 <xsl:element name="Item">
           <LineChange>
    		    <xsl:choose>     
                     <!-- Wert 7 (Cancel), wenn es Artikel gibt in denen EDI vorkommt (EDIPER/EDICIL) -->
                     <xsl:when test="SupplierArticleNumber[contains(., 'EDI')]">7</xsl:when>                     
			    </xsl:choose>
		    </LineChange>
                <!--create new node LineNum with counter for Item_001 -->
    		<LineNum>
                <xsl:number value="position()" />                 
            </LineNum>
	<!--copy all other nodes-->
	<xsl:apply-templates select="@* | node()"/>                
	<!-- Positionstext, wenn es Abweichungen zwischen bestellten und bestätigten Artikel gibt  -->
        <xsl:choose>
    			<xsl:when test="SupplierArticleNumber[contains(., 'EDI')]">
    				<LineText>
						<Qualifier>ZZZ</Qualifier>						
						<Text>Article remplace par <xsl:value-of select="BuyerArticleNumber"/></Text>	
					</LineText>
				</xsl:when>
        </xsl:choose>   
</xsl:element>
   </xsl:template>
   
  <!-- Delete Item_001/BuyerArticleNumber-->
  <xsl:template match="Item_001/BuyerArticleNumber"/>
  
  <xsl:template match="Item_002">        
 <xsl:element name="Item">
        <!-- Wert 7 (Cancelled_Item) -->
           <LineChange>7</LineChange>
                <!--create new node LineNum with counter for Item_001 -->
        	<LineNum>
                <xsl:number value="position()" />                 
            </LineNum>
	<!--copy all other nodes-->
	<xsl:apply-templates select="@* | node()"/>
</xsl:element>
   </xsl:template>

    <xsl:template match="LineText_002">        
        <xsl:element name="LineText">       
	<!--copy all other nodes-->
	<xsl:apply-templates select="@* | node()"/>
        </xsl:element>
    </xsl:template>
   

   
   <xsl:template match="Item[not(LineNumSalesLine)]">
  <xsl:copy>
    <!--copy all other nodes-->
    <xsl:apply-templates select="@* | node()"/>
    <LineNumSalesLineTest>
      <xsl:value-of select="count(preceding::LineNumSalesLine) +
        count(//Item[not(preceding::LineNumSalesLine)]) + 1"/>
    </LineNumSalesLineTest>
  </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>

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

LG Julian