XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Posttop
(Deleted User) 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"/>&#32;
<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>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text>&#32;</xsl:text>
<xsl:text>Arrive </xsl:text>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text>&#32;</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"/>&#32;
<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>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text>&#32;</xsl:text>
<xsl:text>Arrive </xsl:text>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text>&#32;</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"/>&#32;
<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>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text>&#32;</xsl:text>
<xsl:text>Arrive </xsl:text>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text>&#32;</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"/>&#32;
<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>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text>&#32;</xsl:text>
<xsl:text>Arrive </xsl:text>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text>&#32;</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"/>&#32;
<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>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text>&#32;</xsl:text>
<xsl:text>Arrive </xsl:text>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text>&#32;</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"/>&#32;
<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>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsDepart,$timeFormat)"/>
<xsl:text>&#32;</xsl:text>
<xsl:text>Arrive </xsl:text>&#32;&#32;
<xsl:text>&#32;</xsl:text>
<xsl:value-of select="ms:format-time(dtsArrive,$timeFormat)"/>
<xsl:text>&#32;</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


UnknownTrip-Translators.xslt
Code Fragment

UnknownReservation.xml
Reservation- Fragment

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.