This is the mail archive of the
docbook-apps@lists.oasis-open.org
mailing list .
[docbook-apps] Programlisting strip-spaces problem
- From: TiP <TiP at tut dot by>
- To: docbook-apps at lists dot oasis-open dot org
- Date: Fri, 1 Oct 2004 09:20:50 +0200
- Subject: [docbook-apps] Programlisting strip-spaces problem
- Reply-to: TiP <TiP at tut dot by>
Hello docbook-apps,
I've made some customizations to progamlisting to strip empty lines
in the beginning and in the end of it. It is a recursive template, but
this is not a problem. The problem is that all internal formatting of
programlisting is lost. For example:
<programlisting>
$ cvs -d:pserver:<parameter>username</parameter>@cvs.site.net:/repository checkout <parameter>module</parameter>
</programlisting>
Template below produces output string by string, omitting newlines
at the end and beginning. And somewhere during conversion internal
formatting for these strings is lost. Like
$ cvs -d:pserver:<TT>username</TT>@cvs.site.net:/repository checkout <TT>module</TT>
becomes
$ cvs -d:pserver:username@cvs.site.net:/repository checkout module
is there any way to avoid losing markup information?
Maybe some exslt functions?
<xsl:template name="trim_newlines">
<xsl:param name="string" select="."/>
<xsl:param name="in_end_mode" select="false()"/> <!-- looking for endstring -->
<xsl:message>
<xsl:copy-of select="$string"/>
<xsl:text> </xsl:text>
</xsl:message>
<xsl:if test="normalize-space($string)"> <!-- prevent endless cycle on empty blocks -->
<xsl:variable name="nl" select="'
'" />
<xsl:variable name="beforenl" select="substring-before($string,$nl)" />
<xsl:variable name="afternl" select="substring-after($string,$nl)" />
<xsl:variable name="nextnl" select="normalize-space(substring-before($afternl,$nl))" />
<xsl:choose>
<xsl:when test="not($in_end_mode) and string-length(normalize-space($beforenl)) = 0">
<xsl:call-template name="trim_newlines">
<xsl:with-param name="string" select="$afternl" />
<xsl:with-param name="in_end_mode" select="$in_end_mode or $nextnl" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="concat($beforenl,$nl)"/>
<xsl:call-template name="trim_newlines">
<xsl:with-param name="string" select="$afternl" />
<xsl:with-param name="in_end_mode" select="true()" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
Tnx.
--
TiP