Convert XML Through XSLT Transformation to HTML, WordProcessing, or PDF

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Conversion MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-conversion -- dnx GroupDocs.Conversion.Mcp --yes
Folders, licensing and more →

GroupDocs.Conversion for .NET allows you to transform XML data into a variety of formats, including HTML, WordProcessing documents (e.g., DOCX), and PDFs, using XSLT stylesheets. This method offers flexibility to define the layout, structure, and styling of the target format while leveraging the powerful XML transformation capabilities of XSLT.

Key Features

  • Transform XML data into different formats using custom XSLT templates.
  • Output formats supported: HTML, DOCX, and PDF.
  • Highly customizable transformation based on XSLT design.

Prerequisites

Before proceeding, ensure the following:

  1. GroupDocs.Conversion for .NET is installed in your project.
  2. An XML file with the data to convert.
  3. An XSLT stylesheet defining the transformation logic.

Examples

1. Convert XML to HTML

The following code demonstrates converting XML to an HTML file using an XSLT template:

using (var converter = new Converter("books.xml", (LoadContext loadContext) => new XmlLoadOptions
       {
           XsltFactory = () => new FileStream("bookstore-template.xslt", FileMode.Open)
       }))
{
    var options = new WebConvertOptions();
    converter.Convert("converted.html", options);
}

2. Convert XML to Wordprocessing

The following code demonstrates converting XML to a DOCX file using an XSLT template:

using (var converter = new Converter("books.xml", (LoadContext loadContext) => new XmlLoadOptions
       {
           XsltFactory = () => new FileStream("bookstore-template.xslt", FileMode.Open)
       }))
{
    var options = new WordProcessingConvertOptions();
    converter.Convert("converted.docx", options);
}

3. Convert XML to PDF

The following code demonstrates converting XML to a PDF file using an XSLT template:

using (var converter = new Converter("books.xml", (LoadContext loadContext) => new XmlLoadOptions
       {
           XsltFactory = () => new FileStream("bookstore-template.xslt", FileMode.Open)
       }))
{
    var options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}