473,383 Members | 1,855 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,383 software developers and data experts.

Writing XML to html with XSLT

VMI
I'm having trouble writing several records from an XML file into an html
file. The problem is that it only outputs one record to the html file. I
need to export all the records in the xml file to html. How can I do this?
Is there a better (and easier) way to export a dataset to a
'friendly-printer' format? The resulting XML file is hard to understand if
printed, and that's why I'm using XLST.

This is what the xsl file looks like. Can I add a loop to it?:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<!-- indicates what our output type is going to be -->
<xsl:output method="html" />

<!--
Main template to kick off processing our Sample.xml
From here on we use a simple XPath selection query to
get to our data.
-->
<xsl:template match="/">

<html>

<head>

<title>Printout</title>

<style>
body,td {font-family:Tahoma,Arial; font-size:9pt;}
</style>

</head>

<body>
<xsl:value-of select="/dsXML/audit/InKey"/>
<br/>
<xsl:value-of select="/dsXML/audit/InFBU"/>
<br/>
<xsl:value-of select="/dsXML/audit/OutDel"/>
<br/>
<xsl:value-of select="/dsXML/audit/OutCity"/>
<br/>
</body>

</html>

</xsl:template>

</xsl:stylesheet>

Thanks for the help.
Nov 16 '05 #1
3 2740
First off, you're posting to entirely the wrong group. This is a group
discussing and giving help on the C# programming language, not XML.
Event the .NET XML group is concerned with using XML within the .NET
framework. You need to find a general-purpose XML group.

That said, I think you're misunderstanding how XSLT works. XSLT is a
pattern-matching language, not a procedural programming language. While
you can write loops in XSLT, you're much better off creating patterns
that say, "Whenever you see an 'audit' node do this..." Try looking up
more on-line examples of how XSLT works and you'll get the idea. You
can start here:

http://www.zvon.org/xxl/XSLTutorial/Output/index.html

Nov 16 '05 #2
You want to try using something like apply-templates or for-each.
This is an example:
<xsl:template match="/">
<html>
<head>
<title>Printout</title>
<style>body,td {font-family:Tahoma,Arial; font-size:9pt;}</style>
</head>
<body>
<xsl:apply-templates select="audit" />
</body>
</html>
</xsl:template>
<xsl:template match="audit">
<xsl:value-of select="InKey"/>
<br/>
<xsl:value-of select="InFBU"/>
<br/>
<xsl:value-of select="OutDel"/>
<br/>
<xsl:value-of select="OutCity"/>
<br/>
</xsl:template>
</xsl:stylesheet>

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"VMI" <vo******@yahoo.com> wrote in message
news:ug**************@tk2msftngp13.phx.gbl...
I'm having trouble writing several records from an XML file into an html
file. The problem is that it only outputs one record to the html file. I
need to export all the records in the xml file to html. How can I do this?
Is there a better (and easier) way to export a dataset to a
'friendly-printer' format? The resulting XML file is hard to understand if
printed, and that's why I'm using XLST.

This is what the xsl file looks like. Can I add a loop to it?:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<!-- indicates what our output type is going to be -->
<xsl:output method="html" />

<!--
Main template to kick off processing our Sample.xml
From here on we use a simple XPath selection query to
get to our data.
-->
<xsl:template match="/">

<html>

<head>

<title>Printout</title>

<style>
body,td {font-family:Tahoma,Arial; font-size:9pt;}
</style>

</head>

<body>
<xsl:value-of select="/dsXML/audit/InKey"/>
<br/>
<xsl:value-of select="/dsXML/audit/InFBU"/>
<br/>
<xsl:value-of select="/dsXML/audit/OutDel"/>
<br/>
<xsl:value-of select="/dsXML/audit/OutCity"/>
<br/>
</body>

</html>

</xsl:template>

</xsl:stylesheet>

Thanks for the help.

Nov 16 '05 #3
>
This is what the xsl file looks like. Can I add a loop to it?:


Not sure about loops but sure of recursive template calling. Using a
variables let to control the depth of recursion.
I'm sure bcs I did that.

Nov 16 '05 #4

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

Similar topics

2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
6
by: mike | last post by:
regards: Is it possible to use java XML api to translate a HTML document into a XHTML document(mobile profile) thank you best wishes
2
by: Taare | last post by:
Hi, I got <xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD HTML 4.01//EN" doctype-system=" http://www.w3.org/TR/html4/strict.dtd"/> in my XSLT file. This should remove...
5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
6
by: Mike P | last post by:
I am quite new to XML and XSLT, and I know you can apply XSLT to XML to display data in an XML file according to the XSLT file, but is it possible to apply an XSLT file to page/s of HTML, so that...
3
by: Rusty | last post by:
Hi, our intranet web site needs to add this feature. I've got the components but just need the last step to get it going. Here's the setup. 1) a user clicks on a link which calls a web service...
12
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I...
4
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report>...
5
by: miller.paul.w | last post by:
I've searched the standard library docs, and, while there are a couple options for *reading* HTML from Python, I didn't notice any for *writing* it. Does anyone have any recommendations...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

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.