|
top
|
 Subject: HELP: Functional XSLT Implementation of Arrays Author: (Deleted User) Date: 10 Mar 2008 11:14 PM Originally Posted: 10 Mar 2008 11:01 PM
|
I'm new to XSLT. I have a problem implementing arrays. Below is a sample code.
<!-- The purpose is to display The Reservation Details such as : The Passenger's Outgoing Trip , Stops and Incoming Trip and Stops. The Trips may vary, it depends on the customer. Thanks in advance. ^_^ -->
***********************************************************************
<!--Code Below May not be necessarily correct as I am still working on it. Please enlighten.-->
***********************************************************************
<tr>
<xsl:variable name="Trips" select="count(/Reservations/TripServices)"/>
<xsl:choose>
<xsl:when test="count($Trips)>1">
<xsl:for-each select="Reservations/TripServices[1]">
<xsl:variable name="SubTrip" select="count(/Reservations/TripServices/Trip/Stops)"/>
<xsl:choose>
<!--When greater than 1-->
<xsl:when test="count($SubTrip)>1">
<xsl:variable name="j" select ="count($SubTrip)"/>
<!--loop through each Stop-->
<xsl:for-each select="/Stops/Stop[$j]">
<td width="250px">
<strong>Out Going Trip</strong>
<br/>
<xsl:value-of select="PassengerDetail/BusNo"/> 
<xsl:value-of select="PassengerDetail/TravelNo"/>
<br/>
<!--<xsl:value-of select="concat((ArrivalStation, $EmptyString), ' (', ArrivalStation, ')')"/>-->
<!--<xsl:value-of select='concat(DepartureStation,,"-",ArrivalStation)'/>-->
<xsl:variable name ="DepartTerminal" select="DepartureStation," >
</xsl:variable>
<xsl:variable name ="ArriveTerminal" select="ArrivalStation" >
</xsl:variable>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$DepartTerminal" />
</xsl:call-template>
<xsl:text>-</xsl:text>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$ArriveTerminal" />
</xsl:call-template>
<br/>
<!--<xsl:value-of select="ms:format-date($timeFormat,$dtsArrive)"/>-->
<!--<xsl:value-of select= "ms:format-date($timeFormat,$dtsDepart)"/>-->
<xsl:value-of select="ms:format-date(dtsDepart,$dateFormat)"/>
<br/>
<xsl:text>Depart </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text> </xsl:text>
<xsl:text>Arrive </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text> </xsl:text>
<br/>
<br/>
<xsl:if test="count($SubTrip)>1">
</xsl:if>
</td>
</xsl:for-each>
<!--loop through each Sub Trips/Stops-->
</xsl:when>
<!--WhenSubTripis greater than 1-->
<xsl:otherwise>
<td width="250px">
<strong>Out Going Trip</strong>
<br/>
<xsl:value-of select="PassengerDetail/BusNo"/> 
<xsl:value-of select="PassengerDetail/TravelNo"/>
<br/>
<!--<xsl:value-of select="concat((ArrivalStation, $EmptyString), ' (', ArrivalStation, ')')"/>-->
<!--<xsl:value-of select='concat(DepartureStation,,"-",ArrivalStation)'/>-->
<xsl:variable name ="DepartTerminal" select="DepartureStation," >
</xsl:variable>
<xsl:variable name ="ArriveTerminal" select="ArrivalStation" >
</xsl:variable>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$DepartTerminal" />
</xsl:call-template>
<xsl:text>-</xsl:text>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$ArriveTerminal" />
</xsl:call-template>
<br/>
<!--<xsl:value-of select="ms:format-date($timeFormat,$dtsArrive)"/>-->
<!--<xsl:value-of select= "ms:format-date($timeFormat,$dtsDepart)"/>-->
<xsl:value-of select="ms:format-date(dtsDepart,$dateFormat)"/>
<br/>
<!--<xsl:value-of select='concat("Depart"," ",ms:format-date($timeFormat,$dtsDepart),"Arive","",ms:format-date($timeFormat,$dtsArrive))'/>-->
<xsl:text>Depart </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text> </xsl:text>
<xsl:text>Arrive </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text> </xsl:text>
<br/>
<br/>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="/Reservations/TripServices/Trip[2]">
<xsl:choose>
<!--WhenSubTripis greater than 1-->
<xsl:when test="count($SubTrip)>1">
<xsl:variable name="j" select ="count($SubTrip)"/>
<!--loop through each Sub Trips/Stops-->
<xsl:for-each select="Stops/Stop[$j]">
<td width="250px">
<strong>IncomingTrip</strong>
<br/>
<xsl:value-of select="PassengerDetail/BusNo"/> 
<xsl:value-of select="PassengerDetail/TravelNo"/>
<br/>
<!--<xsl:value-of select="concat((ArrivalStation, $EmptyString), ' (', ArrivalStation, ')')"/>-->
<!--<xsl:value-of select='concat(DepartureStation,,"-",ArrivalStation)'/>-->
<xsl:variable name ="DepartTerminal" select="DepartureStation," >
</xsl:variable>
<xsl:variable name ="ArriveTerminal" select="ArrivalStation" >
</xsl:variable>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$DepartTerminal" />
</xsl:call-template>
<xsl:text>-</xsl:text>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$ArriveTerminal" />
</xsl:call-template>
<br/>
<!--<xsl:value-of select="ms:format-date($timeFormat,$dtsArrive)"/>-->
<!--<xsl:value-of select= "ms:format-date($timeFormat,$dtsDepart)"/>-->
<xsl:value-of select="ms:format-date(dtsDepart,$dateFormat)"/>
<br/>
<!--<xsl:value-of select='concat("Depart"," ",ms:format-date($timeFormat,$dtsDepart),"Arive","",ms:format-date($timeFormat,$dtsArrive))'/>-->
<xsl:text>Depart </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text> </xsl:text>
<xsl:text>Arrive </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text> </xsl:text>
<br/>
<br/>
<xsl:if test="$j >1"></xsl:if>
</td>
</xsl:for-each>
<!--loop through each Sub Trips/Stops-->
</xsl:when>
<!--WhenSubTripis greater than 1-->
<xsl:otherwise>
<td width="250px">
<strong>IncomingTrip</strong>
<br/>
<xsl:value-of select="PassengerDetail/BusNo"/> 
<xsl:value-of select="PassengerDetail/TravelNo"/>
<br/>
<!--<xsl:value-of select="concat((ArrivalStation, $EmptyString), ' (', ArrivalStation, ')')"/>-->
<!--<xsl:value-of select='concat(DepartureStation,,"-",ArrivalStation)'/>-->
<xsl:variable name ="DepartTerminal" select="DepartureStation," >
</xsl:variable>
<xsl:variable name ="ArriveTerminal" select="ArrivalStation" >
</xsl:variable>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$DepartTerminal" />
</xsl:call-template>
<xsl:text>-</xsl:text>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$ArriveTerminal" />
</xsl:call-template>
<br/>
<!--<xsl:value-of select="ms:format-date($timeFormat,$dtsArrive)"/>-->
<!--<xsl:value-of select= "ms:format-date($timeFormat,$dtsDepart)"/>-->
<xsl:value-of select="ms:format-date(dtsDepart,$dateFormat)"/>
<br/>
<xsl:text>Depart </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text> </xsl:text>
<xsl:text>Arrive </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text> </xsl:text>
<br/>
<br/>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<!--When Tripis greater than 1-->
<xsl:otherwise>
<xsl:for-each select="Reservations/TripServices[1]">
<xsl:choose>
<!--When Sub Trip is greater than 1-->
<xsl:when test="count($SubTrip)>1">
<xsl:variable name="j" select ="count($SubTrip)"/>
<!--loop through each Sub Trips/Stops-->
<xsl:for-each select="Stops/Stop[$j]">
<td width="250px">
<strong>Out Going Trip</strong>
<br/>
<xsl:value-of select="PassengerDetail/BusNo"/> 
<xsl:value-of select="PassengerDetail/TravelNo"/>
<br/>
<!--<xsl:value-of select="concat((ArrivalStation, $EmptyString), ' (', ArrivalStation, ')')"/>-->
<!--<xsl:value-of select='concat(DepartureStation,,"-",ArrivalStation)'/>-->
<xsl:variable name ="DepartTerminal" select="DepartureStation," >
</xsl:variable>
<xsl:variable name ="ArriveTerminal" select="ArrivalStation" >
</xsl:variable>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$DepartTerminal" />
</xsl:call-template>
<xsl:text>-</xsl:text>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$ArriveTerminal" />
</xsl:call-template>
<br/>
<!--<xsl:value-of select="ms:format-date($timeFormat,$dtsArrive)"/>-->
<!--<xsl:value-of select= "ms:format-date($timeFormat,$dtsDepart)"/>-->
<xsl:value-of select="ms:format-date(dtsDepart,$dateFormat)"/>
<br/>
<!--<xsl:value-of select='concat("Depart"," ",ms:format-date($timeFormat,$dtsDepart),"Arive","",ms:format-date($timeFormat,$dtsArrive))'/>-->
<xsl:text>Depart </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text> </xsl:text>
<xsl:text>Arrive </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text> </xsl:text>
<br/>
<br/>
<xsl:if test="$j >1"></xsl:if>
</td>
</xsl:for-each>
<!--loop through each Stop-->
</xsl:when>
<!--When Sub Trip is greater than 1-->
<xsl:otherwise>
<td width="250px">
<strong>Out Going Trip</strong>
<br/>
<xsl:value-of select="PassengerDetail/BusNo"/> 
<xsl:value-of select="PassengerDetail/TravelNo"/>
<br/>
<!--<xsl:value-of select="concat((ArrivalStation, $EmptyString), ' (', ArrivalStation, ')')"/>-->
<!--<xsl:value-of select='concat(DepartureStation,,"-",ArrivalStation)'/>-->
<xsl:variable name ="DepartTerminal" select="DepartureStation," >
</xsl:variable>
<xsl:variable name ="ArriveTerminal" select="ArrivalStation" >
</xsl:variable>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$DepartTerminal" />
</xsl:call-template>
<xsl:text>-</xsl:text>
<xsl:call-template name="ConvertStationCode">
<xsl:with-param name="CityCode" select ="$ArriveTerminal" />
</xsl:call-template>
<br/>
<!--<xsl:value-of select="ms:format-date($timeFormat,$dtsArrive)"/>-->
<!--<xsl:value-of select= "ms:format-date($timeFormat,$dtsDepart)"/>-->
<xsl:value-of select="ms:format-date(dtsDepart,$dateFormat)"/>
<br/>
<!--<xsl:value-of select='concat("Depart"," ",ms:format-date($timeFormat,$dtsDepart),"Arive","",ms:format-date($timeFormat,$dtsArrive))'/>-->
<xsl:text>Depart </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text> </xsl:text>
<xsl:text>Arrive </xsl:text>  
<xsl:text> </xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text> </xsl:text>
<br/>
<br/>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</tr>
***********************************************************************
Sample XML File
<?xml version="1.0" encoding="utf-8" ?>
<Reservations>
<ReservationsID>192D1278</ReservationsID>
<ReferenceID />
<ReservationStatus>Default</ReservationStatus>
<ReservationReferenceID>0@0h$891WWVV**1!</ReservationReferenceID>
<ReservedPassengers>
<ReservedPassenger>
<State>Default</State>
<PassengerNumber />
<PassengerNumber>0</PassengerNumber>
<Name>
<Title>MR</Title>
<FirstName>Raphael</FirstName>
<MiddleName>D.</MiddleName>
<LastName>Crisanto</LastName>
</Name>
<PasPriceKind>
<PasType/>
</PasPriceKind>
<PassengerFees />
<PassengerPenaltyFees />
<PassengerID>50574540</PassengerID>
<FamilyNumber>0</FamilyNumber>
<ResidentCountry>US</ResidentCountry>
<TotalCost>17668.00000</TotalCost>
<BalanceDue>0</BalanceDue>
<PassengerMinor>
<PassengerID>0</PassengerID>
<DTSB>
9999-12-31T00:00:00Z</DTSB>
<Gender>Male</Gender>
<Nationality />
<ResidentCountry />
<Name>
<Title />
<FirstName />
<MiddleName />
<LastName />
<Suffix />
</Name>
</PassengerMinor>
</ReservedPassenger>
<ReservedPassenger>
<State>Default</State>
<PassengerNumber />
<PassengerNumber>0</PassengerNumber>
<Name>
<Title>Mrs</Title>
<FirstName>Grace</FirstName>
<MiddleName>T.</MiddleName>
<LastName>Hilton</LastName>
</Name>
<PasPriceKind>
<PasType/>
</PasPriceKind>
<PassengerFees />
<PassengerPenaltyFees />
<PassengerID>50574541</PassengerID>
<FamilyNumber>0</FamilyNumber>
<ResidentCountry>US</ResidentCountry>
<TotalCost>17668.00000</TotalCost>
<BalanceDue>0</BalanceDue>
<PassengerMinor>
<PassengerID>0</PassengerID>
<DTSB>9999-12-31T00:00:00Z</DTSB>
<Gender>Male</Gender>
<Nationality />
<ResidentCountry />
<Name>
<Title />
<FirstName />
<MiddleName />
<LastName />
<Suffix />
</Name>
</PassengerMinor>
</ReservedPassenger>
<ReservedPassenger>
<State>Pending</State>
<PassengerNumber />
<PassengerNumber>0</PassengerNumber>
<Name>
<Title>Mr.</Title>
<FirstName>Clint</FirstName>
<MiddleName>T.</MiddleName>
<LastName>Crisanto</LastName>
</Name>
<PasPriceKind>
<PasType/>
</PasPriceKind>
<PassengerFees />
<PassengerPenaltyFees />
<PassengerID>50574542</PassengerID>
<FamilyNumber>0</FamilyNumber>
<ResidentCountry>US</ResidentCountry>
<TotalCost>17668.00000</TotalCost>
<BalanceDue>0</BalanceDue>
<PassengerMinor>
<PassengerID>0</PassengerID>
<DTSB>9999-12-31T00:00:00Z</DTSB>
<Gender>Male</Gender>
<Nationality />
<ResidentCountry />
<Name>
<Title />
<FirstName />
<MiddleName />
<LastName />
<Suffix />
</Name>
</PassengerMinor>
</ReservedPassenger>
</ReservedPassengers>
<TripServices>
<Trip>
<Stops>
<Stop>
<DepartureStation>ABCCity</DepartureStation>
<dtsDepart>2008-03-22T12:25:00</dtsDepart>
<ArrivalStation>ABCStopCity1</ArrivalStation>
<dtsArrive>2008-03-22T13:15:00</dtsArrive>
<PassengerDetail>
<BusNo>TEA123</BusNo>
<TravelNo>900</TravelNo>
</PassengerDetail>
</Stop>
<Stop>
<DepartureStation>ABCStopCity2</DepartureStation>
<dtsDepart>2008-03-22T20:55:00</dtsDepart>
<ArrivalStation>DEFCity</ArrivalStation>
<dtsArrive>2008-03-23T00:35:00</dtsArrive>
<PassengerDetail>
<BusNo>TEA123</BusNo>
<TravelNo>900</TravelNo>
</PassengerDetail>
</Stop>
</Stops>
<NotForGeneralUse>false</NotForGeneralUse>
<Fares>
<Fare>
<TypeOfService>Y</TypeOfService>
<RuleTariff />
<BusNo />
<RuleNumber />
<FareBasis />
</Fare>
</Fares>
<TripClasses />
</Trip>
</TripServices>
<TripServices>
<Trip>
<Stops>
<Stop>
<DepartureStation>GHICity</DepartureStation>
<dtsDepart>2008-03-22T12:25:00</dtsDepart>
<ArrivalStation>GHICityStop1</ArrivalStation>
<dtsArrive>2008-03-22T13:15:00</dtsArrive>
<PassengerDetail>
<BusNo>TEA123</BusNo>
<TravelNo>900</TravelNo>
</PassengerDetail>
</Stop>
<Stop>
<DepartureStation>GHICityStop1</DepartureStation>
<dtsDepart>2008-03-22T20:55:00</dtsDepart>
<ArrivalStation>GHICity</ArrivalStation>
<dtsArrive>2008-03-23T00:35:00</dtsArrive>
<PassengerDetail>
<BusNo>TEA123</BusNo>
<TravelNo>900</TravelNo>
</PassengerDetail>
</Stop>
<Stop>
<DepartureStation>ABCStopCity1</DepartureStation>
<dtsDepart>2008-03-22T12:25:00</dtsDepart>
<ArrivalStation>ABCSCityAgain</ArrivalStation>
<dtsArrive>2008-03-22T13:15:00</dtsArrive>
<PassengerDetail>
<BusNo>TEA123</BusNo>
<TravelNo>900</TravelNo>
</PassengerDetail>
</Stop>
</Stops>
<NotForGeneralUse>false</NotForGeneralUse>
<Fares>
<Fare>
<TypeOfService>Y</TypeOfService>
<RuleTariff />
<BusNo />
<RuleNumber />
<FareBasis />
</Fare>
</Fares>
<TripClasses />
</Trip>
</TripServices>
</Reservations>
**********************************************************************************************************************************************
"The reason of our purpose is the purpose of our reason" - eeginakiyuckudon
Trip-Translators.xslt Code Fragment
Reservation.xml Reservation- Fragment
|
|
|
|