Here's an xslt for converting DocBook to MoinMoin. This is just a start...you'll have to adjust it to your needs a bit. For example, I don't handle sect1, sect2, just recursive sections. I also don't yet deal with xrefs and many other constructs...this was for a specific document. Putting it here for safe keeping.

<?xml version ="1.0"?>

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

  <xsl:output method="text" indent="no"/>


  <xsl:template match="title[parent::book or parent::part or parent::chapter or parent::section]">
<xsl:variable name="head"><xsl:for-each select="ancestor-or-self::section|ancestor-or-self::part|ancestor-or-self::chapter|ancestor-or-self::book"><xsl:text>=</xsl:text></xsl:for-each></xsl:variable>
<xsl:if test="parent::*[@id]">&lt;&lt;Anchor(<xsl:value-of select="parent::*/@id"/>)>><xsl:text>
</xsl:text></xsl:if>
        <xsl:value-of select="concat($head, ' ', normalize-space(.), ' ', $head)"/><xsl:text>

</xsl:text>
        <xsl:apply-templates select="*[not(self::title)]"/>
  </xsl:template>

        <xsl:template match="listitem[parent::orderedlist]">
<xsl:variable name="depth"><xsl:for-each select="ancestor-or-self::listitem"><xsl:text> </xsl:text></xsl:for-each></xsl:variable>
<xsl:value-of select="$depth"/><xsl:text>1. </xsl:text><xsl:apply-templates/>
        </xsl:template>

        <xsl:template match="listitem[parent::itemizedlist]">
<xsl:variable name="depth"><xsl:for-each select="ancestor-or-self::listitem"><xsl:text> </xsl:text></xsl:for-each></xsl:variable>
<xsl:if test="not(preceding-sibling::listitem)"><xsl:text>
</xsl:text></xsl:if><xsl:value-of select="$depth"/><xsl:text>* </xsl:text><xsl:apply-templates/>
        </xsl:template>

  <xsl:template match="para"><xsl:apply-templates/><xsl:text>

</xsl:text>
  </xsl:template>

  <xsl:template match="emphasis[@role='bold']|guilabel|guibutton">'''<xsl:apply-templates/>'''</xsl:template>
  <xsl:template match="emphasis[@role='italic' or not(@role)]">''<xsl:apply-templates/>''</xsl:template>
  <xsl:template match="literal|code|emphasis[@role='monospace']">{{{<xsl:apply-templates/>}}}</xsl:template>
  <xsl:template match="programlisting|screen">
{{{
<xsl:copy-of select="./text()"/>
}}}
  </xsl:template>

  <xsl:template match="indexterm"/>

<xsl:template match="glossary">
<xsl:variable name="head"><xsl:for-each select="ancestor-or-self::section|ancestor-or-self::part|ancestor-or-self::chapter|ancestor-or-self::book"><xsl:text>=</xsl:text></xsl:for-each></xsl:variable>
        <xsl:value-of select="concat($head, ' Glossary ', $head)"/><xsl:text>

</xsl:text>
        <xsl:apply-templates select="*[not(self::title)]"/>
  </xsl:template>

  <xsl:template match="glossentry">
<xsl:if test="@id">&lt;&lt;Anchor(<xsl:value-of select="@id"/>)>><xsl:text>
</xsl:text></xsl:if>
<xsl:text> </xsl:text><xsl:value-of select="glossterm"/>:: <xsl:apply-templates select="*[not(self::glossterm)]"/><xsl:text>
</xsl:text>
  </xsl:template>

  <xsl:template match="ulink[normalize-space(.) = '']"><xsl:value-of select="@url"/></xsl:template>
  <xsl:template match="ulink[normalize-space(.) != '']">[[<xsl:value-of select="@url"/>|<xsl:value-of select="normalize-space(.)"/>]]</xsl:template>

  <xsl:template match="glossterm[not(parent::glossentry)]">[[#<xsl:value-of select="@linkend"/>|<xsl:apply-templates/>]]</xsl:template>

  <xsl:template match="formalpara">'''<xsl:value-of select="title"/>'''. <xsl:apply-templates select="para"/></xsl:template>

<!-- This will only handle the simplest of tables -->
  <xsl:template match="row">
||<xsl:for-each select="entry"><xsl:if test="ancestor::thead">''' </xsl:if><xsl:value-of select="."/><xsl:if test="ancestor::thead"> '''</xsl:if>||</xsl:for-each></xsl:template>

<xsl:template match="glossseealso">[[#<xsl:value-of select="@otherterm"/>|<xsl:value-of select="."/>]]</xsl:template>

  </xsl:stylesheet>

MoinMoin: DavidCramer/DocBookToMoinMoin (last edited 2009-01-21 21:55:39 by DavidCramer)