[xsl] Re: losing significant whitespace with normalize-space

Subject: [xsl] Re: losing significant whitespace with normalize-space
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Tue, 16 Jul 2002 12:39:15 -0700 (PDT)
--- "Bradford, Denis" <denisb at rational dot com> wrote:

 
> Generating text output (an apropos file) from a docbook reference
> manual,
> I'm not able to preserve whitespace around the inline <command>
> elements in
> the <refpurpose> element below. 
> 
> Code snippet:
> 
> <refentry>
> <refnamediv>
> <refname>
> <indexterm><primary>configuration records</primary></indexterm>
> catcr
> </refname>
> <refpurpose>Displays configuration record 
> created by <command>xmake</command>, <command>ymake</command>
> , or <command>xaudit</command> 
> </refpurpose>
> 
> The desired output is a single line, like this:
> 
> catcr                     Displays configuration record created by
> xmake,
> ymake, or xaudit
> 
> What I'm getting is this: 
> 
> catcr                     Displays configuration record created
> byxmake,ymake, orxaudit
> 
> 
> Using normalize-space is the only way I've found to eliminate the
> newlines,
> but then I lose the whitespace around the command elements is
> stripped.
> The
> preserve-space (and strip-space) functions don't seem to have any
> effect,
> presumably because refpurpose is not a text-only element. Here's the
> current
> state of the stylesheet - can anybody suggest what I'm doing wrong?
> 
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";;
>                 version="1.0">
> <xsl:output method="text" 
>             indent="no"/>
> 
> <xsl:preserve-space elements="refpurpose"/>
> 
> <xsl:template match="/">
> 
>    <xsl:variable name="newline">
> <xsl:text>
> </xsl:text>
>    </xsl:variable>
>   
>    <xsl:for-each select="book/reference/refentry/refnamediv">
>       <xsl:apply-templates select="refname"/>
>       <xsl:apply-templates select="refpurpose">
> 	     <xsl:with-param name="refnameLen"
> select="string-length(refname/text())"/>
> 	     <xsl:with-param name="refnameField" select="'
> '"/>
>       </xsl:apply-templates>
>       <xsl:value-of select="$newline"/>
>    </xsl:for-each>
> </xsl:template>
> 
> <xsl:template match="refname">
>     <xsl:apply-templates/>
> </xsl:template>
> 
> <xsl:template match="refpurpose">
>    <xsl:param name="refnameField"/>
>    <xsl:param name="refnameLen"/>
>    <xsl:value-of select="substring($refnameField,$refnameLen)"/> <!--
> Pad
> with 25 spaces minus refname -->
>    <xsl:apply-templates/> 
> </xsl:template>
> 
> <xsl:template match="*/text()">
>    <xsl:value-of select="normalize-space(.)"/>
> </xsl:template>
> 
> <xsl:template match="indexterm"></xsl:template>
> <xsl:template match="indexterm/primary"></xsl:template>
> <xsl:template match="indexterm/secondary"></xsl:template>
> <xsl:template match="indexterm/secondary"></xsl:template>
> 
> </xsl:stylesheet>

Hi Brad,

Use:

  <xsl:template match="text()">
    <xsl:value-of select="translate(., '&#xA;&#xD;', '')"/>
  </xsl:template>


Hope this helped.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread