473,320 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to Display XML tags and values in an HTML page?

I've done a little xml and xsl, but am a relative newbie.
I have been unable to find a stylesheet to process an xml file and
output the tagNames and tagValues in HTML. I have also posted this
message in tek-tips.

I can get the node names with name() and the value with xsl:value-of
.... but I would like to get the lowest level tagNames via the xsl. I'd
like to be able to build html for a number of different xml files.
I'm trying to get something like:

Flights
Flight 1
Flight_Number: BA123
Origin : GLA
Destination : LHR
Carrier : British Airways
Date : 01/01/2002
.....
other flights

from xml as follows:
<Flights>
<Flight>
<Flight_Number>BA123</Flight_Number>
<Origin>GLA</Origin>
<Destination>LHR</Destination>
<Carrier>British Airways</Carrier>
<Date>01/01/2002</Date>
</Flight>
<Flight>
<Flight_Number>BA4234</Flight_Number>
<Origin>GLA</Origin>
<Destination>YOW</Destination>
<Carrier>British Airways</Carrier>
<Date>01/01/2002</Date>
</Flight>
</Flights>
I've tried name() and local-name() but they return the name of the
parent node, not the leaf element name.
TIA

jack

Nov 27 '05 #1
2 1719
dr*********@sympatico.ca wrote:
I've done a little xml and xsl, but am a relative newbie.
I have been unable to find a stylesheet to process an xml file and
output the tagNames and tagValues in HTML. I have also posted this
message in tek-tips.
First of all, please read http://xml.silmaril.ie/authors/makeup/
I can get the node names with name() and the value with xsl:value-of
... but I would like to get the lowest level tagNames via the xsl. I'd
like to be able to build html for a number of different xml files.
Have you set <xsl:output method="html"/> ?

I'm trying to get something like:

Flights
Flight 1
Flight_Number: BA123
Origin : GLA
Destination : LHR
Carrier : British Airways
Date : 01/01/2002
.....
other flights

from xml as follows:
<Flights>
<Flight>
<Flight_Number>BA123</Flight_Number>
<Origin>GLA</Origin>
<Destination>LHR</Destination>
<Carrier>British Airways</Carrier>
<Date>01/01/2002</Date>
</Flight>
<Flight>
<Flight_Number>BA4234</Flight_Number>
<Origin>GLA</Origin>
<Destination>YOW</Destination>
<Carrier>British Airways</Carrier>
<Date>01/01/2002</Date>
</Flight>
</Flights>
I've tried name() and local-name() but they return the name of the
parent node, not the leaf element name.


As you didn't post your XSL code we can only guess at what you're doing.

What you need is a template for each element of your XML document,
giving the HTML element type that you want to be output for it, eg

<xsl:template match="Flights">
<h1>
<xsl:apply-templates/>
</h1>
</xsl:template>

<xsl:template match="Flight">
<h2>
<xsl:text>Flight </xsl:text>
<xsl:number/>
</h2>
<table>
<xsl:for-each select="*">
<tr>
<td>
<xsl:value-of select="name()"/>
</td>
<td>:</td>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>

The XSL List is a good place to discuss the details of XSL[T]:
see the details of other FAQs at the address below.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Nov 27 '05 #2
Thanks Peter,

I have partially solved the issue. Here is the output and the xsl Used.

Output:

List of matching Flights

Flight
Flight_Number: BA123
Origin: GLA
Destination: LHR
Carrier: British Airways
Date: 01/01/2002

Flight
Flight_Number: BA4234
Origin: GLA
Destination: YOW
Carrier: British Airways
Date: 01/01/2002

Flight
Flight_Number: AA4959
Origin: GLA
Destination: LHR
Carrier: American Airways
Date: 01/01/2002

Flight
Flight_Number: AC23
Origin: CAN
Destination: LHR
Carrier: Air Canada
Date: 01/02/2004
xsl:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="no"/>
<xsl:template match="Flights">
<html>
<head>
<title>Matching Request Flights</title>
</head>
<body>
<h1>List of matching Flights </h1>
<xsl:apply-templates select="Flight"/>
</body>
</html>
</xsl:template>

<!-- Templates -->
<xsl:template match="Flight">
<!-- Display Flight-->
<tr><th><br/>
<b><font color="blue"><xsl:value-of select="local-name()"/></font></b>
</th></tr>
<table border="0">
<xsl:apply-templates />
</table>
</xsl:template>

<xsl:template match="Flight/*">
<tr><td><b><xsl:value-of select="local-name()"/>:</b></td>
<td><xsl:value-of select="."/></td></tr>
</xsl:template>

</xsl:stylesheet>

Nov 28 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: vishal | last post by:
i am making an application. the user can give description and that description is stored in database and then the description is shown on html page. suppose the user has written "<b>hello</b>"...
2
by: Jon Haakon | last post by:
Hi, I'm developing a websolution using ASP and DHTML technology that's running on a MS IIS webserver. My solution is frame based with a toolbar on top, a hidden frame for scripts in the...
4
by: dmiller23462 | last post by:
I'm trying to create a submission page for users to request PC/LAN Access....If they select "Yes" in the field asking about if they need Non Standard Software, I want several other HTML fields to...
3
by: Al | last post by:
Hi Many thanks in advacne, does anyone know how to display contenet of a Html page on a VB form.? can this be display in a RichRextBox? if yet how.. Many thank Al
5
by: acord | last post by:
Hi, I m getting annoying display problem when placing javascript tags in a html page. Should the javasscript tags placed at the beginning of a html page before anything start? or placed between...
6
by: vasu1308 | last post by:
Hi I would like to know how to remove tags in a HTML page. Can anyone help me.. Thanks Vasu
5
by: teddarr | last post by:
I have this product catalog. I am to scroll through the catalog on the HTML page and use data from the XML page to display the different products with a picture of each. I have the data and the...
34
by: vpriya6 | last post by:
Hi guys, I am new to Ajax, xml and javascript. I want to know how can I retrieve data from xml and display in the html page? please help me out. suppose my xml file is customer.xml the code...
2
by: arty | last post by:
hello i have no problem with this code: var z=new Array() z="<span style ='color:red;'>yeah</span>" document.getElementById("aa").innerHTML = z; it ouputs everything and also with the style....
1
by: idoru17 | last post by:
Hi, I need to set some parameters in an HTML page displayed in a lightbox (fancybox) using an iframe. The calling page is in HTML, here are the parameters to be set: - 2 text areas named champ1...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.