Here is one way of doing it. In this case I am using the Altova library because for this client I needed XSLT2 support.
using System;
using System.Text.RegularExpressions;
using Altova.AltovaXML;
namespace RedCell.App.XsltTransformer
{
public class Transformer
{
#region Initialization
public Transformer()
{
this.Input = "";
this.Xslt = "";
this.Output = "";
}
public Transformer(string input, string xslt)
{
this.Input = input;
this.Xslt = xslt;
}
#endregion
#region Properties
public string Input { get; set; }
public string Xslt { get; set; }
public string Output { get; set; }
#endregion
#region Methods
public void Transform()
{
if(string.IsNullOrEmpty(Input))
throw new ArgumentNullException("Entrée");
if (string.IsNullOrEmpty(Xslt))
throw new ArgumentNullException("Xslt");
Input = Regex.Replace(Input, "<!DOCTYPE.+?>", "", RegexOptions.Singleline);
var app = new ApplicationClass();
XSLT2 xslt2 = app.XSLT2;
xslt2.XSLFromText = Xslt;
xslt2.InputXMLFromText = Input;
Output = xslt2.ExecuteAndGetResultAsString();
}
#endregion
}
}