Skip to content

Instantly share code, notes, and snippets.

@uniquelau
Last active December 16, 2015 08:08
Show Gist options
  • Save uniquelau/5403147 to your computer and use it in GitHub Desktop.
Save uniquelau/5403147 to your computer and use it in GitHub Desktop.
/// Lets give it a go.
/// Why could this fail? API offline, API outputing invalid XML, XSLT file missing/invalid.
try
{
/// <summary>
/// Passes the parameters into a XSL file, that is run against in memory XML
/// </summary>
string xsltFilePath = Server.MapPath("~/XSLT/getProduct.xsl");
// Load XML from our Global Variable
XPathNavigator nav = Data.CreateNavigator();
// Stream for the transformed XML
MemoryStream stream = new MemoryStream();
XsltArgumentList argsList = new XsltArgumentList();
argsList.AddParam("refID", "", refID);
argsList.AddParam("subRefID", "", subRefID);
// Load XSLT & transform
XslCompiledTransform transformer = new XslCompiledTransform();
transformer.Load(xsltFilePath);
transformer.Transform(nav, argsList, stream);
// Write output
using (StreamReader reader = new StreamReader(stream))
{
stream.Position = 0;
Response.Write(reader.ReadToEnd());
reader.Close();
}
}
/// fail
catch { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment