Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 6th, 2012, 11:08 AM
Authorized User
 
Join Date: May 2009
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT 1 apply template help

Hi All,
I am kind of find it difficult to build my (xslt 1) template:

I have this following XML input:

Code:
<Ticket>

  <ItineraryItem>
                <Flight ArrivalDateTime="2012-08-31T09:40:00" DepartureDateTime="2012-08-31T06:00:00" DirectionInd="Outbound">
                    <DepartureAirport LocationCode="BRN"/>
                    <ArrivalAirport LocationCode="ZTH"/>
                    <OperatingAirline Code="2L" FlightNumber="5320"/>
                </Flight>
            </ItineraryItem>
            <ItineraryItem>
                <Flight ArrivalDateTime="2012-09-14T11:00:00" DepartureDateTime="2012-09-14T10:15:00" DirectionInd="Inbound">
                    <DepartureAirport LocationCode="ZTH"/>
                    <ArrivalAirport LocationCode="CFU"/>
                    <OperatingAirline Code="2L" FlightNumber="5321"/>
                </Flight>
            </ItineraryItem>
            <ItineraryItem>
                <Flight ArrivalDateTime="2012-09-14T12:40:00" DepartureDateTime="2012-09-14T11:40:00" DirectionInd="Inbound">
                    <DepartureAirport LocationCode="CFU"/>
                    <ArrivalAirport LocationCode="BRN"/>
                    <OperatingAirline Code="2L" FlightNumber="5321"/>
                </Flight>
            </ItineraryItem>


</Ticket>
And Have built the following template (xslt 1):

Code:
<xsl:template match="ota:Flight">
		<xsl:variable name="direction" select="@DirectionInd"/>
		<Fat ServiceType="T">
			<xsl:attribute name="SegRef">
				<xsl:if test="java:setIndex($rph_pos, java:getIndex($rph_pos) + 1)"/>
				<xsl:value-of select="format-number(java:getIndex($rph_pos) - 1,'000.#')"/>
			</xsl:attribute>
			<xsl:if test="../@Key">
				<xsl:attribute name="Key">
					<xsl:choose>
						<xsl:when test="ota:CabinAvailability/ota:Seat/@Code">
							<xsl:variable name="code" select="ota:CabinAvailability/ota:Seat/@Code"/>
							<xsl:value-of select="concat(substring(../@Key, 1, 10), $code, substring(../@Key, 12))"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="../@Key"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
			</xsl:if>
			<StartDate>
				<xsl:value-of select="datetime:format-date(substring(@DepartureDateTime, 1, 10), 'ddMMyyyy')"/>
			</StartDate>
			<Dep>
				<xsl:value-of select="ota:DepartureAirport/@LocationCode"/>
			</Dep>
			<Arr>
				<xsl:value-of select="ota:ArrivalAirport/@LocationCode"/>
			</Arr>
			<Persons>
				<xsl:value-of select="translate(ota:CabinAvailability/ota:PassengerRPHs/@ListOfPassengerRPH,' ', '')"/>
			</Persons>
		</Fat>

And it generates the following output:

Code:
<Request>
	<Fat ServiceType="T" SegRef="000">
		<StartDate>31082012</StartDate>
		<Dep>BRN</Dep>
		<Arr>ZTH</Arr>
		<Persons>12</Persons>
	</Fat>
	<Fat ServiceType="T" SegRef="001">
		<StartDate>14092012</StartDate>
		<Dep>ZTH</Dep>
		<Arr>CFU</Arr>
		<Persons>12</Persons>
	</Fat>
	<Fat ServiceType="T" SegRef="002">
		<StartDate>14092012</StartDate>
		<Dep>CFU</Dep>
		<Arr>BRN</Arr>
		<Persons>12</Persons>
	</Fat>
</Request>
Whereas I want an output to be like this:

Code:
<Request>
	<Fat ServiceType="T" SegRef="000">
		<StartDate>31082012</StartDate>
		<Dep>BRN</Dep>
		<Arr>ZTH</Arr>
		<Persons>12</Persons>
	</Fat>
	<Fat ServiceType="T" SegRef="001">
		<StartDate>14092012</StartDate>
		<Dep>ZTH</Dep>
		<Arr>BRN</Arr>
		<Persons>12</Persons>
	</Fat>
</Request>

That is to skip the intermediate flight, but only the start and end airports.

In this above case, The outbound flight is fine, but there are 2 Inbound flights. I just want the starting Inbound airport and the final Inbound airport in the return flight.

Similarly, there could be a scenario, where I have 2 Outbound flight, in that case the scenario woulc be the same that is the first Outboud flight and last Outboud flight.

Normal scenario with single Outbound and Inbound flight are only covered at the moment by my template above. That case should stay as it is in the revised template.

Your help in this regard should be highlly appreciated.

Thanks.

Last edited by sbutt; July 6th, 2012 at 11:19 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use recursive apply vs call template FXYLDY XSLT 2 June 15th, 2010 01:57 PM
How to apply template for the first w:p in w:tbl? senglory XSLT 11 January 31st, 2010 08:09 AM
Question on Apply Template vvenk XSLT 7 July 10th, 2008 12:21 PM
apply-template from included xslt stylesheet chobo XSLT 9 April 16th, 2008 05:25 PM
Difference between call-template ,apply-templates vikkiefd XSLT 4 March 12th, 2008 05:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.