DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: Train table

  1. #1
    Join Date
    Sep 2009
    Posts
    1

    Exclamation Train table

    Hi.

    I am quite new to xml, and I am trying to create a xml file that contains a train table.

    I am however unsure how to do this. The table must contain different stops, train numbers, routes and times.

    How can I do this in a way so I can later extract f.ex the stop times on a certain route for a given street.

    F.ex I have train number 67 that goes from Berlin to Munich, with stops in Frankfurt and Köln. And I have train number 65 that goes from Copenhagen to Munich with stop in Kôln.

    How can i organize this in a xml file so that I later can extract all departures by all trains from Köln, or all departures by train number 67 and so on.

    If there are any germans in here, i appologize for my bad geography skills. I just used these cities as an example ;-)

  2. #2
    Join Date
    May 2009
    Posts
    60
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <trainlist>
        <train no="67" startstation="Berlin" outtime="6:15" destinationstation="Munich" intime="14:15">
            <connectingstation intime="10:00" outtime="10:15">Frankfurt</connectingstation>
            <connectingstation intime="9:00" outtime="9:15">Cologne</connectingstation>
        </train>
        <train no="65" startstation="Copenhagen" outtime="6:15" destinationstation="Munich" intime="14:15">
            <connectingstation intime="10:00" outtime="10:15">Cologne</connectingstation>
        </train>
        <train no="65" startstation="Copenhagen" outtime="6:15" destinationstation="Munich" intime="14:15">
        </train>
    </trainlist>
    make a html table use xsl

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:output indent="yes" method="html"/>
        <xsl:template match="/">
            <html>
                <xsl:apply-templates select="trainlist">
                    <xsl:sort select="train/@no"/>
                </xsl:apply-templates>
            </html>
        </xsl:template>
        <xsl:template match="trainlist">
            <table border="3px solid">
                <xsl:apply-templates select="train"/>
            </table>
        </xsl:template>
        <xsl:template match="train">
            <tr>
                <td>
                    <xsl:text>Stationnr.</xsl:text>
                </td>
                <td colspan="2">
                    <xsl:text>Trainnr. </xsl:text>
                    <xsl:value-of select="@no"/>
                </td>
                <td><xsl:text>  in</xsl:text></td>
                <td><xsl:text> out</xsl:text></td>
            </tr>
            <tr>
                <td>
                    <xsl:value-of select="1"/>
                </td>
                <td colspan="2">
                    <xsl:value-of select="@startstation"/>
                </td>
                <td/>
                <td>
                    <xsl:value-of select="@outtime"/>
                </td>
            </tr>
            <xsl:if test="connectingstation">
                <xsl:apply-templates select="connectingstation">
                    <xsl:sort select="translate(@intime,':','')" data-type="number"/>
                    <xsl:with-param name="no" select="1"/>
                </xsl:apply-templates>
            </xsl:if>
            <tr>
                <td>
                    <xsl:value-of select="count(child::*)+2"/>
                </td>
                <td colspan="2">
                    <xsl:value-of select="@destinationstation"/>
                </td>
                <td>
                    <xsl:value-of select="@intime"/>
                </td>
                <td/>
            </tr>
        </xsl:template>
        <xsl:template match="connectingstation">
            <xsl:param name="no"/>
            <tr>
                <td>
                    <xsl:value-of select="position()+$no"/>
                </td>
                <td colspan="2">
                    <xsl:value-of select="."/>
                </td>
                <td>
                    <xsl:value-of select="@intime"/>
                </td>
                <td>
                    <xsl:value-of select="@outtime"/>
                </td>
            </tr>
        </xsl:template>
    
    </xsl:stylesheet>
    result

    Code:
    <html>
       <table border="3px solid">
          <tr>
             <td>Stationnr.</td>
             <td colspan="2">Trainnr. 67</td>
             <td>  in</td>
             <td> out</td>
          </tr>
          <tr>
             <td>1</td>
             <td colspan="2">Berlin</td>
             <td></td>
             <td>6:15</td>
          </tr>
          <tr>
             <td>2</td>
             <td colspan="2">Cologne</td>
             <td>9:00</td>
             <td>9:15</td>
          </tr>
          <tr>
             <td>3</td>
             <td colspan="2">Frankfurt</td>
             <td>10:00</td>
             <td>10:15</td>
          </tr>
          <tr>
             <td>4</td>
             <td colspan="2">Munich</td>
             <td>14:15</td>
             <td></td>
          </tr>
          <tr>
             <td>Stationnr.</td>
             <td colspan="2">Trainnr. 65</td>
             <td>  in</td>
             <td> out</td>
          </tr>
          <tr>
             <td>1</td>
             <td colspan="2">Copenhagen</td>
             <td></td>
             <td>6:15</td>
          </tr>
          <tr>
             <td>2</td>
             <td colspan="2">Cologne</td>
             <td>10:00</td>
             <td>10:15</td>
          </tr>
          <tr>
             <td>3</td>
             <td colspan="2">Munich</td>
             <td>14:15</td>
             <td></td>
          </tr>
          <tr>
             <td>Stationnr.</td>
             <td colspan="2">Trainnr. 65</td>
             <td>  in</td>
             <td> out</td>
          </tr>
          <tr>
             <td>1</td>
             <td colspan="2">Copenhagen</td>
             <td></td>
             <td>6:15</td>
          </tr>
          <tr>
             <td>2</td>
             <td colspan="2">Munich</td>
             <td>14:15</td>
             <td></td>
          </tr>
       </table>
    </html>

Similar Threads

  1. Database Design Help needed
    By Brian Pittman in forum Database
    Replies: 2
    Last Post: 04-29-2007, 08:23 AM
  2. query tuning
    By dhaya in forum Database
    Replies: 11
    Last Post: 08-25-2003, 05:24 PM
  3. Attn: Daniel Reber
    By joe in forum Database
    Replies: 0
    Last Post: 04-04-2003, 05:25 PM
  4. Re: (No subject)
    By Joe in forum Database
    Replies: 0
    Last Post: 04-04-2003, 05:13 PM
  5. Replies: 2
    Last Post: 04-13-2000, 01:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links