Jump to content

XSLT apply template help


sbutt
 Share

Recommended Posts

Hi All, I am kind of find it difficult to build my (xslt 1) template: I have this following XML input:

 <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):

 <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:

 <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:

 <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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...