<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="no"/>

	<xsl:template match="/">
		<Envelope>
			<xsl:for-each select="Envelope/Hotel">
				<xsl:sort select="min(RoomType/Room/Price/RoomPrice)" data-type="number" order="ascending"/>

				<!-- Start Copying everything -->
				<xsl:copy>
					<xsl:copy-of select="@*"/>
					<xsl:apply-templates mode="copy"/>
				</xsl:copy>
			</xsl:for-each>
		</Envelope>
	</xsl:template>

	<xsl:template match="@*|node()" mode="copy">

		<xsl:choose>
			<!-- First Room Type is reached -->
			<xsl:when test="string(node-name(.))='RoomType' and generate-id(.) = generate-id(../RoomType[1])">
				<xsl:for-each select="../RoomType">
					<xsl:sort select="min(Room/Price/RoomPrice)" data-type="number" order="ascending"/>
					<xsl:copy>
						<xsl:copy-of select="@*"/>
						<xsl:apply-templates mode="copy"/>
					</xsl:copy>
				</xsl:for-each>
			</xsl:when>

			<!-- First Room is reached -->
			<xsl:when test="string(node-name(.))='Room' and generate-id(.) = generate-id(../Room[1])">
				<xsl:for-each select="../Room">
					<xsl:sort select="min(Price/RoomPrice)" data-type="number" order="ascending"/>
					<xsl:copy>
						<xsl:copy-of select="@*"/>
						<xsl:apply-templates mode="copy"/>
					</xsl:copy>
				</xsl:for-each>
			</xsl:when>

			<!-- First Price is reached -->
			<xsl:when test="string(node-name(.))='Price' and generate-id(.) = generate-id(../Price[1])">
				<xsl:for-each select="../Price">
					<xsl:sort select="min(RoomPrice)" data-type="number" order="ascending"/>
					<xsl:copy>
						<xsl:copy-of select="@*"/>
						<xsl:apply-templates mode="copy"/>
					</xsl:copy>
				</xsl:for-each>
			</xsl:when>

			<!-- Ignore non-first repetitions -->
			<xsl:when test="string(node-name(.))='RoomType' or string(node-name(.))='Room' or string(node-name(.))='Price'"/>

			<!-- Simply copy all standard nodes -->
			<xsl:otherwise>
				<xsl:copy>
					<xsl:copy-of select="@*"/>
					<xsl:apply-templates mode="copy"/>
				</xsl:copy>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="test" userelativepaths="yes" externalpreview="no" url="test123.xml" htmlbaseurl="" outputurl="..\..\..\..\temp\test123.xml" processortype="saxon8" useresolver="yes" 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>
-->