I'm using C# to transform an XML document and it is working fine:
using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
public class XmlTransformUtil
{
public static void Main(string[] args)
{
if (args.Length == 2)
{
Transform(args[0], args[1]);
}
else
{
PrintUsage();
}
}
public static void Transform(string sXmlPath, string sXslPath)
{
try
{
//load the Xml doc
XPathDocument myXPathDoc = new XPathDocument(sXmlPath);
XslTransform myXslTrans = new XslTransform();
//load the Xsl
myXslTrans.Load(sXslPath);
//create the output stream
XmlTextWriter myWriter = new XmlTextWriter
("result.html", null);
//do the actual transform of Xml
myXslTrans.Transform(myXPathDoc, null, myWriter);
myWriter.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}", e.ToString());
}
}
public static void PrintUsage()
{
Console.WriteLine
("Usage: XmlTransformUtil.exe <xml path> <xsl path>");
}
}
The above code works perfectly, however what I want to do is, before the XSLT is transformed, I want it to add additional Lines of code to specific parts of the XSLT.
XSLT Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html lang="en-GB">
<body style="font-family:'Praxis Com Light'; color:#632423; width:100%; font-size:14px !important;">
//MAIN BODY OF CODE
</body>
</html>
</xsl:template>
</xsl:stylesheet>
How i want the XSLT Code changed in C# Before the transformation:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="HEAD.xslt"/>
<xsl:include href="FOOT.xslt"/>
<xsl:template match="/">
<html lang="en-GB">
<body style="font-family:'Praxis Com Light'; color:#632423; width:100%; font-size:14px !important;">
<xsl:call-template name="Header"/>
//MAIN BODY OF CODE
<xsl:call-template name="Footer"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
How can this be accomplished?