cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Johannes Textor <>
Subject Re: AW: newlines to <br>
Date Fri, 10 Dec 2004 08:40:09 GMT
Hi Merico,

You might want to use "white-space:pre-line", which still collapses
white space, breaks lines at box borders and on occurence of "\n" in text.
However, "pre" is the only one that works at least in Mozilla. None seem
to work in early IE versions, so I still prefer the XSL solution.

Some words about "elegance": As you say. combined with 
and maybe a "mode" attribute, you can just match any "text()" node in 
that mode
and replace all newlines in it. That's quite cool.

However, XSL is not an elegant solution when it comes to replacing multiple
tags. For instance, I had one form where the user should be able to enter
links (in HTML "a" tag format) as well as use "<b> ... </b>" to make text
bold. All text was saved into a DB straightforward, and I used an XSL to
"un-escape" the permitted tags back into XML. I'm attaching the stylesheet
at the end of the mail so you can see just how ugly it is, even though 
it works.
Those are in fact the only moments where I wished I'd still be able to 
use those
handy PHP functions ...


Merico Raffaele wrote:

>Hi Johannes
>Thanks a lot for your support and the script.
>In the mean time I have found an additional/alternative solution based on
><div style="white-space:pre;">
>At the moment I'm still not able to judge which is the *most elegant* way to
>solve problems of formatting strings-parts within a string (<br> is just one
>formatting aspect in a multiline field). In the mean time again I have also
>realized that it makes a big difference in processing text-nodes with
><xsl:value-of/> or <xsl:apply-templates/>. The last approach combined with
>identity transformation enables one to include some basic formatting tags
>(as list, bold, italic and so on) within a string.
>Thanks again ... Raffaele

    <!-- in der datenbank eingegebene b-tags wieder "unescapen" -->
    <xsl:template name="b-replace">
        <xsl:param name="word"/>
        <xsl:variable name="open"><xsl:value-of 
        <xsl:variable name="close"><xsl:value-of 
            <xsl:when test="contains($word,$open)">
                <xsl:call-template name="br-replace">
                    <xsl:with-param name="word" 
                <xsl:call-template name="br-replace">
                        <xsl:with-param name="word" 
                <xsl:call-template name="b-replace">
                    <xsl:with-param name="word" 
                <xsl:call-template name="br-replace">
                    <xsl:with-param name="word" select="$word"/>

    <!-- http:// und mailto: - Links erkennen und ersetzen -->
    <xsl:template name="link-replace">
        <xsl:param name="text"></xsl:param>
        <xsl:variable name="beforetext"><xsl:choose>
            <xsl:when test="contains($text,'http://')"><xsl:value-of 
            <xsl:when test="contains($text,'mailto:')"><xsl:value-of 
            <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
        <xsl:variable name="aftertext"><xsl:choose>
            <xsl:when test="contains($text,'http://')"><xsl:value-of 
            <xsl:when test="contains($text,'mailto:')"><xsl:value-of 
        <xsl:variable name="proto"><xsl:choose>
            <xsl:when test="contains($text,'http://')">http://</xsl:when>
            <xsl:when test="contains($text,'mailto:')">mailto:</xsl:when>
        <xsl:variable name="target"><xsl:choose>
            <xsl:when test="contains($aftertext,' ')"><xsl:value-of 
select="substring-before($aftertext,' ')"/></xsl:when>
        <xsl:value-of select="$beforetext"/>
        <xsl:if test="$aftertext!=''">
            <a><xsl:if test="proto='http://'"><xsl:attribute 
            <xsl:call-template name="link-replace">
                <xsl:with-param name="text"><xsl:value-of 
select="concat(' ',substring-after($aftertext,' '))"/></xsl:with-param>

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message