I originally posted back in Feb. 2011 about needing to transform one xml file with another xml file.. thinking it would be a straight one for one transformation... but of course, it can't remain that easy! I now have to take multiple line items from the input file based on an invoice number and use those to transform my output purchase order with the correct line items.
So taking the input file... something like this
<EInvoice>
<EID>
<EInvoiceData>
<InvoiceDate>1070108</InvoiceDate>
<CustomerNumber>4638501</CustomerNumber>
<InvoiceNumber>59925</InvoiceNumber>
<LineItem>100</LineItem>
<XRef>LPS3015-472MLC</XRef>
<CustPartNumber>3644882</CustPartNumber>
<ShipQty>3000.000</ShipQty>
<TotalTaxAmt>.00</TotalTaxAmt>
<UnitPrice>.2500000</UnitPrice>
<CustOrdNumber>22852462</CustOrdNumber>
<Terms>90</Terms>
<Total>750.00</Total>
</EInvoiceData>
</EID>
<EID>
<EInvoiceData>
<InvoiceDate>1070108</InvoiceDate>
<CustomerNumber>4638501</CustomerNumber>
<InvoiceNumber>59925</InvoiceNumber>
<LineItem>200</LineItem>
<XRef>LSS3014-401MLC</XRef>
<CustPartNumber>3643482</CustPartNumber>
<ShipQty>3000.000</ShipQty>
<TotalTaxAmt>.00</TotalTaxAmt>
<UnitPrice>.2500000</UnitPrice>
<CustOrdNumber>22852462</CustOrdNumber>
<Terms>90</Terms>
<Total>750.00</Total>
</EInvoiceData>
</EID>
<EID>
<EInvoiceData>
<InvoiceDate>2011-04-05</InvoiceDate>
<CustomerNumber>4638501</CustomerNumber>
<OrderNumber>1065143</OrderNumber>
<InvoiceNumber>164403</InvoiceNumber>
<LineItem>100</LineItem>
<XRef>DA2415-AL</XRef>
<CustPartNumber>3647976</CustPartNumber>
<ShipQty>1000.000</ShipQty>
<TotalTaxAmt>.00</TotalTaxAmt>
<UnitPrice>4.0000000</UnitPrice>
<CustOrdNumber>22751100</CustOrdNumber>
<Terms>90</Terms>
<Total>4000.00</Total>
</EInvoiceData>
</EID>
</EInvoice>
It will have multiple xml segments of invoice data... some from the same invoice, some from other invoices. The xml segments from the same invoice will be in order together... so I have been looping through the whole xml file looking for common invoice number and grabbing all line items associated with an invoice number. The tricky part is taking that information and using xsl to transform the output, to include those loops on the output purchase order end. Should I be able to add a for-each select to loop through each line item as long as it has the same invoice number associated with it? Can I use that inside the template match statement?
I do this template match and apply template select sequence for each tag on in the output file I want to transform with data from the input file.
<xsl:template match="/">
<xsl:apply-templates select="EInvoiceData"/>
</xsl:template>
<xsl:template match="EInvoiceData" >
<tns:InvoiceNotification>
<tns:Invoice>
<tns:BillFrom>
<xsl:apply-templates select="CustOrdNumber" />
</tns:BillFrom>
</tns:Invoice>
</tns:InvoiceNotification>
</xsl:template>
<xsl:template match="CustOrdNumber" >
<tns:PurchaseOrderNumber>
<dp:Identifier>
<xsl:value-of select="." />
</dp:Identifier>
</tns:PurchaseOrderNumber>
</xsl:template>
Here's what I would like to see on the output end...some of the tags are static... but the line items from the input file need to loop from <InvoiceLineItem> to </InvoiceLineItem> in the output file.
output for each line item segment... values supplied from my static template and from the input file tags associated with each output tag - this whole xml segment will need to be transformed and in place for each line item associated with an invoice:
- <tns:InvoiceLineItem>
<tns:LineNumber>100</tns:LineNumber>
- <tns:OrderStatus>
- <tns:PurchaseOrder>
- <tns:ProductLineItem>
<tns:CountryOfOrigin>US</tns:CountryOfOrigin>
<tns:LineNumber>100</tns:LineNumber>
- <tns:ProductDescription>
- <updi:ProductIdentification>
<updi:ProductName>LPS3015-472MLC</updi:ProductName>
<ulc:Identifier>3644882</ulc:Identifier>
</updi:ProductIdentification>
</tns:ProductDescription>
<sha:ProductQuantity>3000.000</sha:ProductQuantity>
<ucr:Currency>USD</ucr:Currency>
<uuom:UnitOfMeasure>PIE</uuom:UnitOfMeasure>
- <tns:UnitPrice>
<ume:Amount>.2500000</ume:Amount>
<ucr:Currency>USD</ucr:Currency>
</tns:UnitPrice>
</tns:ProductLineItem>
- <tns:PurchaseOrderNumber>
<dp:Identifier>22852462</dp:Identifier>
<dp:Line>100</dp:Line>
</tns:PurchaseOrderNumber>
</tns:PurchaseOrder>
</tns:OrderStatus>
- <tns:PreTaxAmount>
- <ume:FinancialAmount>
<ume:Amount>750.00</ume:Amount>
<ucr:Currency>USD</ucr:Currency>
</ume:FinancialAmount>
- <tns:TotalLineItemAmount>
- <ume:FinancialAmount>
<ume:Amount>750.00</ume:Amount>
<ucr:Currency>USD</ucr:Currency>
</ume:FinancialAmount>
</tns:TotalLineItemAmount>
</tns:InvoiceLineItem>