public string GetPESExpressBody(Guid id)
{
var result = Model;
var xml= GetXMLString(result);
string xsltFile = @"C:\Users\qinxhan\Desktop\New folder\1.xsl";
var html= GetHtmlString(xml,xsltFile);
return html;
}
private string GetXMLString(object model)
{
XmlDocument xmldoc = new XmlDocument();
XmlElement ModelNode = xmldoc.CreateElement("Model");
xmldoc.AppendChild(ModelNode);
if (model != null)
{
foreach (PropertyInfo property in model.GetType().GetProperties())
{
XmlElement attribute = xmldoc.CreateElement(property.Name);
if (property.GetValue(model, null) != null)
attribute.InnerText = property.GetValue(model, null).ToString();
else
attribute.InnerText = "[Null]";
ModelNode.AppendChild(attribute);
}
}
return xmldoc.OuterXml;
}
private string GetHtmlString(string xml,string xsltFile) {
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(xml);
System.Xml.Xsl.XslCompiledTransform xct = new System.Xml.Xsl.XslCompiledTransform();
xct.Load(xsltFile);
System.IO.StringWriter writer = new System.IO.StringWriter();
xct.Transform(xdoc, null, writer);
writer.Close();
return writer.ToString();
}
///XSL
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:template match="/">
<table border="1">
<tr bgcolor="#9acd32">
<th>StaffCode</th>
<th>CostCenter</th>
</tr>
<tr>
<td>
<xsl:value-of select="/Model/StaffCode"/>
</td>
<td>
<xsl:value-of select="/Model/CostCenter"/>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>