XSL Question....

Hi,
I need to get this following output xml from the XSL file for this source XML document. I have attached the source xml and the output xml. As you can see from the output:

<Accommodation RPH="1">
Should be depend on the:
<Anteeo>
             <Accommodation>
                                <ItemNo> 1     </ItemNo>
                                <ProductCode> BURAPX-FIT</ProductCode>

For each new ItemNo and ProductCode  should produce a new <Accommodation RPH="2"> with RPH value increase by 1. Also depend on the <Passenger>
                                                                                         <ItemNo>1</ItemNo>
will determine which room each passenger will be occupying as ItemNo will represent roomno and <PassengerListItem RPH="1">
RPH will increase by one for each passenger in the passengerListItem.
BookRequestSourceXML.xml
OutputXML.xml
ube100Asked:
Who is Participating?
 
Geert BormansConnect With a Mentor Information ArchitectCommented:
something like this?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    xmlns:ota="http://www.opentravel.org/OTA/2003/05"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:key name="pas" match="Passenger" use="ItemNo"/>
    <xsl:key name="acco" match="Accommodation" use="ProductCode"/>
    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes"/>
    <xsl:template match="Anteeo">
        <xsl:element name="OTA_PkgBookRQ" namespace="http://www.opentravel.org/OTA/2003/05">
            <xsl:element name="PackageRequest" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:attribute name="ID">
                    <xsl:text>REF00001</xsl:text>
                </xsl:attribute>
                <xsl:attribute name="ShortDescription">
                    <xsl:text>Y</xsl:text>
                </xsl:attribute>
                <xsl:element name="ItineraryItems" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:apply-templates select="Accommodation[generate-id() = generate-id(key('acco', ProductCode)[1])]"/>
                </xsl:element>
            </xsl:element>            
            <xsl:element name="PassengerListItems" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:apply-templates select="Passenger"/>
            </xsl:element>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="Accommodation">
        <xsl:element name="ItineraryItem" namespace="http://www.opentravel.org/OTA/2003/05">
            <xsl:element name="Accommodation" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:attribute name="RPH">
                    <xsl:value-of select="position()"/>
                </xsl:attribute>
                <xsl:element name="Identity" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:attribute name="HotelCode">
                        <xsl:value-of select="ProductCode"/>
                    </xsl:attribute>
                </xsl:element>
                <xsl:element name="DateRange" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:attribute name="Start">
                        <xsl:value-of select="StartDate"/>
                    </xsl:attribute>
                    <xsl:attribute name="Duration">
                        <xsl:text>P0Y0M</xsl:text>
                        <xsl:value-of select="Duration"/>
                        <xsl:text>D</xsl:text>
                    </xsl:attribute>
                </xsl:element>
                <xsl:element name="RoomProfiles" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:for-each select="key('acco', ProductCode)">
                        <xsl:element name="RoomProfile" namespace="http://www.opentravel.org/OTA/2003/05">
                            <xsl:attribute name="Configuration">
                                <xsl:value-of select="GDSID"/>
                            </xsl:attribute>
                            <xsl:element name="PassengerRPHs" namespace="http://www.opentravel.org/OTA/2003/05">
                                <xsl:element name="PassengerRPH" namespace="http://www.opentravel.org/OTA/2003/05">
                                    <xsl:attribute name="RPH">
                                        <xsl:value-of select="key('pas', ItemNo)/PsgrNum"/>
                                    </xsl:attribute>
                                </xsl:element>
                            </xsl:element>
                        </xsl:element>
                    </xsl:for-each>
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template>

    <xsl:template match="Passenger">
        <xsl:element name="PassengerListItem" namespace="http://www.opentravel.org/OTA/2003/05">
            <xsl:attribute name="RPH">
                <xsl:value-of select="ItemNo"/>
            </xsl:attribute>
            <xsl:element name="Name" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:element name="GivenName" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:value-of select="FirstName"/>
                </xsl:element>
                <xsl:element name="Surname" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:value-of select="LastName"/>
                </xsl:element>
                <xsl:element name="NameTitle" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:value-of select="Title"/>
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    xmlns:ota="http://www.opentravel.org/OTA/2003/05"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:key name="pas" match="Passenger" use="ItemNo"/>
    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes"/>
    <xsl:template match="Anteeo">
        <xsl:element name="OTA_PkgBookRQ" namespace="http://www.opentravel.org/OTA/2003/05">
            <xsl:element name="PackageRequest" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:attribute name="ID">
                    <xsl:text>REF00001</xsl:text>
                </xsl:attribute>
                <xsl:attribute name="ShortDescription">
                    <xsl:text>Y</xsl:text>
                </xsl:attribute>
                <xsl:element name="ItineraryItems" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:apply-templates select="Accommodation"/>
                </xsl:element>
            </xsl:element>            
            <xsl:element name="PassengerListItems" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:apply-templates select="Passenger"/>
            </xsl:element>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="Accommodation">
        <xsl:element name="ItineraryItem" namespace="http://www.opentravel.org/OTA/2003/05">
            <xsl:element name="Accommodation" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:attribute name="RPH">
                    <xsl:value-of select="ItemNo"/>
                </xsl:attribute>
                <xsl:element name="Identity" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:attribute name="HotelCode">
                        <xsl:value-of select="ProductCode"/>
                    </xsl:attribute>
                </xsl:element>
                <xsl:element name="DateRange" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:attribute name="Start">
                        <xsl:value-of select="StartDate"/>
                    </xsl:attribute>
                    <xsl:attribute name="Duration">
                        <xsl:text>P0Y0M</xsl:text>
                        <xsl:value-of select="Duration"/>
                        <xsl:text>D</xsl:text>
                    </xsl:attribute>
                </xsl:element>
                <xsl:element name="RoomProfiles" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:element name="RoomProfile" namespace="http://www.opentravel.org/OTA/2003/05">
                        <xsl:attribute name="Configuration">
                            <xsl:value-of select="GDSID"/>
                        </xsl:attribute>
                        <xsl:element name="PassengerRPHs" namespace="http://www.opentravel.org/OTA/2003/05">
                            <xsl:element name="PassengerRPH" namespace="http://www.opentravel.org/OTA/2003/05">
                                <xsl:attribute name="RPH">
                                    <xsl:value-of select="key('pas', ItemNo)/PsgrNum"/>
                                </xsl:attribute>
                            </xsl:element>
                        </xsl:element>
                    </xsl:element>
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template>

    <xsl:template match="Passenger">
        <xsl:element name="PassengerListItem" namespace="http://www.opentravel.org/OTA/2003/05">
            <xsl:attribute name="RPH">
                <xsl:value-of select="ItemNo"/>
            </xsl:attribute>
            <xsl:element name="Name" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:element name="GivenName" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:value-of select="FirstName"/>
                </xsl:element>
                <xsl:element name="Surname" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:value-of select="LastName"/>
                </xsl:element>
                <xsl:element name="NameTitle" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:value-of select="Title"/>
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
As always... it is hard to implement the exact logic of your specification based on the source and the result XML, since they seem to have no relation to each other
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ube100Author Commented:
Gertone,

Thanks for that but there should be few things you should be aware:
<Accommodation RPH="1"> &&  <Accommodation RPH="2">
These Should be:  <Accommodation RPH="1"> and both roomprofile should be under these node since the Hotelcode is:  <Identity HotelCode="BURAPX-FIT" /> same for both as we have to create new accommodation only when we have new itemno and hotelcode (compsite key). However, If you have different hotel code then you would have been right but on this case both the hotel codes are same.

hope I have made it clear so you can follow me.
0
 
Geert BormansInformation ArchitectCommented:
Please be more carefull with your specs
your original question says
> For each new ItemNo and ProductCode  
and in your follow up you say
> have new itemno and hotelcode (compsite key).

and the example you post has
  <Accommodation>
    <ItemNo>1</ItemNo>
    <ProductCode>BURAPX-FIT</ProductCode>
...
  <Accommodation>
    <ItemNo>2</ItemNo>
    <ProductCode>BURAPX-FIT</ProductCode>

not really the same composite key???

And as I said, nothing in your example in and output tells me how to relate them really, because they don't match.
You post question after question whilst constantly changing your mind, your specifications and your data...
I am about to simply give up on your questions
0
 
ube100Author Commented:
Gertone,

Sorry If I mislead you. This is the scenario. If we have the same hotel code then we need to create one accommodation and will have all the rooms under the room profile with RPH set to increase by one for each rooms. When we have a different hotel code then we will have a different accommodation and the rooms underneath it. I hope I made it clear, please don't give up on this as I need your help finish this off.
0
 
Geert BormansInformation ArchitectCommented:
Anyway, here is the XSLT according to your specs. I had to make up my own source data to test it.
I hope I have the references right... but that is all I can give without a clear and decent set of specs
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    xmlns:ota="http://www.opentravel.org/OTA/2003/05"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:key name="pas" match="Passenger" use="ItemNo"/>
    <xsl:key name="acco-by-item" match="Accommodation" use="ItemNo"/>
    <xsl:key name="acco" match="Accommodation" use="concat(ProductCode, '#', ItemNo)"/>
    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes"/>
    <xsl:template match="Anteeo">
        <xsl:element name="OTA_PkgBookRQ" namespace="http://www.opentravel.org/OTA/2003/05">
            <xsl:element name="PackageRequest" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:attribute name="ID">
                    <xsl:text>REF00001</xsl:text>
                </xsl:attribute>
                <xsl:attribute name="ShortDescription">
                    <xsl:text>Y</xsl:text>
                </xsl:attribute>
                <xsl:element name="ItineraryItems" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:apply-templates select="Accommodation[generate-id() = generate-id(key('acco', concat(ProductCode, '#', ItemNo))[1])]"/>
                </xsl:element>
            </xsl:element>            
            <xsl:element name="PassengerListItems" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:apply-templates select="Passenger"/>
            </xsl:element>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="Accommodation">
        <xsl:element name="ItineraryItem" namespace="http://www.opentravel.org/OTA/2003/05">
            <xsl:element name="Accommodation" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:attribute name="RPH">
                    <xsl:value-of select="position()"/>
                </xsl:attribute>
                <xsl:element name="Identity" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:attribute name="HotelCode">
                        <xsl:value-of select="ProductCode"/>
                    </xsl:attribute>
                </xsl:element>
                <xsl:element name="DateRange" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:attribute name="Start">
                        <xsl:value-of select="StartDate"/>
                    </xsl:attribute>
                    <xsl:attribute name="Duration">
                        <xsl:text>P0Y0M</xsl:text>
                        <xsl:value-of select="Duration"/>
                        <xsl:text>D</xsl:text>
                    </xsl:attribute>
                </xsl:element>
                <xsl:element name="RoomProfiles" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:for-each select="key('acco', concat(ProductCode, '#', ItemNo))">
                        <xsl:element name="RoomProfile" namespace="http://www.opentravel.org/OTA/2003/05">
                            <xsl:attribute name="Configuration">
                                <xsl:value-of select="GDSID"/>
                            </xsl:attribute>
                            <xsl:element name="PassengerRPHs" namespace="http://www.opentravel.org/OTA/2003/05">
                                <xsl:element name="PassengerRPH" namespace="http://www.opentravel.org/OTA/2003/05">
                                    <xsl:attribute name="RPH">
                                        <xsl:value-of select="key('pas', ItemNo)/PsgrNum"/>
                                    </xsl:attribute>
                                </xsl:element>
                            </xsl:element>
                        </xsl:element>
                    </xsl:for-each>
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template>

    <xsl:template match="Passenger">
        <xsl:element name="PassengerListItem" namespace="http://www.opentravel.org/OTA/2003/05">
            <xsl:attribute name="RPH">
                <xsl:value-of select="count(key('acco-by-item', ItemNo)/preceding-sibling::Accommodation[generate-id() = generate-id(key('acco', concat(ProductCode, '#', ItemNo))[1])]) + 1"/>
            </xsl:attribute>
            <xsl:element name="Name" namespace="http://www.opentravel.org/OTA/2003/05">
                <xsl:element name="GivenName" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:value-of select="FirstName"/>
                </xsl:element>
                <xsl:element name="Surname" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:value-of select="LastName"/>
                </xsl:element>
                <xsl:element name="NameTitle" namespace="http://www.opentravel.org/OTA/2003/05">
                    <xsl:value-of select="Title"/>
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
Well, our messages crossed.
I have a look at that, but don't promise anything for today.
I have some other work to do now
0
 
Geert BormansInformation ArchitectCommented:
Do I need to number starting from one, within each hotel?
Or can the numbering continue...
It is a clear advantage if the numbering can continue, since the numbering would then still be unique per room,
and the references between passengers and hotelroom can be kept. so would be my recommendation

One other thing
you want the same hotel but different bookings in different accommodation
but that would mean that the start date and the duration are outside the container for the actual booking.
That is weird, can I assume that these dates will always be the same within a Anteo?

Or would startdate and duration be another part of the composite key?
0
 
ube100Author Commented:
Yes numbering can continue.
No, All will be under a same booking but can be different accommodation and the startdate and the duration will be same for all the accommodation under the any particular booking.
0
 
ube100Author Commented:
Gertone,

<Accommodation RPH="2">
          <Identity HotelCode="BURAPX-FIT" />
          <DateRange Start="08-Jan-2010" Duration="P0Y0M7D" />
          <RoomProfiles>
            <RoomProfile Configuration="3">
              <PassengerRPHs>
                <PassengerRPH RPH="" />
              </PassengerRPHs>
            </RoomProfile>
          </RoomProfiles>
        </Accommodation>

As you can see from above this:      <PassengerRPH RPH="" /> Should be this:
     <PassengerRPH RPH="2" />

And this:  <PassengerListItem RPH="1">
      <Name>
        <GivenName>Mythili</GivenName>
        <Surname>Ubendran</Surname>
        <NameTitle>Mrs</NameTitle>
      </Name>

Should be this:

<PassengerListItem RPH="2">
      <Name>
        <GivenName>Mythili</GivenName>
        <Surname>Ubendran</Surname>
        <NameTitle>Mrs</NameTitle>
      </Name>
0
 
ube100Author Commented:
Gertone,

This is not producing the RPH=?

<RoomProfiles>
            <RoomProfile Configuration="">
              <PassengerRPHs>
                <PassengerRPH RPH="" />
              </PassengerRPHs>
            </RoomProfile>
          </RoomProfiles>
bookingsource.xml
0
 
ube100Author Commented:
Sorry, I have missed the xsl file:
XSLTFile3.xml
0
 
ube100Author Commented:
Itemno is changed to TMSNum so I made all the appropriate changes in the XSL file but still it is not producing the RPH for   <PassengerRPH RPH="" />
Please advice me as I have tried to fix it but all in vain.
0
 
ube100Author Commented:
Thanks!
0
 
Geert BormansInformation ArchitectCommented:
As you can see in your source, the string value for the identifiers is not the same : '01' vs. '1'
So you need to cast to numbers first
Here is the correcte stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
	xmlns:ota="http://www.opentravel.org/OTA/2003/05"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:key name="pas" match="Passenger" use="number(TMSNum)"/>
	<xsl:key name="acco" match="Accommodation" use="ProductCode"/>
	<xsl:strip-space elements="*"/>
	<xsl:output indent="yes"/>
	<xsl:template match="Anteeo">
		<xsl:element name="OTA_PkgBookRQ">
			<xsl:element name="PackageRequest" >
				<xsl:attribute name="ID">
					<xsl:text>REF00001</xsl:text>
				</xsl:attribute>
				<xsl:attribute name="ShortDescription">
					<xsl:text>Y</xsl:text>
				</xsl:attribute>
				<xsl:element name="ItineraryItems" >
					<xsl:apply-templates select="Accommodation[generate-id() = generate-id(key('acco', ProductCode)[1])]"/>
				</xsl:element>
			</xsl:element>
			<xsl:element name="PassengerListItems" >
				<xsl:apply-templates select="Passenger"/>
			</xsl:element>
		</xsl:element>
	</xsl:template>
	
	<xsl:template match="Accommodation">
		<xsl:element name="ItineraryItem">
			<xsl:element name="Accommodation">
				<xsl:attribute name="RPH">
					<xsl:value-of select="position()"/>
				</xsl:attribute>
				<xsl:element name="Identity">
					<xsl:attribute name="HotelCode">
						<xsl:value-of select="ProductCode"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="DateRange">
					<xsl:attribute name="Start">
						<xsl:value-of select="StartDate"/>
					</xsl:attribute>
					<xsl:attribute name="Duration">
						<xsl:text>P0Y0M</xsl:text>
						<xsl:value-of select="Duration"/>
						<xsl:text>D</xsl:text>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="RoomProfiles" >
					<xsl:for-each select="key('acco', ProductCode)">
						<xsl:element name="RoomProfile" >
							<xsl:attribute name="Configuration">
								<xsl:value-of select="GDSID"/>
							</xsl:attribute>
							<xsl:element name="PassengerRPHs" >
								<xsl:element name="PassengerRPH" >
									<xsl:attribute name="RPH">
										<xsl:value-of select="key('pas', number(ItemNo))/PsgrNum"/>
									</xsl:attribute>
								</xsl:element>
							</xsl:element>
						</xsl:element>
					</xsl:for-each>
				</xsl:element>
			</xsl:element>
		</xsl:element>
	</xsl:template>
	
	<xsl:template match="Passenger">
		<xsl:element name="PassengerListItem" >
			<xsl:attribute name="RPH">
				<xsl:value-of select="TMSNum"/>
			</xsl:attribute>
			<xsl:element name="Name" >
				<xsl:element name="GivenName">
					<xsl:value-of select="FirstName"/>
				</xsl:element>
				<xsl:element name="Surname" >
					<xsl:value-of select="LastName"/>
				</xsl:element>
				<xsl:element name="NameTitle" >
					<xsl:value-of select="Title"/>
				</xsl:element>
			</xsl:element>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.