IRONSOFTWAREHOME
USE CASES

How to Convert XML to PDF with XSLT in C#

Curtis Chau
Curtis Chau
Updated: July 5, 2026

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");

(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);
}

When 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
Technical Writer

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.

...
Read More

Related Articles

Key in blue circle

Get your free 30-day Trial Key instantly.

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required