Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: First attempt for DITA -> DocBook with Python #23

Open
wants to merge 16 commits into
base: pyproc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore files
__pycache__
*.patch
*.diff
568 changes: 568 additions & 0 deletions ditatodocbook.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docbook/highlight2db.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
applicable licenses.-->
<!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->

<xsl:stylesheet version="2.0"
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
2 changes: 1 addition & 1 deletion docbook/programming2db.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
applicable licenses.-->
<!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->

<xsl:stylesheet version="2.0"
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output
Expand Down
2 changes: 1 addition & 1 deletion docbook/software2db.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
applicable licenses.-->
<!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->

<xsl:stylesheet version="2.0"
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="*[contains(@class,' sw-d/msgblock ')]">
Expand Down
2 changes: 1 addition & 1 deletion docbook/topic2db.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
applicable licenses.-->
<!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->

<xsl:stylesheet version="2.0"
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


Expand Down
2 changes: 1 addition & 1 deletion docbook/ui2db.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
applicable licenses.-->
<!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->

<xsl:stylesheet version="2.0"
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- to do: attributes -->
Expand Down
2 changes: 1 addition & 1 deletion docbook/util.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
applicable licenses.-->
<!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->

<xsl:stylesheet version="2.0"
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


Expand Down
4 changes: 2 additions & 2 deletions pyproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def py_normpath(context, node):
return path.upper()


def pyproc_xmlparser(args):
def create_xmlparser(args):
"""Return a XMLParser object with the appropriate properties

:param args: the arguments from the argparse object
Expand Down Expand Up @@ -184,7 +184,7 @@ def process(args):
ns.prefix = 'py'
ns.update(dict(normpath=py_normpath))

xmlparser = pyproc_xmlparser(args)
xmlparser = create_xmlparser(args)
root = etree.parse(args.xml, parser=xmlparser)
if args.xinclude:
root.xinclude()
Expand Down
61 changes: 61 additions & 0 deletions tests/dita2db.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[DEFAULT]
# [DITAMAP's_DIR]/converted/[DITAMAP's_NAME]
outputdir =

# STYLEROOT: Style root to write into the DC file. (default: [none])
styleroot =

# CLEANTEMP: Delete temporary directory after conversion. (default: 1)
cleantmp = True

# CLEANID: Remove IDs that are not used as linkends. (default: 1)
cleanid = True

# TWEAK: Space-separated list of vendor tweaks to apply.
# (default: [none], available:
# "fujitsu" - convert emphases starting with "PENDING:" to <remark/>s,
# remove emphases from link text
# )
tweak = fujitsu

# + ENTITYFILE: File name (not path!) of an external file that will be
# included with all XML files. To reuse an existing file, it has to
# exist below [OUTPUTDIR]/xml, if it does not, an empty file will be
# created. (default: "entities.xml")
entityfile = entities.xml


[DITAMAP]
# + [DITAMAP]_DC: Name of output DC file.
# (default: DC-[DITAMAP's_NAME])
dc = DC-%s

# + [DITAMAP]_MAIN: Name of output main file.
# (default: MAIN.[DITAMAP's_NAME].xml)
main = MAIN.%s.xml

# + [DITAMAP]_REPLACE: Space-separated list of files that will be replaced
# by a different DocBook file or removed. Newly included files must
# either already be placed in [OUTPUTDIR]/xml or be available in the
# same directory as [DITAMAP].
# NOTE: Newly included files will be used as-is, without conversion,
# addition of XIncludes or extra entities. Images referenced in newly
# included files will not be copied.
# (default: [none], syntax:
# "relative/path/old.xml=new.xml relative/path/old2.xml=new2.xml ..."
# )
replace =
foo/bar/old.xml=new.xml
bar/fooz/old2.xml=new2.xml

# + [DITAMAP]_REMOVE: Space-separated list of files that will be removed.
# NOTE: This option also removes files that are included within the
# reference of the removed file.
# NOTE: If a file is supposed to be both removed and replaced, it will
# always be removed.
# (default: [none], syntax:
# "relative/path/old.xml relative/path/old2.xml ..."
# )
remove =
zoo/zaz/old3.xml
zoo/zoz/old4.xml
1 change: 1 addition & 0 deletions xslt/create-unique-ids.xsl
47 changes: 47 additions & 0 deletions xslt/dita2docbook_template.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- This file is part of the DITA Open Toolkit project hosted on
Sourceforge.net. See the accompanying license.txt file for
applicable licenses.-->
<!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dita="http://dita-ot.sourceforge.net"
exclude-result-prefixes="dita">

<xsl:import href="docbook/util.xsl"/>
<xsl:import href="docbook/topic2db.xsl"/>
<xsl:import href="docbook/highlight2db.xsl"/>
<xsl:import href="docbook/programming2db.xsl"/>
<xsl:import href="docbook/software2db.xsl"/>
<xsl:import href="docbook/ui2db.xsl"/>

<dita:extension id="dita.xsl.docbook" behavior="org.dita.dost.platform.ImportXSLAction" />

<xsl:output
method="xml"
indent="yes"
omit-xml-declaration="no"
standalone="no"/>


<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- DOCUMENT
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="comment()">
<xsl:comment><xsl:copy/></xsl:comment>
</xsl:template>

<xsl:template match="dita">
<section>
<title/>
<xsl:apply-templates/>
</section>
</xsl:template>


</xsl:stylesheet>
72 changes: 72 additions & 0 deletions xslt/docbook/highlight2db.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- This file is part of the DITA Open Toolkit project hosted on
Sourceforge.net. See the accompanying license.txt file for
applicable licenses.-->
<!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- FORMATTING PHRASES
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<xsl:template match="*[contains(@class,' hi-d/b ')]" name="bold">
<xsl:param name="IDPrefix" select="'b'"/>
<emphasis role="bold">
<xsl:call-template name="setStandardAttr">
<xsl:with-param name="IDPrefix" select="$IDPrefix"/>
</xsl:call-template>
<xsl:apply-templates/>
</emphasis>
</xsl:template>

<xsl:template match="*[contains(@class,' hi-d/i ')]" name="italic">
<xsl:param name="IDPrefix" select="'i'"/>
<emphasis role="italic">
<xsl:call-template name="setStandardAttr">
<xsl:with-param name="IDPrefix" select="$IDPrefix"/>
</xsl:call-template>
<xsl:apply-templates/>
</emphasis>
</xsl:template>

<xsl:template match="*[contains(@class,' hi-d/u ')]" name="underline">
<xsl:param name="IDPrefix" select="'u'"/>
<emphasis role="underline">
<xsl:call-template name="setStandardAttr">
<xsl:with-param name="IDPrefix" select="$IDPrefix"/>
</xsl:call-template>
<xsl:apply-templates/>
</emphasis>
</xsl:template>

<xsl:template match="*[contains(@class,' hi-d/tt ')]" name="monospaced">
<xsl:param name="IDPrefix" select="'tt'"/>
<emphasis role="monospaced">
<xsl:call-template name="setStandardAttr">
<xsl:with-param name="IDPrefix" select="$IDPrefix"/>
</xsl:call-template>
<xsl:apply-templates/>
</emphasis>
</xsl:template>

<xsl:template match="*[contains(@class,' hi-d/sup ')]">
<superscript>
<xsl:call-template name="setStandardAttr">
<xsl:with-param name="IDPrefix" select="'sup'"/>
</xsl:call-template>
<xsl:apply-templates/>
</superscript>
</xsl:template>

<xsl:template match="*[contains(@class,' hi-d/sub ')]">
<subscript>
<xsl:call-template name="setStandardAttr">
<xsl:with-param name="IDPrefix" select="'sub'"/>
</xsl:call-template>
<xsl:apply-templates/>
</subscript>
</xsl:template>


</xsl:stylesheet>
Loading