Skip to main content

DITA Custom XSLT

dita-custom-xslt is a set of XSLT stylesheets that convert a generic DITA topic to a specialized DITA concept, reference, or task. dita-convert is a Python 3 package that provides a convenient access to these stylesheets and a command-line utility to perform the conversions.

In combination with asciidoctor-dita-vale, asciidoctor-dita-topic, and dita-cleanup, this project can be used to rapidly convert AsciiDoc content to DITA:

  1. Identify incompatible markup in the AsciiDoc source file:

    vale source_file.adoc
    
  2. Convert the AsciiDoc file to a generic DITA topic:

    dita-topic source_file.adoc
    
  3. Convert the generic DITA topic to a specialized DITA concept, reference, or task:

    dita-convert -g source_file.dita -o output_file.dita
    
  4. Optional: Clean up the resulting DITA file if necessary:

    dita-cleanup -iD ../images -X . output_file.dita
    

Installation

Install the dita-convert Python package:

python3 -m pip install --upgrade dita-convert

Usage

Using the command-line interface

To convert a DITA topic to a specialized DITA content type, run the following command:

dita-convert -t TYPE TOPIC_FILE

Available TYPE values are concept, reference, or task.

By default, the script treats the source file as a generic DITA topic. To convert files generated by asciidoctor-dita-topic that follow the guidelines for modules as defined in the Modular Documentation Reference Guide, add the -g option:

dita-convert -t TYPE -g TOPIC_FILE

For generated topics, this is the preferred method because asciidoctor-dita-topic includes predictable headings that allow parts of the document to be correctly identified as prereq, result, tasktroubleshooting, postreq, and related-links. If the original AsciiDoc files included valid content type definitions, you can also omit the -t option.

For a complete list of available command-line options, run dita-convert with the -h option:

dita-convert -h

Using the Python interface

To convert a DITA topic to a specialized DITA content type, the dita-convert package exports the corresponding to_concept(), to_reference(), to_task(), to_concept_generated(), to_reference_generated(), and to_task_generated() functions that return an ElementTree object:

import sys

from lxml import etree
from dita.convert import to_task

# Parse the contents of a sample DITA topic file:
topic = etree.parse("topic.dita")

# Report possible errors:
try:
    # Convert the DITA topic to a DITA task:
    task  = to_task(topic)
except etree.XSLTApplyError as msg:
    # Print the error message to standard error output:
    print(msg, file=sys.stderr)

    # Terminate the script:
    sys.exit(1)

# Report possible warnings:
for error in to_task.error_log:
    # Print the warning message to standard error output:
    print(error.message, file=sys.stderr)

# Print the resulting XML to standard output:
print(str(task))

If you prefer to work with the underlying XSLT stylesheets directly, you can access their Path objects as follows:

from dita.convert import xslt

# Print the full path to the XSLT stylesheet for DITA reference:
print(xslt.reference)

Available variables are concept, reference, task, concept_generated, reference_generated, and task_generated.

Copyright © 2024–2026 Jaromir Hradilek

This program is free software, released under the terms of the MIT license. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Metadata

Release files for dita-convert 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dita-convert 1.5.0
File Size Uploaded Provenance Actions
dita_convert-1.5.0.tar.gz 26.0 kB Without provenance Details for dita_convert-1.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dita-convert 1.5.0
File Interpreter ABI Platform Actions
dita_convert-1.5.0-py3-none-any.whl Python 3 none any Details for dita_convert-1.5.0-py3-none-any.whl

Total release size: 58.4 kB

Release files / dita_convert-1.5.0.tar.gz

Download URL dita_convert-1.5.0.tar.gz
Size 26.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e93c0626351951435f6bf2947d9e523b68c3c3a59dd51e09e3449cf48cfbffa9
BLAKE2b-256 checksum
How to use checksums
418780b0075a8eee430abb4f9a8f5e1f187c5e850e464be86f54e90f5b5c6b33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.10

Release files / dita_convert-1.5.0-py3-none-any.whl

Download URL dita_convert-1.5.0-py3-none-any.whl
Size 32.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ab5472f335617377ff3286565f12aaee8c570cc164dd0cf6438659d27e797b8
BLAKE2b-256 checksum
How to use checksums
3ace8148a79e390d01948a2fbc6e3909b53522a76ce9ed19093f2f304995e768
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.10

Security for dita-convert 1.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page