XSLT 1.0 Group By Tags

AbipseBraipse

New Member
I have the following XML data:\[code\] <result><row><CountryId>26</CountryId><CountryName>United Kingdom</CountryName><NoOfNights>1</NoOfNights><AccommodationID>6004</AccommodationID><RoomID>1</RoomID><RoomName>Double for Sole Use</RoomName><RatePlanID>1</RatePlanID><RoomRatePlan>Advance</RoomRatePlan><NoOfSameTypeRoom>0</NoOfSameTypeRoom><RoomSize/><Max_Person>1</Max_Person><RackRate>189</RackRate><CurrencySymbol>&pound;</CurrencySymbol><NoOfRoomsAvailable>4</NoOfRoomsAvailable><Rate>79.00</Rate><RatePerDay>27 Mar 2013_79.00</RatePerDay></row><row><CountryId>26</CountryId><CountryName>United Kingdom</CountryName><NoOfNights>1</NoOfNights><AccommodationID>6004</AccommodationID><RoomID>1</RoomID><RoomName>Double for Sole Use</RoomName><RatePlanID>2</RatePlanID><RoomRatePlan>Standard</RoomRatePlan><NoOfSameTypeRoom>0</NoOfSameTypeRoom><RoomSize/><Max_Person>1</Max_Person><RackRate>189</RackRate><CurrencySymbol>&pound;</CurrencySymbol><NoOfRoomsAvailable>5</NoOfRoomsAvailable><Rate>89.00</Rate><RatePerDay>27 Mar 2013_89.00</RatePerDay></row><row><CountryId>26</CountryId><CountryName>United Kingdom</CountryName><NoOfNights>1</NoOfNights><AccommodationID>6004</AccommodationID><RoomID>2</RoomID><RoomName>Double Room</RoomName><RatePlanID>1</RatePlanID><RoomRatePlan>Advance</RoomRatePlan><NoOfSameTypeRoom>0</NoOfSameTypeRoom><RoomSize/><Max_Person>2</Max_Person><RackRate>199</RackRate><CurrencySymbol>&pound;</CurrencySymbol><NoOfRoomsAvailable>5</NoOfRoomsAvailable><Rate>89.00</Rate><RatePerDay>27 Mar 2013_89.00</RatePerDay></row> </result>\[/code\]My XSLT for the above xml is this:\[code\]<?xml version="1.0" encoding="utf-8" ?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output omit-xml-declaration="yes" indent="yes" method="xml" /> <xsl:strip-space elements="*"/> <!-- Default template : ignore unrecognized elements and text --> <xsl:template match="*|text()" /> <!-- Match document root : add hotels element and process each children node of result --> <xsl:template match="/"> <hotels> <!-- We assume that the XML documents are always going to follow the structure: result as the root node and xml_acc elements as its children --> <xsl:for-each select="result/row"> <result> <hotel_rooms> <xsl:element name="hotel_id"> <xsl:value-of select="AccommodationID"/> </xsl:element> <xsl:apply-templates /> </hotel_rooms> <xsl:element name="Rate"> <xsl:element name="RoomRatePlan"> <xsl:value-of select="RoomRatePlan"/> </xsl:element> <xsl:element name="numeric_price"> <xsl:value-of select="Rate"/> </xsl:element> </xsl:element> </result> </xsl:for-each> </hotels> </xsl:template> <!-- Elements to be copied as they are --> <xsl:template match="NoOfNights|RoomName|RoomSize|Max_Person|RackRate|RatePerDay|CurrencySymbol|NoOfRoomsAvailable|RoomDescription|RoomFacilities|PolicyComments|Breakfast|Policy|Message"> <xsl:copy-of select="." /> </xsl:template> <xsl:template match="Photo_Max60"> <RoomImages> <Photo_Max60> <xsl:value-of select="." /> </Photo_Max60> <Photo_Max300> <xsl:value-of select="../Photo_Max300" /> </Photo_Max300> <Photo_Max500> <xsl:value-of select="../Photo_Max500" /> </Photo_Max500> </RoomImages> </xsl:template></xsl:stylesheet>\[/code\]In XSLT 1.0, I want to group by Room ID and Hotel ID . so in the above data, I Want the result like this.\[code\]<hotels> <result> <hotel_rooms> <hotel_id>6004</hotel_id> <NoOfNights>1</NoOfNights> <RoomID>1</RoomID> <RoomName>Double for Sole Use</RoomName> <RoomSize/> <Max_Person>1</Max_Person> <RackRate>189</RackRate> <CurrencySymbol>&pound;</CurrencySymbol> <NoOfRoomsAvailable>4</NoOfRoomsAvailable> <RatePerDay>27 Mar 2013_79.00</RatePerDay> </hotel_rooms> <Rate> <RoomRatePlan>Advance</RoomRatePlan> <numeric_price>79.00</numeric_price> <RoomRatePlan>Standard</RoomRatePlan> <numeric_price>89.00</numeric_price> </Rate> </result> </result> <hotels>\[/code\]I want a xslt file for the above xml output i need.please help..
 
Back
Top