Menu

Stylesheets

Anonymous
2014-12-20
2015-06-12
  • Anonymous

    Anonymous - 2014-12-20

    Hi,
    I have been experimenting with making my own xsl files for fo and html. I have made a simple one that changes to A4 paper for fo. I then copied the shared style root to a local dir and changed the fo/docbook.xsl to include my xsl. So far everything worked.

    But I guess this is not the way to go, I have been trying to get DAPS to read my (local) xsl files first and then include the shared ones, but I cant get it to work. I have tried the STYLEROOT, STYLEFO, STYLEROOT parameters in the DC file but with daps check it only shows the shared ones.

    Is there a guide for how to do this ? Or is that the work-in-progress chapter 9 ?

    Thankful for any hints,

    /TC

     
  • Frank Sundermeyer

    Hi,

    admittedly this reply comes a "little bit" late - I'm awfully sorry, but I completely overlooked this question. While the answer may not be of use to the original poster anymore, it may be interesting for others...

    The recommended way to write your own stylesheets is to customize the original DocBook stylesheets - very similar to what you would do when customizing an existing CSS.

    Create the directory structure

    Start by duplicating the directory structure (without any files) of the original DocBook stylesheets (this is required by daps). For fo this would look like:

    mystyle/
     |-fo/
    

    Adding HTML you get

    mystyle/
     |-fo/
     |-html/
    

    Only create directories for stylesheets you would like to customize!

    Next you need to copy the image directory from the original stylesheets. In openSUSE this would be

    cp -r /usr/share/xml/docbook/stylesheet/nwalsh/current/images mystyle/
    

    (The path may vary on other distributions)

    Create the stylesheets

    To create your own fo stylesheet, create a file mystyle/fo/docbook.xsl with the following content:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fo="http://www.w3.org/1999/XSL/Format">
    
      <xsl:import    
        href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>
    
    </xsl:stylesheet>
    

    The important part is the <xsl:import ...=""> line. This imports the original DocBook stylesheets for fo (DocBook 4 in this case). In order to be portable, do not use file-references, but rather the URI specified above. It is correctly resolved to a local file via a catalog entry. This URI is the same on every platform and system.</xsl:import>

    It is not necessary (and not recommended) to copy the original stylesheet files and to make adjustments within these copies. The way to customize the stylesheets is to import everything and then change parts by overwriting the paramaters and templates you have imported.

    This step needs to be done for all directories you have created. Each directory has to have at leat a docbook.xsl file with the content shown above. Replace the /fo/ part with the respective directory in the import statement.

    Customizing

    Now you can start customising, e.g. by setting parameters. The following example sets the paper size to A4 and makes variablelists look good ;-):

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fo="http://www.w3.org/1999/XSL/Format">
    
      <xsl:import    
        href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>
    
      <xsl:param name="paper.type" select="'A4'"/>
      <xsl:param name="variablelist.term.break.after" select="1"/>
    
    </xsl:stylesheet>
    

    Use the same method to adjust the HTML stylesheets. The URI for importing the original stylesheets is http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl

    Changing/setting parameters is a good start to customize the sytlesheets. Refer to
    http://docbook.sourceforge.net/release/xsl/current/doc/param.html
    for a complete parameter list.

    Of course you are not limited to setting parameters. See http://docbook.sourceforge.net/release/xsl/current/doc/developer.html
    for more information.
    Have a look at the SUSE documentation stylesheets as an example for extensive stylesheet adjustments:
    https://github.com/openSUSE/suse-xsl

    Making DAPS use my styles

    To make DAPS use your custom styles, set the parameter STYLEROOT in the document's DC-file:

    ## Doc Config File for FOOBAR
    ##
    ## Basics
    MAIN="MAIN.FOOBAR.xml"
    ROOTID="foobar.deployment"
    
    # stylesheet location
    STYLEROOT="/home/documentation/stylesheets/mystyle"
    

    Stylesheet fallbacks

    In case mystyle/ only contains stylesheets for fo, DAPS automatically falls back to the original stylesheets in case you build your document with another format such as HTML or ePUB.
    In case you have custom stylesheets in different locations, you can specify a fallback styleroot with FB_STYLEROOT in the DC file. If set, DAPS will look at this styleroot for a fallback. If this also fails, the original DocBook stylesheets will be used. It is not possible to specify mor than one FB_STYLEROOT.

     

Anonymous
Anonymous

Add attachments
Cancel