How to Convert XML to PDF with XSLT in C#
XML cannot render to PDF directly, so the path runs in two steps: an XSLT stylesheet transforms the XML into HTML, then IronPDF renders that HTML to PDF through its Chrome engine. IronPDF owns only the final leg; XSLT does the shaping. That split keeps data (the XML) and presentation (the stylesheet) apart, and the use cases below all lean on it.
using IronPdf;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
var transform = new XslCompiledTransform();
transform.Load("invoice.xslt");
using var writer = new StringWriter();
using (var reader = XmlReader.Create("invoice.xml"))
{
transform.Transform(reader, null, writer);
}
new ChromePdfRenderer()
.RenderHtmlAsPdf(writer.ToString())
.SaveAs("invoice.pdf");Imports IronPdf
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Dim transform As New XslCompiledTransform()
transform.Load("invoice.xslt")
Using writer As New StringWriter()
Using reader As XmlReader = XmlReader.Create("invoice.xml")
transform.Transform(reader, Nothing, writer)
End Using
Dim renderer As New ChromePdfRenderer()
renderer.RenderHtmlAsPdf(writer.ToString()).SaveAs("invoice.pdf")
End Using(Note: Transform writes into the StringWriter; it does not return the HTML, so you read writer.ToString() after the call.)
E-invoicing and machine-readable invoice formats
Here the pipeline pays off most. Standards like UBL, Factur-X, and ZUGFeRD carry invoices as XML data, not as documents anyone can read. A stylesheet turns that XML into a formatted invoice, and IronPDF produces the PDF a person actually receives.
Regulated data feeds in finance, government, and healthcare
These industries exchange structured XML: tax filings, financial statements, clinical documents, regulatory submissions. Each schema maps to a compliant printed layout through its own stylesheet, with the transformation logic kept out of your C#.
Product catalogs and price lists
A catalog feed in XML becomes a formatted brochure or table through a stylesheet, with styling handled by familiar HTML and CSS rather than a proprietary PDF language.
One source, many document variants
Because presentation lives in the template, one XML source can produce several outputs (customer invoice, internal copy, localized version) by swapping stylesheets. No data changes, no recompiling.
Parameterized and conditional documents
Pass runtime values into the transform with XsltArgumentList, so one template can branch on currency, region, or draft status before rendering:
var args = new XsltArgumentList();
args.AddParam("currency", "", "AUD");
using var writer = new StringWriter();
using (var reader = XmlReader.Create("invoice.xml"))
{
transform.Transform(reader, args, writer);
}Imports System.Xml
Imports System.Xml.Xsl
Imports System.IO
Dim args As New XsltArgumentList()
args.AddParam("currency", "", "AUD")
Using writer As New StringWriter()
Using reader As XmlReader = XmlReader.Create("invoice.xml")
transform.Transform(reader, args, writer)
End Using
End UsingWhen not to use this
For a simple XML structure or a one-off conversion, the XSLT layer is overhead; parse the XML and build the HTML directly. The stylesheet approach proves its worth in systems handling varied schemas or needing maintainable, reusable transformation logic.
Why the split is the point
The pipeline's strength is that separation. IronPDF gives you pixel-accurate rendering on the last step, but the flexibility, multiple formats, conditional layouts, schema independence, all comes from keeping the transform in XSLT rather than in code.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.