Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use xlst and xml to generate html

Status
Not open for further replies.

mdivk

MIS
Mar 31, 2009
3
CA
Hello folks,

I am very new to xml-related language, I have a dynamically generated xml file, I need to transform it to html, I have a sample xlst, but it is just not working, can anyone tell me how to do it? the xml file is as following:

<Order>
<d>
<DocID>129</DocID>
<nextreviewdate>2009-03-01T00:00:00</nextreviewdate>
<i>
<Code>KS</Code>
<title>Acceptance to transmit electronically VISA Transactions Report and Billing Files from BCE</title>
<ref>2002-6</ref>
<doctype>Risk Acceptance Letter</doctype>
<u>
<Consultant>Stephen</Consultant>
</u>
</i>
</d>
<d>
<DocID>135</DocID>
<nextreviewdate>2010-04-12T00:00:00</nextreviewdate>
<i>
<Code>KS</Code>
<title>Host Based PIN (HBP) Project</title>
<ref>2001-10</ref>
<doctype>Risk Acceptance Letter</doctype>
<u>
<Consultant>Stephen</Consultant>
</u>
</i>
</d>
</Order>

Here is the "wrong" xlst:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl=" <xsl:template match="Order">
<html>
<head>
<style type="text/css">
body {margin-left: 20px; font-family: segoe ui, tahoma, sans-serif;}
h1 {color: #f00;}
h2 {size: 70%; color: #00f;}
td {padding-right: 10px;}
</style>
</head>
<body>
<h1>Document List</h1>
<xsl:apply-templates select="oh"/>
</body>
</html>
</xsl:template>
<xsl:template match="oh">
<DIV style="margin-bottom:20px;">

<table>
<tr>
<th>Code</th>
<th>DocID</th>
<th>Ref</th>
<th>Title</th>
<th>doctype</th>
<th>NextReviewDate</th>
</tr>

<xsl:apply-templates select="p"/>

</table>

</DIV>
<hr />
<p style="font-size: 70%;"><a href=" 2009</p>
</xsl:template>
<xsl:template match="p">
<div style="color:#f00; font-size: 90%;">

<tr>
<td><xsl:value-of select="Code"/></td>
<td><xsl:value-of select="DocID"/></td>
<td><xsl:value-of select="Ref"/></td>
<td><xsl:value-of select="Title"/></td>
<td><xsl:value-of select="doctype"/></td>
<td><xsl:value-of select="NextReviewDate"/></td>
</tr>

</div>
</xsl:template>
<xsl:template match="NoRecords">
<html>
<head>
<style type="text/css">
body {margin-left: 20px; font-family: tahoma, sans-serif;}
</style>
</head>
<body>
<h1>Daily Order Totals</h1>
<div>
No sales records were found for the specified date.

</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Thank you very much.
 
Maybe you should specify what do you mean by "wrong" and how are you applying the transformation.

Cheers,
Dian
 
My XSLT (not xlst) is very rusty, but...
Code:
   <xsl:template match="oh">
   ...
   <xsl:template match="p">
   ...
   <xsl:template match="NoRecords">
You don't have any <oh>, <p> or <NoRecords> elements in your XML file, so those templates are never going to match anything.

Also, for the sake of your future sanity, I suggest you pick a consistent approach to capitalising element names and stick to it, rather than having <DocID>, <Code>, <title> etc. Sooner or later you're going to spend hours debugging a script only to realise that, for example, you've got [tt]<xsl:template match="foo">[/tt] when it should be [tt]<xsl:template match="Foo">[/tt] (or vice versa).

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thank you for the replies.

I am a newbie on xml but I am now getting a little bit more on this, I have been able to revise the xslt file and generate html output. My question is:

How do I design my output? Anything I can do to "transform an existing html page into an xslt file"?

Thanks lots.
 
Here is the xml file I generated from SQL, and the xslt I am using to transform it to html.

XML:
<Result>
<_x0023_consultantview>
<DocID>129</DocID>
<Code>KS</Code>
<Title>Acceptance</Title>
<Ref>2002-6</Ref>
<NextReviewDate>2009-03-01T00:00:00</NextReviewDate>
<Consultant>Stephen</Consultant>
</_x0023_consultantview>
<_x0023_consultantview>
<DocID>135</DocID>
<Code>KS</Code>
<Title>Host Project</Title>
<Ref>2001-10</Ref>
<NextReviewDate>2010-04-12T00:00:00</NextReviewDate>
<Consultant>David</Consultant>
</_x0023_consultantview>
</Result>

XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl=" <xsl:template match="Result">
<html>
<head>
<style type="text/css">
body {margin-left: 20px; font-family: segoe ui, tahoma, sans-serif;}
h1 {color: #f00;}
h2 {size: 70%; color: #00f;}
td {padding-right: 10px;}
</style>
</head>
<body>
<h1>Email Notification</h1>
<xsl:apply-templates select="_x0023_consultantview"/>
</body>
</html>
</xsl:template>
<xsl:template match="_x0023_consultantview">
<DIV style="margin-bottom:20px;">
<table>
<tr>
<th>DocID</th>
<th>Code</th>
<th>Title</th>
<th>Ref</th>
<th>NextReviewDate</th>
<th>Consultant</th>
</tr>

<xsl:apply-templates select="_x0023_consultantview"/>

</table>

</DIV>
<hr />
<p style="font-size: 70%;"><a href=" 2008</p>
</xsl:template>
<xsl:template match="_x0023_consultantview">
<div style="color:#f00; font-size: 90%;">

<tr>
<td style="width=8%"><xsl:value-of select="DocID"/></td>
<td style="width=8%"><xsl:value-of select="Code"/></td>
<td style="width=20%"><xsl:value-of select="Title"/></td>
<td style="width=8%"><xsl:value-of select="Ref"/></td>
<td style="width=15%"><xsl:value-of select="NextReviewDate"/></td>
<td style="width=15%"><xsl:value-of select="Consultant"/></td>
</tr>

</div>
</xsl:template>
</xsl:stylesheet>


Well, apparently the combined html output is not nice at all, I need to do some customize work, problem is how to do this? is there any convenient tool that can do this for me?

Thanks.
 
Still no answers about how are you doing it and why the result is wrong

*Sigh*

Anyway, an article for you.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top