docbook-apps

  • 1.  modular customization layer with imports.

    Posted 01-28-2008 22:27
    I am trying to override progrmalisting in docbook with a code that will
    provide indentation for included XML code. I need to be able to generate
    pdf and html. So I divided my xslt into 3 files. One off them has the
    common templates, and the rest has the formating templates.
    The one that has the common templates can be called "common.xsl". My
    question will deal with the html version only and I will figre out the
    FO version later.

    The common.xsl has a template that mathes programlisting.


    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:formatting="http://indentation.for.the.source.code">
    <xsl:import href="/opt/docbook/xhtml/docbook.xsl" />
    <xsl:strip-space elements="*" />
    <xsl:template match="programlisting">
    <xsl:choose>
    <xsl:when test="self::*">
    <formatting:INDENT>
    <formatting:TAG>
    <xsl:text><</xsl:text>
    <formatting:TAGNAME>
    <xsl:value-of select="name(.)" />
    </formatting:TAGNAME>
    <xsl:for-each select="@*">
    <formatting:ATTRIBUTENAME>
    <xsl:value-of
    select="concat(' ',name(.))" />
    </formatting:ATTRIBUTENAME>
    <xsl:text>=</xsl:text>
    <formatting:ATTRIBUTEVALUE>
    <xsl:value-of
    select="concat('"',.,'"')" />
    </formatting:ATTRIBUTEVALUE>
    </xsl:for-each>
    <xsl:text>></xsl:text>
    </formatting:TAG>
    <xsl:apply-templates />
    <formatting:TAG>
    <xsl:text></</xsl:text>
    <formatting:TAGNAME>
    <xsl:value-of select="name(.)" />
    </formatting:TAGNAME>
    <xsl:text>></xsl:text>
    </formatting:TAG>
    </formatting:INDENT>
    </xsl:when>
    </xsl:choose>
    </xsl:template>
    </xsl:stylesheet>

    The html one formats the added tags:


    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:formatting="http://indentation.for.the.source.code">
    <xsl:strip-space elements="*" />
    <xsl:template match="/">
    <xsl:apply-templates />
    </xsl:template>
    <xsl:template match="formatting:INDENT" mode="phase-2">

    <xsl:apply-templates />

    </xsl:template>
    <xsl:template match="formatting:TAGNAME">

    <xsl:apply-templates />

    </xsl:template>
    <xsl:template match="formatting:ATTRIBUTENAME">

    <xsl:apply-templates />

    </xsl:template>
    <xsl:template match="formatting:ATTRIBUTEVALUE">

    <xsl:apply-templates />

    </xsl:template>
    <xsl:template match="formatting:TAG">

    <xsl:apply-templates />

    </xsl:template>
    <xsl:template match="formatting:CONTENTS">

    <xsl:apply-templates />

    </xsl:template>
    </xsl:stylesheet>


    I am not able to find anyway to combine these two and get the correct
    output. I tried to use import in the html sheet and inport the
    common.xsl, but that did not help. Can anyone suggest a solution ?





  • 2.  Re: [docbook-apps] modular customization layer with imports.

    Posted 01-29-2008 19:47
    Hi,
    Your current setup outputs the <formatting:*> elements to the output, and
    your templates that match on formatting:* are looking for such elements from
    the input. The output stream is not automatically processed again by
    templates reading the input.

    You need to save your generated <formatting:*> elements into a variable,
    then use exslt:node-set() to turn it into a node set, and then apply
    templates to it. Something like this:

    <xsl:template match="programlisting">
    <xsl:variable name="temp">
    <formatting:INDENT>
    <formatting:TAG>
    etc.
    </xsl:variable>

    <xsl:apply-templates select="exslt:node-set($temp/*)"/>

    And you need to add the exslt namespace declaration to your customization
    layer.

    Bob Stayton
    Sagehill Enterprises
    bobs@sagehill.net