<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="/">
		<root>
			<xsl:for-each select="root/row">
				<!-- This little trick generates an ID from the first and current node, and only one time they will match(first time) -->
				<xsl:if test="generate-id(.) = generate-id(../row[purchase_order = current()/purchase_order])">
					<xsl:variable name="PO" select="purchase_order"/>

					<PurchaseOrder>
						<!-- HEADER -->
						<header>
							<PO>
								<xsl:value-of select="$PO"/>
							</PO>
							<business_unit>
								<xsl:value-of select="business_unit"/>
							</business_unit>
							<!-- HEADER/VENDOR -->
							<vendor>
								<vendor_id>
									<xsl:value-of select="vendor_id"/>
								</vendor_id>
								<vendor_name>
									<xsl:value-of select="vendor_name"/>
								</vendor_name>
							</vendor>
						</header>

						<!-- Now we select all the rows with the same Purchaseordernumber and map the itmeinformations -->
						<xsl:for-each select="../row[purchase_order=$PO]">
							<item>
								<line_item>
									<xsl:value-of select="line_item"/>
								</line_item>
								<description_1>
									<xsl:value-of select="description_1"/>
								</description_1>
								<unit_price>
									<xsl:value-of select="unit_price"/>
								</unit_price>
							</item>
						</xsl:for-each>
					</PurchaseOrder>
				</xsl:if>
			</xsl:for-each>
		</root>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="test.xml" htmlbaseurl="" outputurl="" processortype="custom" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="java Xi30Xslt %1 %2 %3" additionalpath="" additionalclasspath="${classpath};C:\Program Files\Stylus Studio 2007 XML Enterprise Suite\bin\xi30xslt.jar;\\Itg01\all\Appl_Dev\Swarovski_Konzept_&amp;_Design\Projekte\XI Setup\EDI Migration\Tools\SwaTools\SwaTools.jar;\\Itg01\all\Appl_Dev\Swarovski_Konzept_&amp;_Design\Projekte\XI Setup\EDI Migration\Tools\SeeTools\SeeFunctionsXI.jar;\\Itg01\all\Appl_Dev\Swarovski_Konzept_&amp;_Design\Projekte\XI Setup\EDI Migration\Tools\SeeTools\SeeXICommonCollection.jar" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/><scenario default="no" name="Scenario2" userelativepaths="yes" externalpreview="no" url="..\Desktop" htmlbaseurl="" outputurl="" processortype="custom" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="java Xi30Xslt %1 %2 %3" additionalpath="" additionalclasspath="${classpath};C:\Program Files\Stylus Studio 2007 XML Enterprise Suite\bin\xi30xslt.jar;\\Itg01\all\Appl_Dev\Swarovski_Konzept_&amp;_Design\Projekte\XI Setup\EDI Migration\Tools\SwaTools\SwaTools.jar;\\Itg01\all\Appl_Dev\Swarovski_Konzept_&amp;_Design\Projekte\XI Setup\EDI Migration\Tools\SeeTools\SeeFunctionsXI.jar;\\Itg01\all\Appl_Dev\Swarovski_Konzept_&amp;_Design\Projekte\XI Setup\EDI Migration\Tools\SeeTools\SeeXICommonCollection.jar" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->