This is the mail archive of the
docbook-apps@lists.oasis-open.org
mailing list .
Re: [docbook-apps] Programlisting strip-spaces problem
- From: "Bob Stayton" <bobs at sagehill dot net>
- To: "TiP" <TiP at tut dot by>, <docbook-apps at lists dot oasis-open dot org>
- Date: Tue, 5 Oct 2004 23:18:42 -0700
- Subject: Re: [docbook-apps] Programlisting strip-spaces problem
- References: <132738003.20041001092050@tut.by>
The basic problem is that your current template converts the element to a
string. When you convert an element to a string in XSLT, the child elements
are converted to strings too. So your first substring expressions do the
reduction.
You'll need to handle text() nodes and element nodes differently, so you can
process the elements as elements. I don't have an off-the-shelf solution
for what you want to do, but maybe someone else does.
Bob Stayton
Sagehill Enterprises
DocBook Consulting
bobs@sagehill.net
----- Original Message -----
From: "TiP" <TiP@tut.by>
To: <docbook-apps@lists.oasis-open.org>
Sent: Friday, October 01, 2004 12:20 AM
Subject: [docbook-apps] Programlisting strip-spaces problem
> 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
>
>
>