Writing XML to html with XSLT

V

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:blush:utput 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.
 
B

Bruce Wood

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
 
D

Dennis Myrén

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>
 
A

Antony Baula

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top