LinuxCommandLibrary

xsltproc

Transform XML documents using XSL stylesheets

SYNOPSIS

xsltproc [options] stylesheet [xml-document]

PARAMETERS

-o file, --output file
    Specifies the output file. If omitted, the transformation result is written to standard output.

--stringparam name value
    Passes a string parameter with the given name and value to the stylesheet.

--param name value
    Passes an XPath expression result as a parameter to the stylesheet. The value is evaluated as an XPath expression.

--nonet
    Disables network access for fetching DTDs, external entities, or remote stylesheets, enhancing security.

--novalid
    Disables DTD validation of the input XML document. This can speed up processing if validation is not required.

--xinclude
    Processes XInclude elements in the input XML document before transformation.

--html
    Treats the input document as HTML, attempting to parse it as such before applying the XSLT stylesheet.

--version
    Displays the version number of xsltproc and the underlying libxslt and libxml2 libraries.

--timing
    Displays the time taken for various stages of processing, including parsing and transformation.

--maxdepth depth
    Sets the maximum template recursion depth to prevent infinite loops, with a default usually around 250.

--encoding encoding
    Specifies the encoding for the output document, overriding any encoding specified in the stylesheet.

--path path
    Adds a directory path to the search list for stylesheets, DTDs, or other external resources.

DESCRIPTION

xsltproc is a command-line tool that applies XSLT (Extensible Stylesheet Language Transformations) stylesheets to XML documents. It is an integral part of the libxslt library, which is built on top of libxml2.

Its primary function is to transform XML input into various output formats, such as HTML, plain text, or other XML structures, based on the rules defined in an XSLT stylesheet. xsltproc is widely used in scripting environments and automated workflows for document generation, data conversion, and content manipulation. While it primarily supports XSLT 1.0, it also includes support for many EXSLT extensions.

CAVEATS

xsltproc primarily implements the XSLT 1.0 specification. It does not support XSLT 2.0 or XSLT 3.0 features, which offer more advanced data types, schema awareness, and powerful new functions. For these, consider alternatives like Saxon.

Processing very large XML documents or complex stylesheets can consume significant memory and CPU resources. It's advisable to test performance with typical datasets.

By default, xsltproc can fetch external resources (like DTDs, entities, or imported stylesheets) over the network. For security-sensitive environments, always use the --nonet option to prevent unintended network access or potential exploits.

XSLT 1.0 AND EXSLT SUPPORT

xsltproc is designed to fully support the XSLT 1.0 specification and includes robust support for common EXSLT extensions (e.g., str, math, common, sets, dates-and-times), which provide additional functions not found in the core XSLT 1.0 standard.

STANDARD INPUT/OUTPUT

When no input XML document is specified, xsltproc reads from standard input (stdin), allowing for piping XML data directly to it from other commands. Similarly, if no output file is specified, the transformed result is written to standard output (stdout), making it easily usable in shell pipelines for further processing.

HISTORY

xsltproc is an integral part of the libxslt project, which itself is built upon the libxml2 XML parsing library. Both libxml2 and libxslt were initiated by Daniel Veillard in the late 1990s as open-source, C-based libraries to provide robust and fast XML and XSLT processing capabilities. xsltproc emerged as the command-line interface to libxslt, making its powerful features accessible directly from the shell, thus becoming a staple in Unix-like environments for automated XML transformations. Its development has focused on performance and standards compliance within the XSLT 1.0 paradigm.

SEE ALSO

xmllint(1), xmlstarlet(1), saxon(1)

Copied to clipboard