?
Solved

XSL Question....

Posted on 2010-01-01
16
Medium Priority
?
314 Views
Last Modified: 2013-11-18
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
0
Comment
Question by:ube100
  • 8
  • 8
16 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26159061

<?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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26159072
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
 

Author Comment

by:ube100
ID: 26159260
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26161188
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
 

Author Comment

by:ube100
ID: 26161227
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26161230
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26161234
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26161257
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
 

Author Comment

by:ube100
ID: 26161320
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
 

Author Comment

by:ube100
ID: 26161484
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
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 26161754
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
 

Author Comment

by:ube100
ID: 26165734
Gertone,

This is not producing the RPH=?

<RoomProfiles>
            <RoomProfile Configuration="">
              <PassengerRPHs>
                <PassengerRPH RPH="" />
              </PassengerRPHs>
            </RoomProfile>
          </RoomProfiles>
bookingsource.xml
0
 

Author Comment

by:ube100
ID: 26165736
Sorry, I have missed the xsl file:
XSLTFile3.xml
0
 

Author Comment

by:ube100
ID: 26165748
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
 

Author Closing Comment

by:ube100
ID: 31671841
Thanks!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26166698
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question