Skip to content

Instantly share code, notes, and snippets.

@peterfleck
Last active May 14, 2018 15:29
Show Gist options
  • Save peterfleck/e33c8f99667987dcb84ebf7f5c0a5b05 to your computer and use it in GitHub Desktop.
Save peterfleck/e33c8f99667987dcb84ebf7f5c0a5b05 to your computer and use it in GitHub Desktop.
Snippets of Docbook

Docbook Snippets

The Docbook guide can be found here https://tdg.docbook.org/

Paragraphs

Indent paragraphs and allow alignment

  <xsl:attribute-set name="normal.para.spacing">
    <xsl:attribute name="space-before.optimum">0em</xsl:attribute>
    <xsl:attribute name="space-before.minimum">0em</xsl:attribute>
    <xsl:attribute name="space-before.maximum">0em</xsl:attribute>
  </xsl:attribute-set>

  <xsl:template match="d:para[preceding-sibling::d:para]">
    <fo:block text-indent="5mm">
      <xsl:apply-imports/>
    </fo:block>
  </xsl:template>

  <xsl:template match="d:para[1] | d:para[preceding-sibling::*[1][not(self::d:para)]]" priority="6">
    <fo:block text-indent="0em">
      <xsl:apply-imports/>
    </fo:block>
  </xsl:template>
  
    <xsl:attribute-set name="para.properties" use-attribute-sets="normal.para.spacing">
    <xsl:attribute name="text-align">
      <xsl:choose>
        <xsl:when test="@role = 'left'">left</xsl:when>
        <xsl:when test="@role = 'justify'">justify</xsl:when>
        <xsl:when test="@role = 'right'">right</xsl:when>
        <xsl:when test="@role = 'center'">center</xsl:when>
        <xsl:otherwise>inherit</xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
    <xsl:attribute name="text-indent">
      <xsl:choose>
        <xsl:when test="@role = 'indent'">5mm</xsl:when>
        <xsl:when test="@role = 'double-indent'">10mm</xsl:when>
        <xsl:when test="@role = 'print-no-indent'">0in</xsl:when>
        <xsl:when test="@role = 'no-indent'">0in</xsl:when>
        <xsl:otherwise>inherit</xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
  </xsl:attribute-set>
  

Inlines

Add extras to <emphasis>

   <xsl:template match="d:emphasis">
  <xsl:choose>
    <xsl:when test="@role='bold' or @role='strong'">
      <xsl:call-template name="inline.boldseq"/>
    </xsl:when>
    <xsl:when test="@role='underline'">
      <fo:inline text-decoration="underline">
        <xsl:call-template name="inline.charseq"/>
      </fo:inline>
    </xsl:when>
    <xsl:when test="@role='strikethrough' or @role='line-through'">
      <fo:inline text-decoration="line-through">
        <xsl:call-template name="inline.charseq"/>
      </fo:inline>
    </xsl:when>
    <xsl:when test="@role='overline'">
      <fo:inline text-decoration="overline">
        <xsl:call-template name="inline.charseq"/>
      </fo:inline>
    </xsl:when>
    <xsl:when test="@role='double'">
      <fo:inline border-after-style="double" border-after-width="1mm">
        <xsl:call-template name="inline.charseq"/>
      </fo:inline>
    </xsl:when>
    <xsl:otherwise>
      <xsl:variable name="depth" select="count(ancestor::d:emphasis  [not(contains(' bold strong underline strikethrough ', concat(' ', @role, ' ')))]  )"/>
      <xsl:choose>
        <xsl:when test="$depth mod 2 = 1">
          <fo:inline font-style="normal">
            <xsl:apply-templates/>
          </fo:inline>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="inline.italicseq"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Page-break

  <xsl:template match="processing-instruction('hard-pagebreak')">
   <fo:block break-after="page"/>
  </xsl:template>

HTML Copy RDFa attributes

<xsl:template name="common.html.attributes">
  <xsl:param name="inherit" select="0"/>
  <xsl:param name="class" select="local-name(.)"/>
    <xsl:apply-templates select="." mode="common.html.attributes">
      <xsl:with-param name="class" select="$class"/>
      <xsl:with-param name="inherit" select="$inherit"/>
    </xsl:apply-templates>

   <xsl:apply-templates select="." mode="rdfa.html.attributes"/>
</xsl:template>

<xsl:template match="*" mode="rdfa.html.attributes">
  <xsl:copy-of select="@vocab"/>
  <xsl:copy-of select="@typeof"/>
  <xsl:copy-of select="@property"/>
  <xsl:copy-of select="@resource"/>
  <xsl:copy-of select="@Prefix"/>
</xsl:template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment