1

I'm trying to transform an XML document using XSLT. I have got so far but I can't get the grouping level correct. I want each of the ASN numbers to have there own section. I've tried placing the For loops at different locations but no joy.

XML:-

<?xml version="1.0" encoding="utf-8"?>
<Orders>
	<Order>
		<och_contract>FO</och_contract>
		<SourceLocation>W235X</SourceLocation>
		<SourceLocationName>ARMSTRONG FASENINGS LTD</SourceLocationName>
		<DestinationLocation>3C</DestinationLocation>
		<och_type>P</och_type>
		<CollectionDate>20170814</CollectionDate>
		<Customer_Ref>FO-323296</Customer_Ref>
		<Plan_m3>3.60</Plan_m3>
		<Plan_Kgs>2500.00</Plan_Kgs>
		<Actual_M3>0.00</Actual_M3>
		<Actual_Kgs>0.00</Actual_Kgs>
		<och_trip_ref>IBHC0141733001H</och_trip_ref>
		<ASN_Numbers>
			<ASN>STU1234</ASN>
			<ASN>STU2345</ASN>
			<ASN>STU3456</ASN>
		</ASN_Numbers>
	</Order>
	<Order>
		<och_contract>FO</och_contract>
		<SourceLocation>A07LA</SourceLocation>
		<SourceLocationName>STOKES GROUP LTD</SourceLocationName>
		<DestinationLocation>3C</DestinationLocation>
		<och_type>P</och_type>
		<CollectionDate>20170817</CollectionDate>
		<Customer_Ref>FO-323430</Customer_Ref>
		<Plan_m3>2.88</Plan_m3>
		<Plan_Kgs>2500.00</Plan_Kgs>
		<Actual_M3>5.40</Actual_M3>
		<Actual_Kgs>14782.00</Actual_Kgs>
		<och_trip_ref>IBHC0491733004H</och_trip_ref>
		<ASN_Numbers>
			<ASN>ANDY1234</ASN>
			<ASN>ANDY2345</ASN>
			<ASN>ASN3456</ASN>
		</ASN_Numbers>
	</Order>
</Orders>

XSLT:-

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/apps/otm file:///C:/Users/andfishe/Documents/Projects/OTM%20Training/OTM/GLogXML_6.3.xsd">
	<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>
<xsl:template match="/">
<INVOICE>
			<xsl:call-template name="Invoice"/>
			<xsl:call-template name="Shipment"/>
</INVOICE>
</xsl:template>
<xsl:template name="Invoice">
<CARRIER_GSDB>V0K2Q</CARRIER_GSDB>
<INV_REF>6L027195</INV_REF>
</xsl:template>
<xsl:template name="Shipment">
<xsl:for-each select="Orders/Order">
<SHIPMENT>
<BILL_CURR>GBX</BILL_CURR>
	<STOP_GSDB>
		<xsl:value-of select="SourceLocation"/>
	</STOP_GSDB>
	
	<STOP_NAME>
		<xsl:value-of select="SourceLocationName"/>
	</STOP_NAME>
		<LINE_ITEM>
			<xsl:for-each select="ASN_Numbers">
				<ASN>
					<ASN_REF>
						<xsl:value-of select="ASN"/>
					</ASN_REF>
				</ASN>
			</xsl:for-each>
		</LINE_ITEM>
	
</SHIPMENT>
	</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Current Output:-

<?xml version="1.0" encoding="UTF-8"?>
<INVOICE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<CARRIER_GSDB>V0K2Q</CARRIER_GSDB>
	<INV_REF>6L027195</INV_REF>
	<SHIPMENT>
		<BILL_CURR>GBX</BILL_CURR>
		<STOP_GSDB>W235X</STOP_GSDB>
		<STOP_NAME>ARMSTRONG FASENINGS LTD</STOP_NAME>
		<LINE_ITEM>
			<ASN>
				<ASN_REF>STU1234 STU2345 STU3456</ASN_REF>
			</ASN>
		</LINE_ITEM>
	</SHIPMENT>
	<SHIPMENT>
		<BILL_CURR>GBX</BILL_CURR>
		<STOP_GSDB>A07LA</STOP_GSDB>
		<STOP_NAME>STOKES GROUP LTD</STOP_NAME>
		<LINE_ITEM>
			<ASN>
				<ASN_REF>ANDY1234 ANDY2345 ASN3456</ASN_REF>
			</ASN>
		</LINE_ITEM>
	</SHIPMENT>
</INVOICE>

I would like the LINE_ITEM section to look like:-

<?xml version="1.0" encoding="UTF-8"?>
<INVOICE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<CARRIER_GSDB>V0K2Q</CARRIER_GSDB>
	<INV_REF>6L027195</INV_REF>
	<SHIPMENT>
		<BILL_CURR>GBX</BILL_CURR>
		<STOP_GSDB>W235X</STOP_GSDB>
		<STOP_NAME>ARMSTRONG FASENINGS LTD</STOP_NAME>
		<LINE_ITEM>
			<ASN>
				<ASN_REF>STU1234</ASN_REF>
			</ASN>
			<ASN>
				<ASN_REF>STU2345</ASN_REF>
			</ASN>
			<ASN>
				<ASN_REF>STU3456</ASN_REF>
			</ASN>
		</LINE_ITEM>
	</SHIPMENT>
	<SHIPMENT>
		<BILL_CURR>GBX</BILL_CURR>
		<STOP_GSDB>A07LA</STOP_GSDB>
		<STOP_NAME>STOKES GROUP LTD</STOP_NAME>
		<LINE_ITEM>
			<ASN>
				<ASN_REF>ANDY1234</ASN_REF>
			</ASN>
			<ASN>
				<ASN_REF>ANDY2345</ASN_REF>
			</ASN>
			<ASN>
				<ASN_REF>ASN3456</ASN_REF>
			</ASN>
		</LINE_ITEM>
	</SHIPMENT>
</INVOICE>

Does anybody know how to acheive this please?

2 Answers 2

3
        <LINE_ITEM>
        <xsl:for-each select="ASN_Numbers/ASN">
            <ASN>
                <ASN_REF>                           
                    <xsl:value-of select="."/>
                </ASN_REF>
            </ASN>
        </xsl:for-each>
    </LINE_ITEM>
Sign up to request clarification or add additional context in comments.

Comments

1

Change this part:

<xsl:for-each select="ASN_Numbers">
    <ASN>
        <ASN_REF>
            <xsl:value-of select="ASN"/>
        </ASN_REF>
    </ASN>
</xsl:for-each>

to:

<xsl:for-each select="ASN_Numbers/ASN">
    <ASN>
        <ASN_REF>
            <xsl:value-of select="."/>
        </ASN_REF>
    </ASN>
</xsl:for-each>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.