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 ?