We help IT Professionals succeed at work.
Get Started

INABLE TO DISPLAY THE REQUIRED OUTUT PROPERLY USING XML AND XSL.

497 Views
Last Modified: 2013-11-18
I am having an xml file with some flights information.using xsl,i want to display airline ticket.

i want to display flight information in the form of a ticket.

the airline ticket should look like:
         
frankfurt UL 0554  22.11 18.00   22.11 23.59
Columbo   UL 0553  06.12 20.00   06.12 23.59
franfurt
-VOID-
-VOID-

But i am getting output as
frankfurt UL 0554  22.11 18.00   22.11 23.59
Columbo   UL 0553  06.12 20.00   06.12 23.59



each row is a salesorderserviceitem in my xml file.
for ex,if i am going from frankfurt to columbo and back,then my ticket looks as

frankfurt UL 0554  22.11 18.00   22.11 23.59
Columbo   UL 0553  06.12 20.00   06.12 23.59
frankfurt
-VOID-
-VOID-

i mean i have to check whether any stops in bettween my source and destination.
if there are stops in between suppose frankfurt-singapore-columbo and back then.

then i am expecting outout as:

(departure)(airlinecode)(flightnumber)(dep date)(dep time)      (arrivaldate)(arrivaltime)        

frankfurt    UL 0554  22.11 18.00    22.11    23.59
singapore   UL 0553  06.12 20.00   06.12   23.59
columbo   UL 0556  07.12 20.00      07.12   23.59
singapore   UL 0551  08.12 20.00   08.12    23.59
frankfurt

i the above ticket,each row is an salesorderservice item.
i think i have to change the logic in only with <xsl:for-each> line in my xsl file.


Thanks for your help.
vihar123


------------------------------------
my xml file:
<?xml version="1.0" encoding="utf-16"?>
<SalesOrder Date="2003-08-11">
   <Services>
      <SalesOrderService>
         <ServiceItems>
            <SalesOrderServiceItem  DateFrom="2003-11-22" DateUntil="2003-11-22">
               <Unit>
                  <UnitDetails AirlineCode="UL" FlightNumber="0554" Direction="Outbound" DepartureTime="18.00" ArrivalTime="23:59" AddDays="0">
                     <DepartureAirport Code="FRA" Name="Frankfurt" City="" Country="" ID="606">
                        <Locations/>
                     </DepartureAirport>
                     <ArrivalAirport Code="CMB" Name="Colombo" City="" Country="" ID="568">
                        <Locations/>
                     </ArrivalAirport>
                  </UnitDetails>
               </Unit>
            </SalesOrderServiceItem>
            <SalesOrderServiceItem  DateFrom="2003-12-06" DateUntil="2003-12-06">
               <Unit>
                  <UnitDetails AirlineCode="UL" FlightNumber="0553" Direction="Return" DepartureTime="20.00" ArrivalTime="23:59" AddDays="0">
                     <DepartureAirport Code="CMB" Name="Colombo" City="" Country="" ID="568">
                        <Locations/>
                        <Annotation>
                           <TranslatableText Language="EN"/>
                        </Annotation>
                        <Description>
                           <TranslatableText Language="EN"/>
                        </Description>
                     </DepartureAirport>
                     <ArrivalAirport Code="FRA" Name="Frankfurt" City="" Country="" ID="606">
                        <Locations/>
                     </ArrivalAirport>
                  </UnitDetails>
               </Unit>
            </SalesOrderServiceItem>
         </ServiceItems>
      </SalesOrderService>
      <SalesOrderService>
         <ServiceItems>
            <SalesOrderServiceItem>
               <Unit>
                  <UnitDetails nil="true"/>
               </Unit>
            </SalesOrderServiceItem>
            <SalesOrderServiceItem>
               <Unit>
                  <UnitDetails nil="true"/>
               </Unit>
            </SalesOrderServiceItem>
            <SalesOrderServiceItem>
               <Unit>
                  <UnitDetails nil="true"/>
               </Unit>
            </SalesOrderServiceItem>
         </ServiceItems>
      </SalesOrderService>
      <SalesOrderService>
         <ServiceItems>
            <SalesOrderServiceItem>
               <Unit>
                  <UnitDetails nil="true"/>
               </Unit>
            </SalesOrderServiceItem>
         </ServiceItems>
      </SalesOrderService>
   </Services>
</SalesOrder>
---------------------------
my xsl file:


<?xml version="1.0" encoding="UTF-16" ?>
<xsl:stylesheet version="1.0"

            xmlns:fo="http://www.w3.org/1999/XSL/Format"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:ms="urn:schemas-microsoft-com:xslt">

<xsl:template name="ticket_body">
<fo:table width="18cm">
<fo:table-column column-width="13cm"/>
<fo:table-column column-width="5cm"/>

<fo:table-body>

<fo:table-row height="3cm">
<fo:table-cell>
<fo:block>

<fo:table width="13cm">

                  <fo:table-column column-width="4.8cm"/>
                  <fo:table-column column-width="1cm"/>
                  <fo:table-column column-width="1cm"/>
                  <fo:table-column column-width="0.7cm"/>
                  <fo:table-column column-width="1.2cm"/>
                  <fo:table-column column-width="1.2cm"/>
                  <fo:table-column column-width="1cm"/>
                  <fo:table-column column-width="0.5cm"/>
                  <fo:table-column column-width="3cm"/>
                  <fo:table-column column-width="1.2cm"/>
                  <fo:table-column column-width="1.2cm"/>
                  <fo:table-column column-width="1.2cm"/>

                  <fo:table-body>
                        <fo:table-row height="0.5cm">
                              <fo:table-cell/>
                        </fo:table-row>

      

                  <xsl:for-each select="/SalesOrder/Services/SalesOrderService/ServiceItems/SalesOrderServiceItem">
                        <fo:table-row height="0.5cm">
                              <fo:table-cell>
                                    <fo:block>
                                          <xsl:value-of select="Unit/UnitDetails/DepartureAirport/@Name"/>
                                    </fo:block>
                              </fo:table-cell>
                              <fo:table-cell>
                                    <fo:block>
                                          <xsl:value-of select="Unit/UnitDetails/@AirlineCode"/>
                                    </fo:block>
                              </fo:table-cell>
                              <fo:table-cell>
                                    <fo:block>
                                          <xsl:value-of select="Unit/UnitDetails/@FlightNumber"/>
                                    </fo:block>
                              </fo:table-cell>
                              <fo:table-cell>
                                    <fo:block>
                                          <xsl:if test="Unit/UnitDetails/DepartureAirport/@Name !=''">
                                            Y<!--xsl:value-of select="Unit/UnitDetails/@Class"/-->
                                           </xsl:if>
                                    </fo:block>
                              </fo:table-cell>
                              <fo:table-cell>
                                    <fo:block>
                                          <xsl:if test="Unit/UnitDetails/DepartureAirport/@Name !=''">
                                           <xsl:value-of select="substring(@DateFrom,9,2)"/>.<xsl:value-of select="substring(@DateFrom,6,2)"/>
                                          </xsl:if>
                                    </fo:block>
                              </fo:table-cell>
                              <fo:table-cell>
                                    <fo:block>
                                          <xsl:value-of select="Unit/UnitDetails/@DepartureTime"/>
                                    </fo:block>
                              </fo:table-cell>
                              <fo:table-cell>
                                    <fo:block>
                                          <xsl:if test="Unit/UnitDetails/DepartureAirport/@Name !=''">
                                           OK<!--xsl:value-of select="Unit/UnitDetails/@Status"/-->
                                          </xsl:if>
                                    </fo:block>
                              </fo:table-cell>
                              <fo:table-cell>
                                    <fo:block>
                                          <xsl:if test="Unit/UnitDetails/DepartureAirport/@Name !=''">
                                            [N]
                                          </xsl:if>
                                    </fo:block>
                              </fo:table-cell>
                              <fo:table-cell>
                                    <fo:block>

                                    </fo:block>
                              </fo:table-cell>
                              <fo:table-cell>
                                    <fo:block>
                                          <xsl:if test="Unit/UnitDetails/DepartureAirport/@Name !=''">
                                           <xsl:value-of select="substring(@DateUntil,9,2)"/>.<xsl:value-of select="substring(@DateUntil,6,2)"/>
                                        </xsl:if>
                                    </fo:block>
                              </fo:table-cell>
                              <fo:table-cell>
                                    <fo:block>
                                          <xsl:value-of select="Unit/UnitDetails/@ArrivalTime"/>
                                    </fo:block>
                              </fo:table-cell>
                              <fo:table-cell>
                                    <fo:block>
                                       <xsl:if test="Unit/UnitDetails/DepartureAirport/@Name !=''">
                                           12<!--for weight-->
                                       </xsl:if>
                                    </fo:block>
                              </fo:table-cell>
                        </fo:table-row>

                  <!--/xsl:for-each-->

                  </xsl:for-each>
                  </fo:table-body>

            </fo:table>

      </xsl:template>

</xsl:stylesheet>
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE