Created
December 20, 2015 21:41
-
-
Save ivanignatiev/aa5f8686e325901b4dbf to your computer and use it in GitHub Desktop.
Apply XSLT to XML transformation on C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Xml.XPath; | |
using System.Xml.Xsl; | |
namespace ApplyXSLTToXML | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (args.Length < 2) | |
{ | |
Console.WriteLine("Error:"); | |
Console.WriteLine("Not enough parameters to run this application"); | |
return; | |
} | |
string XMLFilePath = args[0]; | |
string XSLTFilePath = args[1]; | |
// ApplyXSLTToXML.exe Input.xml Transformation.xslt | |
try | |
{ | |
// Load documents | |
var xmlDocument = new XPathDocument(XMLFilePath); | |
var xslt = new XslCompiledTransform(); | |
xslt.Load(XSLTFilePath); | |
// Apply transformation and output results to console | |
var consoleWriter = new StreamWriter(Console.OpenStandardOutput()); | |
consoleWriter.AutoFlush = true; | |
xslt.Transform(xmlDocument, null, consoleWriter); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Error:"); | |
Console.WriteLine(e.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment