Search code examples
docbook

Switch between multiple languages in DocBook program listings


The Clutter Cookbook (created using DocBook) has code examples in C. I would like to add examples in Vala (another programming language) and allow the user to switch between the two languages by clicking a link. How can I do this? Should I just generate two versions of each page?


Solution

  • Conditional text (profiling) could be of help here:

    <para>See this example: <phrase code="c">some C code</phrase> 
                            <phrase code="vala">some Vala code</phrase>
    </para>
    

    Depending on your processor you can set options to choose one code language. For xsltproc you use the special stylesheet html/profile-chunk.xsl and add --stringparam profile.code "Vala" to create a conditional XML version for Vala.

    xsltproc --output document.vala.xml --stringparam profile.code "vala" ..path-to/html/profile-chunk.xsl document.xml
    

    Then you do your usual tool chain with your own stylesheet and with the Vala version of your document (document.vala.xml).

    This way you can create the same document twice but with different code.

    For more details see http://www.sagehill.net/docbookxsl/Profiling.html and for the linking part have a look at http://www.sagehill.net/docbookxsl/OlinkVariations.html#ProfilingOlinks