Skip to main content

Convert a generic DITA topic to a specialized concept, task, or reference.

Project description

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:

    asciidoctor -r dita-topic -b dita-topic -S secure 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. Clean up the resulting DITA file if necessary:

    dita-cleanup -iI -D ../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

Copyright © 2024, 2025 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dita_convert-1.4.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dita_convert-1.4.0-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file dita_convert-1.4.0.tar.gz.

File metadata

  • Download URL: dita_convert-1.4.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dita_convert-1.4.0.tar.gz
Algorithm Hash digest
SHA256 b0bb7d2b3f1e438c95691518a7d7961c59222c80afd9d45c426b97d66b760a97
MD5 81bfebe787be594511dcde32b8a818ff
BLAKE2b-256 6197ca5380b16c0e9579c3cd0fe93b9a1a05e72293f517630669c668738d0885

See more details on using hashes here.

File details

Details for the file dita_convert-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: dita_convert-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dita_convert-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c791b08bb704eb1754a8a122974e854705238d741e6ba0fc7632d6ca6aca6cc9
MD5 03a10e9ea6f5fe42aca1ca700626716c
BLAKE2b-256 c6485b7981b6971a9080b1f5416e9e28ae4574de2d507f3c1824beafc3953197

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page