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 "xsl:apply-templates"
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 ...


Regards,
Johannes

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
CSS:
---
<div style="white-space:pre;">
...
</div>
---
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 select="'&lt;b&gt;'"/></xsl:variable>
<xsl:variable name="close"><xsl:value-of select="'&lt;/b&gt;'"/></xsl:variable>
<xsl:choose>
<xsl:when test="contains($word,$open)">
<xsl:call-template name="br-replace">
<xsl:with-param name="word" select="substring-before($word,$open)"/>
</xsl:call-template>
<b>
<xsl:call-template name="br-replace">
<xsl:with-param name="word" select="substring-after(substring-before($word,$close),$open)"/>
</xsl:call-template>
</b>
<xsl:call-template name="b-replace">
<xsl:with-param name="word" select="substring-after($word,$close)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="br-replace">
<xsl:with-param name="word" select="$word"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


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




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to