Hi,
can anyone start me off with regard to converting some XML to HTML. I've worked on XSLT conversions before, but never from scratch, and I seem to be missing something.
Starting with XML that's something like this:
<order name="fred" value="123.45">
<lines>
<line description="foo" value="123"/>
<line description="bar" value="0.45"/>
</lines>
</order>
...and an XSLT file that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:decimal-format name="sterling" decimal-separator="." grouping-separator=","/>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<xsl:apply-templates select="order"/>
</head>
<body>
<table border="2">
<xsl:apply-templates select="order/lines/line"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="order">
Name is '<xsl:value-of select="@name"/>' and value is <xsl:value-of select="format-number(@value, '£#,###.00', 'sterling')"/>
</xsl:template>
<xsl:template match="order/lines/line">
<tr>
<td>
<xsl:value-of select="@description"/>
</td>
<td>
<xsl:value-of select="@value"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
When I do the conversion using an XslCompiledTransform object from C#, I get the basic html but no content for the the lines. The code I used to the the transform isas follows:
private static String GetHtml(String xml)
{
String result;
var doc = new XmlDocument();
doc.LoadXml(xml);
var transformer = new XslCompiledTransform(true);
transformer.Load("foobar.xslt");
using (var writer = new StringWriter())
{
transformer.Transform(doc, null, writer);
result = writer.ToString();
}
return result;
}
Any help greatly appreciated.
Ross
(as an aside, what's the point of the xsl:decimal-format element if, in using the format-number function, I have to provide the format string ?)