How do I Multipass processing in a Docbook

73 Views Asked by At

I am new to docbook, but can not find a decent way to do multiples transformation in a single step; some post-processing on the result is needed. I would like to add a section with title and some text in the docbook xml structure in the first step then generate the transformation to get my pdf file in the second step

simpleXMLtoXML.xsl

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns:d="http://docbook.org/ns/docbook" 
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">

    <xsl:strip-space elements="*"/>
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
    <xsl:template match="node(  ) | @*"> 
        <xsl:copy>  
            <xsl:apply-templates select="@* | node(  )"/>  
        </xsl:copy>
    </xsl:template>         
    <xsl:template match="d:chapter">

        <xsl:copy> 
            <xsl:copy-of select="@*"/>
            <xsl:copy-of select="*"/>
            <xsl:element name="section" xmlns="http://docbook.org/ns/docbook">
                        <d:title> Cette section a été ajoutée </d:title>
                        <d:para> ce texte a été ajouté </d:para>
            </xsl:element>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

My XSl file to generate PDF

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:fo="http://www.w3.org/1999/XSL/Format"
        xmlns:set="http://exslt.org/sets"
        xmlns:saxon="http://icl.com/saxon"
        xmlns:exsl="http://exslt.org/common"
        extension-element-prefixes="exsl"
        xmlns:d="http://docbook.org/ns/docbook"
        exclude-result-prefixes="d"
        version="1.0">

    <?cco_xsltype addon="DocBook5.0" toolchain="DocBook_to_PDF_FOP"?>
    <?cco_xsltype addon="DocBook5.0" toolchain="DocBook_to_PS_FOP"?>
<!-- Import standard -->
<xsl:import href="simpleXMLtoXML.xsl"/>
<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/profile-docbook.xsl"/>

<!-- DocBook XSL Parameters -->


<xsl:param select="1" name="fop1.extensions"/>

<xsl:param name="paper.type">A4</xsl:param>


<xsl:template match="book">

<xsl:variable name="content"> 
        <xsl:apply-imports/> 
        </xsl:variable> 

<xsl:apply-templates select="exsl:node-set($content)"/>     
</xsl:template>

</xsl:stylesheet>

Thanks for any help.

1

There are 1 best solutions below

4
Martin Honnen On

I would think that using a mode e.g.

<xsl:template match="node() | @*" mode="change"> 
    <xsl:copy>  
        <xsl:apply-templates select="@* | node()" mode="change"/>  
    </xsl:copy>
</xsl:template>         
<xsl:template match="d:chapter" mode="change">

    <xsl:copy> 
        <xsl:copy-of select="@*"/>
        <xsl:copy-of select="*"/>
        <xsl:element name="section" xmlns="http://docbook.org/ns/docbook">
                    <d:title> Cette section a été ajoutée </d:title>
                    <d:para> ce texte a été ajouté </d:para>
        </xsl:element>
    </xsl:copy>
</xsl:template>




<xsl:variable name="content"> 
        <xsl:apply-templates mode="change"/> 
</xsl:variable>

<xsl:template match="/">
   <xsl:apply-templates select="exsl:node-set($content)/node()"/>     
</xsl:template>

is a clean way to separate steps.