Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with splitting XML FILE

    Hi Guys,

    Below mentioned is the present input and the expected output.

    Present Input :
    Code:
    <ProductLineItem>
    <LineNumber>1</LineNumber>
    <ProductIdentification>
    <ProductIdentifier Domain="AssignedBySupplier" Agency="AssignedBySupplier">000000000000552171</ProductIdentifier>
    <ProductIdentifier Domain="AssignedByBuyer" Agency="AssignedByBuyer">00800077</ProductIdentifier>
    </ProductIdentification>
    <ShippedQuantity>
    <Measurement UnitOfMeasureCode="KGM">22500.000</Measurement>
    </ShippedQuantity>
    <PurchaseOrderNumber>
    <DocumentReference>
    <DocumentIdentifier1>2245264776</DocumentIdentifier1>
    <ReferenceItem>10</ReferenceItem>
    </DocumentReference>
    </PurchaseOrderNumber>
    <ProductSubLineItems>
    <SubLineItemNumber>1</SubLineItemNumber>
    <ManufacturingIdentificationDetails>
    <ManufacturingIdentificationTypeCode>Batch</ManufacturingIdentificationTypeCode>
    <ManufacturingIdentificationNumber>PUDOJTEST</ManufacturingIdentificationNumber>
    </ManufacturingIdentificationDetails>
    <NetWeight>
    <Measurement>10575.000</Measurement>
    </NetWeight>
    </ProductSubLineItems>
    <ProductSubLineItems>
    <SubLineItemNumber>2</SubLineItemNumber>
    <ManufacturingIdentificationDetails>
    <ManufacturingIdentificationTypeCode>Batch</ManufacturingIdentificationTypeCode>
    <ManufacturingIdentificationNumber>CIM_TEST04</ManufacturingIdentificationNumber>
    </ManufacturingIdentificationDetails>
    <NetWeight>
    <Measurement>11925.000</Measurement>
    </NetWeight>
    </ProductSubLineItems>
    </ProductLineItem>
    <ProductLineItem>
    <LineNumber>2</LineNumber>
    <ProductIdentification>
    <ProductIdentifier Domain="AssignedBySupplier" Agency="AssignedBySupplier">20000000000552171</ProductIdentifier>
    <ProductIdentifier Domain="AssignedByBuyer" Agency="AssignedByBuyer">20800077</ProductIdentifier>
    </ProductIdentification>
    <ShippedQuantity>
    <Measurement UnitOfMeasureCode="KGM">222500.000</Measurement>
    </ShippedQuantity>
    <PurchaseOrderNumber>
    <DocumentReference>
    <DocumentIdentifier1>22245264776</DocumentIdentifier1>
    <ReferenceItem>10</ReferenceItem>
    </DocumentReference>
    </PurchaseOrderNumber>
    <ProductSubLineItems>
    <SubLineItemNumber>1</SubLineItemNumber>
    <ManufacturingIdentificationDetails>
    <ManufacturingIdentificationTypeCode>2Batch</ManufacturingIdentificationTypeCode>
    <ManufacturingIdentificationNumber>2CIM_TEST04</ManufacturingIdentificationNumber>
    </ManufacturingIdentificationDetails>
    <NetWeight>
    <Measurement>211925.000</Measurement>
    </NetWeight>
    </ProductSubLineItems>
    </ProductLineItem>
    Expected Output :
    Code:
    <ProductLineItem>
    <LineNumber>1</LineNumber>
    <ProductIdentification>
    <ProductIdentifier Domain="AssignedBySupplier" Agency="AssignedBySupplier">000000000000552171</ProductIdentifier>
    <ProductIdentifier Domain="AssignedByBuyer" Agency="AssignedByBuyer">00800077</ProductIdentifier>
    </ProductIdentification>
    <ShippedQuantity>
    <Measurement UnitOfMeasureCode="KGM">22500.000</Measurement>
    </ShippedQuantity>
    <PurchaseOrderNumber>
    <DocumentReference>
    <DocumentIdentifier1>2245264776</DocumentIdentifier1>
    <ReferenceItem>10</ReferenceItem>
    </DocumentReference>
    </PurchaseOrderNumber>
    <ProductSubLineItems>
    <SubLineItemNumber>1</SubLineItemNumber>
    <ManufacturingIdentificationDetails>
    <ManufacturingIdentificationTypeCode>Batch</ManufacturingIdentificationTypeCode>
    <ManufacturingIdentificationNumber>PUDOJTEST</ManufacturingIdentificationNumber>
    </ManufacturingIdentificationDetails>
    <NetWeight>
    <Measurement>10575.000</Measurement>
    </NetWeight>
    </ProductSubLineItems>
    </ProductLineItem>
    <ProductLineItem>
    <LineNumber>2</LineNumber>
    <ProductIdentification>
    <ProductIdentifier Domain="AssignedBySupplier" Agency="AssignedBySupplier">000000000000552171</ProductIdentifier>
    <ProductIdentifier Domain="AssignedByBuyer" Agency="AssignedByBuyer">00800077</ProductIdentifier>
    </ProductIdentification>
    <ShippedQuantity>
    <Measurement UnitOfMeasureCode="KGM">22500.000</Measurement>
    </ShippedQuantity>
    <PurchaseOrderNumber>
    <DocumentReference>
    <DocumentIdentifier1>2245264776</DocumentIdentifier1>
    <ReferenceItem>10</ReferenceItem>
    </DocumentReference>
    </PurchaseOrderNumber>
    <ProductSubLineItems>
    <SubLineItemNumber>2</SubLineItemNumber>
    <ManufacturingIdentificationDetails>
    <ManufacturingIdentificationTypeCode>Batch</ManufacturingIdentificationTypeCode>
    <ManufacturingIdentificationNumber>PUDOJTEST</ManufacturingIdentificationNumber>
    </ManufacturingIdentificationDetails>
    <NetWeight>
    <Measurement>10575.000</Measurement>
    </NetWeight>
    </ProductSubLineItems>
    </ProductLineItem>
    <ProductLineItem>
    <LineNumber>3</LineNumber>
    <ProductIdentification>
    <ProductIdentifier Domain="AssignedBySupplier" Agency="AssignedBySupplier">20000000000552171</ProductIdentifier>
    <ProductIdentifier Domain="AssignedByBuyer" Agency="AssignedByBuyer">20800077</ProductIdentifier>
    </ProductIdentification>
    <ShippedQuantity>
    <Measurement UnitOfMeasureCode="KGM">222500.000</Measurement>
    </ShippedQuantity>
    <PurchaseOrderNumber>
    <DocumentReference>
    <DocumentIdentifier1>22245264776</DocumentIdentifier1>
    <ReferenceItem>10</ReferenceItem>
    </DocumentReference>
    </PurchaseOrderNumber>
    <ProductSubLineItems>
    <SubLineItemNumber>3</SubLineItemNumber>
    <ManufacturingIdentificationDetails>
    <ManufacturingIdentificationTypeCode>2Batch</ManufacturingIdentificationTypeCode>
    <ManufacturingIdentificationNumber>2CIM_TEST04</ManufacturingIdentificationNumber>
    </ManufacturingIdentificationDetails>
    <NetWeight>
    <Measurement>211925.000</Measurement>
    </NetWeight>
    </ProductSubLineItems>
    </ProductLineItem>
    Basically I am counting the number of subline item segment in a single product line item. if its greater than 1 i need to split it into 2 individual pieces carrying over the rest of common segments too. And also i need to increment the LineNumber field too accordingly.

    So far i have only end up with the Counter process wherein i am able to get individual line item segments as seen below
    Code:
    <ShipNoticeDetails><ProductLineItem><LineNumber>1</LineNumber><ProductSubLineItems><SubLineItemNumber>1</SubLineItemNumber></ProductSubLineItems></ProductLineItem><ProductLineItem><LineNumber>2</LineNumber><ProductSubLineItems><SubLineItemNumber>2</SubLineItemNumber></ProductSubLineItems></ProductLineItem><ProductLineItem><LineNumber>3</LineNumber><ProductSubLineItems><SubLineItemNumber>3</SubLineItemNumber></ProductSubLineItems></ProductLineItem></ShipNoticeDetails>
    This was the XSL which i have used
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="xml" indent="yes"/>
    
    	<xsl:template match="@*|node()">
    		 <xsl:copy>
    			<xsl:apply-templates select="@*|node()"/>
    		 </xsl:copy>
    	</xsl:template>
    
    	<xsl:template match="ShipNoticeDetails">
    		    <xsl:copy>
    			
    	<xsl:call-template name="for.loop">
         <xsl:with-param name="i">1</xsl:with-param>
         <xsl:with-param name="count"><xsl:value-of select="count(.//ProductSubLineItems)"/></xsl:with-param>
        </xsl:call-template>
    		
    
    	    </xsl:copy>
    	</xsl:template>
    	
    	
    	<xsl:template name="for.loop">
    
       <xsl:param name="i"/>
       <xsl:param name="count"/>
    
       <!--begin_: Line_by_Line_Output -->
       <xsl:if test="$i &lt;= $count">
       <ProductLineItem>
        <LineNumber><xsl:value-of select="$i"/></LineNumber>
    	
    	
    	<ProductSubLineItems>
    	<SubLineItemNumber><xsl:value-of select="$i"/></SubLineItemNumber>
    	
    </ProductSubLineItems>
    	
    	</ProductLineItem>
       </xsl:if>
    
       <!--begin_: RepeatTheLoopUntilFinished-->
       <xsl:if test="$i &lt;= $count">
          <xsl:call-template name="for.loop">
              <xsl:with-param name="i">
                  <xsl:value-of select="$i + 1"/>
              </xsl:with-param>
              <xsl:with-param name="count">
                  <xsl:value-of select="$count"/>
              </xsl:with-param>
          </xsl:call-template>
       </xsl:if>
    
      </xsl:template>
    	
    
    </xsl:stylesheet>
    Can anyone please help with how to populate the remaining pieces. Any other logic to get the same output other than what i have used is also appreciated.
    </xsl:stylesheet>
    Last edited by Alex Vincent; 05-03-2012 at 06:28 PM. Reason: adding code tags

  • #2
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Small correction in the expected output

    Code:
    <ProductLineItem>
    <LineNumber>1</LineNumber>
    <ProductIdentification>
    <ProductIdentifier Domain="AssignedBySupplier" Agency="AssignedBySupplier">000000000000552171</ProductIdentifier>
    <ProductIdentifier Domain="AssignedByBuyer" Agency="AssignedByBuyer">00800077</ProductIdentifier>
    </ProductIdentification>
    <ShippedQuantity>
    <Measurement UnitOfMeasureCode="KGM">22500.000</Measurement>
    </ShippedQuantity>
    <PurchaseOrderNumber>
    <DocumentReference>
    <DocumentIdentifier1>2245264776</DocumentIdentifier1>
    <ReferenceItem>10</ReferenceItem>
    </DocumentReference>
    </PurchaseOrderNumber>
    <ProductSubLineItems>
    <SubLineItemNumber>1</SubLineItemNumber>
    <ManufacturingIdentificationDetails>
    <ManufacturingIdentificationTypeCode>Batch</ManufacturingIdentificationTypeCode>
    <ManufacturingIdentificationNumber>PUDOJTEST</ManufacturingIdentificationNumber>
    </ManufacturingIdentificationDetails>
    <NetWeight>
    <Measurement>10575.000</Measurement>
    </NetWeight>
    </ProductSubLineItems>
    </ProductLineItem>
    <ProductLineItem>
    <LineNumber>2</LineNumber>
    <ProductIdentification>
    <ProductIdentifier Domain="AssignedBySupplier" Agency="AssignedBySupplier">000000000000552171</ProductIdentifier>
    <ProductIdentifier Domain="AssignedByBuyer" Agency="AssignedByBuyer">00800077</ProductIdentifier>
    </ProductIdentification>
    <ShippedQuantity>
    <Measurement UnitOfMeasureCode="KGM">22500.000</Measurement>
    </ShippedQuantity>
    <PurchaseOrderNumber>
    <DocumentReference>
    <DocumentIdentifier1>2245264776</DocumentIdentifier1>
    <ReferenceItem>10</ReferenceItem>
    </DocumentReference>
    </PurchaseOrderNumber>
    <ProductSubLineItems>
    <SubLineItemNumber>2</SubLineItemNumber>
    <ManufacturingIdentificationDetails>
    <ManufacturingIdentificationTypeCode>Batch</ManufacturingIdentificationTypeCode>
    <ManufacturingIdentificationNumber>CIM_TEST04</ManufacturingIdentificationNumber></ManufacturingIdentificationDetails>
    <NetWeight>
    <Measurement>10575.000</Measurement>
    </NetWeight>
    </ProductSubLineItems>
    </ProductLineItem>
    <ProductLineItem>
    <LineNumber>3</LineNumber>
    <ProductIdentification>
    <ProductIdentifier Domain="AssignedBySupplier" Agency="AssignedBySupplier">20000000000552171</ProductIdentifier>
    <ProductIdentifier Domain="AssignedByBuyer" Agency="AssignedByBuyer">20800077</ProductIdentifier>
    </ProductIdentification>
    <ShippedQuantity>
    <Measurement UnitOfMeasureCode="KGM">222500.000</Measurement>
    </ShippedQuantity>
    <PurchaseOrderNumber>
    <DocumentReference>
    <DocumentIdentifier1>22245264776</DocumentIdentifier1>
    <ReferenceItem>10</ReferenceItem>
    </DocumentReference>
    </PurchaseOrderNumber>
    <ProductSubLineItems>
    <SubLineItemNumber>3</SubLineItemNumber>
    <ManufacturingIdentificationDetails>
    <ManufacturingIdentificationTypeCode>2Batch</ManufacturingIdentificationTypeCode>
    <ManufacturingIdentificationNumber>2CIM_TEST04</ManufacturingIdentificationNumber>
    </ManufacturingIdentificationDetails>
    <NetWeight>
    <Measurement>211925.000</Measurement>
    </NetWeight>
    </ProductSubLineItems>
    </ProductLineItem>
    Last edited by Alex Vincent; 05-03-2012 at 06:27 PM. Reason: adding code tags


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •