Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9298213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:16:00+00:00 2026-06-18T22:16:00+00:00

I need to create a table in html from an XSLT file, but selecting

  • 0

I need to create a table in html from an XSLT file, but selecting only a specific group of nodes. For example in the following XML I wish to select all of the from and to child nodes where routename contains fco-dxb:

<?xml version="1.0" encoding="UTF-8"?>

<flights
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="flights.xsd">

<flight flightid="1">
    <flightno>EK98</flightno>
    <callsign>UAE98</callsign>
    <airline>Emirates Airline</airline>

    <plane planeid="1">
        <name>Airbus A380-861</name>

        <registereddate>07-06-10</registereddate>
    </plane>


    <registration>3A6-EDJ</registration>
    <altitude height="feet">41000</altitude>
    <speed ratio="mph">564</speed>
    <distance unit="miles">erf</distance>

    <route>
    <routename>FCO-DXB</routename>
        <from>
            <iatacode>FCO</iatacode>
            <airport>Fiumicino</airport>
            <country>Italy</country>
            <city>Rome</city>
            <latitude>41.8044</latitude>
            <longitude>12.2508</longitude>
        </from>

        <to>
            <iatacode>DXB</iatacode>
            <airport>Dubai Intl</airport>
            <country>United Arab Emirates</country>
            <city>Dubai</city>
            <latitude>25.2528</latitude>
            <longitude>55.3644</longitude>
        </to>
    </route>

    <course bearing="degrees">154</course>

    <journey>
        <distance type="miles">2,697</distance> 
        <time>PT5H30M</time>
    </journey>

</flight>


<flight flightid="2">
    <flightno>BA283</flightno>
    <callsign>BAW283</callsign>
    <airline>British Airways</airline>

    <plane planeid="2">
        <name>Boeing 747-436</name>
        <registereddate>06-12-97</registereddate>
    </plane>


    <registration>3A6-EDJ</registration>
    <altitude height="feet">41000</altitude>
    <speed ratio="mph">564</speed>
    <distance unit="miles">erf</distance>

    <route>
    <routename>LHR-LAX</routename>
        <from>
            <iatacode>LHR</iatacode>
            <airport>Heathrow</airport>
            <country>England</country>
            <city>London</city>
            <latitude>51.4775</latitude>
            <longitude>0.4614</longitude>
        </from>

        <to>
            <iatacode>LAX</iatacode>
            <airport>Los Angeles International</airport>
            <country>United States of America</country>
            <city>L.A</city>
            <latitude>33.9471</latitude>
            <longitude>-118.4082</longitude>
        </to>
    </route>

    <course bearing="degrees">154</course>

    <journey>
        <distance type="miles">5,441 miles</distance> 
        <time>PT11H5M</time>
    </journey>

</flight>




</flights>

and output this in a table, here is my attempt in the XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />

    <xsl:template match="/">
    <xsl:element name="html">
        <xsl:element name="head">
            <xsl:element name="title">flights</xsl:element>
        </xsl:element>


  <xsl:element name="body"> 
      <xsl:element name="table"><xsl:attribute name="border">1</xsl:attribute>
        <xsl:element name="tr">
          <xsl:element name="td">
            <xsl:element name="b">Title</xsl:element>
          </xsl:element>
          <xsl:element name="td">
            <xsl:element name="b">Artist</xsl:element>
          </xsl:element>
          <xsl:element name="td">
            <xsl:element name="b">Year</xsl:element>
          </xsl:element>
        </xsl:element>
        <xsl:apply-templates select="flights/flight/route[contains(text(), 'FCO-DXB')]" />
      </xsl:element>
    </xsl:element>
</xsl:element>
</xsl:template>


<xsl:template match="from">
<xsl:element name="tr">
  <xsl:element name="td"><xsl:value-of select="iatacode"/></xsl:element>
  <xsl:element name="td"><xsl:value-of select="airport"/></xsl:element>
  <xsl:element name="td"><xsl:value-of select="country"/></xsl:element>
  <xsl:element name="td"><xsl:value-of select="city"/></xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="to">
<xsl:element name="tr">
<xsl:element name="td"><xsl:value-of select="iatacode"/></xsl:element>
  <xsl:element name="td"><xsl:value-of select="airport"/></xsl:element>
  <xsl:element name="td"><xsl:value-of select="country"/></xsl:element>
  <xsl:element name="td"><xsl:value-of select="city"/></xsl:element>
</xsl:element>
</xsl:template>


</xsl:stylesheet>

My goal is to eventually figure out how to pass parameters to the XSLT file so instead of hardcoding the contains text, I can pass it a parameter, but so far I would just like to know how to answer this question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:16:02+00:00Added an answer on June 18, 2026 at 10:16 pm

    You did not say if there can be more than one routename with the same identifier. And if there are, they should be displayed in the same table or in a different table (one per match)?

    I assume here that if there are multiple routenames with the same identifier, those are printed in the same table (correct me if this assumption is not right and I will change the code accordingly).

    This is one way of doing what you are trying to achieve:

    <?xml version="1.0" encoding="utf-8" ?>
    
    <xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:output method="html" omit-xml-declaration="yes" />
    
    <xsl:param name="code"
               select="'FCO-DXB'" />
    
    <xsl:template match="/flights">
        <html>
            <head>
                <title>flights</title>
            </head>
            <body>
                <xsl:apply-templates select="flight/route[routename/. = $code]" />
            </body>
        </html>
    </xsl:template>
    
    
    <xsl:template match="route">
        <table>
            <tr>
                <td><b>IATA Code</b></td>
                <td><b>Airport</b></td>
                <td><b>Country</b></td>
                <td><b>City</b></td>
            </tr>
            <xsl:apply-templates select="*" />
        </table>
    </xsl:template>
    
    <xsl:template match="from|to">
        <tr><xsl:apply-templates select="*" /></tr>
    </xsl:template>
    
    <xsl:template match="iatacode|airport|country|city">
        <td><xsl:value-of select="." /></td>
    </xsl:template>
    
    <xsl:template match="text()" />
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a table from another table but I only want the
I need to create pdf document which outputs all rows from mysql table, but
I need to create an HTML table with pagination. The data comes from 2
I need to create a log file containing HTML (tables, etc). It seems that
In MySQL, I need to create a new table called users with the following
I need to create a dynamic html table using PHP after parsing a JSON
I create rows in a HTML table dynamically from MySQL values in a PHP
I need to frame a json object from an html table with all the
I need to create an HTML table which has fixed column widths, say 200px
i need to create an html report where i've to put a table into.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.