Skip to main content

Restructuring products data using multiple loop elements

The following scenario creates a four-component Job that restructures the products data from an XML source file ProductsIn.xml using multiple loop elements.

For more technologies supported by Talend, see Talend components.

These four components are:

  • tFileInputXML: reads the source products data and passes it to the tXMLMap component.

  • tXMLMap: transforms the input flow to the expected structure streamlined.

  • tLogRow: presents the execution result on the console.

  • tFileOutputXML: writes the output flow into an XML file.

The content of the source XML file ProductsIn.xml is as follows:

<?xml version="1.0" encoding="ISO-8859-15"?>
<products category="1" name="laptop">

	<!-- Summary -->
	<summary>
		<company>DELL, HP</company>
		<sales unit="Dollars">12345678910.12345</sales>
		<model>business</model>
	</summary>

	<!-- Loop1 manufacture -->
	<manufacture id="manu_1" date="2012-10-30">
		<name>DELL</name>
	</manufacture>
	<manufacture id="manu_2" date="2012-10-28">
		<name>HP</name>
	</manufacture>

	<!-- Loop2 types -->
	<types model="business1">
		<type>DELL123</type>
		<manufacture_id>manu_1</manufacture_id>
	</types>
	<types model="business2">
		<type>HP123</type>
		<manufacture_id>manu_2</manufacture_id>
	</types>

	<!-- Loop3 sale -->
	<sales>
		<sale unit="Dollars" type="DELL123">
			<quater>1</quater>
			<income>12345</income>
		</sale>
		<sale unit="Dollars" type="HP123">
			<quater>1</quater>
			<income>12345.123</income>
		</sale>
	</sales>
</products>

The objective of this scenario is to restructure the products data to streamline the presentation of the products information to serve the manufacturing operations. The expected output data is as follows. The root element is changed to manufacturers, the sales information is consolidated into the sale element, and the manufacturer element is reduced to one single level.

<?xml version="1.0" encoding="ISO-8859-15"?>
<manufacturers category="1" name="laptop">
  <sales unit="Dollars">
    <sale sales_type="DELL123">12345.0</sale>
    <sale sales_type="HP123">12345.123</sale>
  </sales>
  <manufacturer id="manu_1" date="03-04-0036" name="DELL"/>
  <manufacturer id="manu_2" date="04-04-0034" name="HP"/>
  <types>
    <type>DELL123</type>
    <manufacturer_id>manu_1</manufacturer_id>
  </types>
  <types>
    <type>DELL123</type>
    <manufacturer_id>manu_2</manufacturer_id>
  </types>
  <types>
    <type>HP123</type>
    <manufacturer_id>manu_1</manufacturer_id>
  </types>
  <types>
    <type>HP123</type>
    <manufacturer_id>manu_2</manufacturer_id>
  </types>
</manufacturers>

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!