I've written a simple XML Document that I am trying to transform with an XSLT file, but I get no results when I run the code. Here is my XML document:
<?xml version="1.0" encoding="utf-8" ?>
<Employee xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="XSLT_MVC.Controllers">
<ID>42</ID>
<Name>Russ</Name>
</Employee>
And here is the XSLT file:
<?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"
xmlns:ex="XSLT_MVC.Controllers" >
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:copy>
<xsl:value-of select="ex:Employee/Name"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Here is the code (from a C# console app) I am trying to run to perform the transform:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
namespace XSLT
{
class Program
{
static void Main(string[] args)
{
Transform();
}
public static void Transform()
{
XPathDocument myXPathDoc = new XPathDocument(@"docs\sampledoc.xml");
XslTransform myXslTrans = new XslTransform();
myXslTrans.Load(@"docs\new.xslt");
XmlTextWriter myWriter = new XmlTextWriter(
"results.html", null);
myXslTrans.Transform(myXPathDoc, null, myWriter);
myWriter.Close();
}
}
}
When I run the code I get a blank html file. I think I may have problems with the namespaces, but am not sure. Can anyone help with this?