xmlto

Name

xmlto — apply an XSL stylesheet to an XML document

Synopsis

xmlto [-o output_dir] [-x custom_xsl] [-m xsl_fragment] [-v] {format} {file}

Description

The purpose of xmlto is to convert an XML file to the desired format using whatever means necessary. This may involve two steps:

Procedure 1.

  1. The application of an appropriate XSL stylesheet using an XSL-T processor. This step will always be performed.

  2. Further processing with other tools. This step may not be necessary.

To decide which stylesheet to use and what, if any, needs to be done to post-process the output, xmlto makes use of format scripts, which are simple shell scripts that xmlto calls during the conversion.

The appropriate format script is selected based on the type of XML file and the desired output format. xmlto comes with some format scripts for converting DocBook XML files to a variety of formats. You may specify your own format script by using an absolute filename for format on the command line.

Firstly, if xmlto has not been told explicitly which stylesheet to use (with the -x option), the format script will be called with $1 set to stylesheet. The environment variable XSL_DIR contains the path to the directory containing some useful stylesheets that come with xmlto. The format script should write the name of the stylesheet to use to standard output.

Secondly, after an XSL-T processor has been run using the stylesheet, the format script will be called again, this time with $1 set to post-process. The format script should perform any necessary steps to translate the XSL-T processed output into the desired output format, including copying the output to the desired output directory. For post-processing, the format script is run in a temporary directory containing just the processed output (whose name is stored in XSLT_PROCESSED and whose basename is that of the original XML file with any filename extension replaced with .proc). INPUT_FILE is set to the name of the original XML file, and OUTPUT_DIR is set to the name of the directory that the output (and only the output) must end up in.

-v

Be verbose.

-x stylesheet

Use stylesheet instead of asking the format script to choose one.

-m fragment

Use the provided XSL fragment to modify the stylesheet.

-o directory

Put output in the specified directory instead of the current working directory.

Examples

To convert a DocBook XML document to PDF, use:

xmlto pdf mydoc.xml

To convert a DocBook XML document to HTML and store the resulting HTML files in a separate directory use:

xmlto -o html-dir html mydoc.xml

To convert a DocBook XML document to a single HTML file use:

xmlto html-nochunks mydoc.xml

To modify the output using an XSL fragment use:

xmlto -m ulink.xsl pdf mydoc.xml

To specify which stylesheet to use (overriding the one that the format script would choose, use:

xmlto -x mystylesheet.xsl pdf mydoc.xml