libxslt clib System & Utilities

libxslt XSLT transforms. Apply stylesheets, XML to HTML/text, parameters, EXSLT support.

ppm install libxslt

Overview

libxslt is the reference XSLT 1.0 implementation — the engine behind Python's lxml.etree, PHP's XSLTProcessor, and many document pipelines. It transforms XML documents using declarative stylesheets into HTML, plain text, other XML formats, or any structured output. Also includes EXSLT extensions (math, string, date, sets).

CLib package

Ubuntu/Debian: sudo apt install libxslt1-dev
Requires: libxml2 (installed automatically)

Quick Start — XML to HTML

uses libxslt;

// One-shot: file + stylesheet → HTML string
var html := TransformFile('/data/catalog.xml', '/xsl/catalog.xsl');
WriteLn(html);

// Or save directly to file
TransformFileToFile('/data/catalog.xml', '/xsl/catalog.xsl', '/out/catalog.html');

With Parameters

// Pass parameters to the stylesheet (values are XPath expressions)
var html := TransformFileParams(
  '/data/report.xml',
  '/xsl/report.xsl',
  'title=''Q1 Report''' + #10 + 'year=2026'
);
WriteLn(html);

Reusable Stylesheet Handle

uses libxml2, libxslt;

// Load once, apply many times
var ss := LoadStylesheet('/xsl/invoice.xsl');
WriteLn('Output method: ', OutputMethod(ss));   // "html" or "xml" or "text"

for I := 0 to Length(invoices) - 1 do begin
  var doc := ParseFile(invoices[I]);
  var r   := Transform(ss, doc);
  var out := ResultToString(ss, r);
  SaveToFile(ResultToDoc(r), '/out/invoice_' + IntToStr(I) + '.html');
  FreeResult(r);
  FreeDoc(doc);
end;

FreeStylesheet(ss);

Transform from String

var xml  := '<data><item>Hello</item></data>';
var xslt := '<?xml version="1.0"?>' +
            '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' +
            '<xsl:template match="/"><p><xsl:value-of select="data/item"/></p></xsl:template>' +
            '</xsl:stylesheet>';

var result := TransformStringWithString(xml, xslt);
WriteLn(result);   // <p>Hello</p>

EXSLT Extensions

// Register EXSLT before loading stylesheets that use exsl:*
RegisterEXSLT;

// Now stylesheets can use:
// math:max(), math:min(), math:sum()
// str:tokenize(), str:padding(), str:replace()
// date:year(), date:month-name()
// set:difference(), set:intersection()
var ss := LoadStylesheet('/xsl/advanced.xsl');
var r  := Transform(ss, doc);

Common XSLT Use Cases

// XML → HTML report
var report := TransformFile('/data/sales.xml', '/xsl/report.xsl');

// XML → CSV
var csv := TransformFile('/data/records.xml', '/xsl/to_csv.xsl');

// Normalize XML structure
var normalized := TransformFile('/in/messy.xml', '/xsl/normalize.xsl');

// Extract data as plain text
var text := TransformFile('/data/doc.xml', '/xsl/extract.xsl');
WriteLn(text);

Package Info

Version1.0.0
Typeclib
C Librarylibxslt + libexslt
Authorgustavo

Dependency

Requires libxml2
Installed automatically by ppm.

Functions

  • LoadStylesheet
  • LoadStylesheetString
  • FreeStylesheet
  • Transform
  • TransformWithParams
  • FreeResult
  • ResultToString
  • ResultToFile
  • ResultToDoc
  • TransformString
  • TransformStringWithString
  • TransformFile
  • TransformFileToFile
  • TransformFileParams
  • OutputMethod / OutputEncoding
  • RegisterEXSLT
  • XSLTVersion / EXSLTVersion

See Also