PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.

Bulleted list from XML and XSL

This code sample helps getting a bulleted list from XML and XSL.

See PDF output.

XML

<?xml version="1.0" encoding="utf-8" ?>
<countries>
  <country>
    <name>Sweden</name>
  </country>
  <country>
    <name>Norway</name>
  </country>
  <country>
    <name>Denmark</name>
  </country>
</countries>

XSL

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <document>
      <section pagesize="a4" startonnewpage="true">
        <xsl:apply-templates select="countries"/>
      </section>
    </document>
  </xsl:template>

  <xsl:template match="country">
    <paragraph type="NumberedItem">
      <numberfragment type="fragment" font="symbol" fontsize="10">&#xb7;</numberfragment>
      <fragment fontsize="10">
        <xsl:value-of select="name"/>
      </fragment>
    </paragraph>
  </xsl:template>

</xsl:stylesheet>

C#

// Load XML
XmlDocument xml = new XmlDocument();
xml.Load("data.xml");

// Load XSL
XslTransform xsl = new XslTransform();
xsl.Load("transform.xsl");

// Transform
XmlReader reader = xsl.Transform(xml, null);

// Write PDF
Document doc = new Document();
doc.Read(reader);

using (FileStream file = new FileStream("out.pdf", FileMode.Create, FileAccess.ReadWrite))
{
  doc.Write(file);
}
Download TallPDF.NET 5.0
We will send you a download link

  • This field is for validation purposes and should be left unchanged.
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download

We have sent an email with a download link.