hello,
i used to have found this template while surching for a similar problem :
<xsl:template name="lf2br">
<!-- import $StringToTransform -->
<xsl:param name="StringToTransform"/>
<xsl:choose>
<!-- string contains linefeed -->
<xsl:when test="contains($StringToTransform,'
')">
<!-- output substring that comes before the
first linefeed -->
<!-- note: use of substring-before() function
means -->
<!-- $StringToTransform will be treated as a
string, -->
<!-- even if it is a node-set or result tree
fragment. -->
<!-- So hopefully $StringToTransform is really
a string! -->
<xsl:value-of
select="substring-before($StringToTransform,'
')"/>
<!-- by putting a 'br' element in the result
tree instead -->
<!-- of the linefeed character, a <br> will be
output at -->
<!-- that point in the HTML
-->
<br/>
<!-- repeat for the remainder of the original
string -->
<xsl:call-template name="lf2br">
<xsl:with-param
name="StringToTransform">
<xsl:value-of
select="substring-after($StringToTransform,'
')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<!-- string does not contain newline, so just output it
-->
<xsl:otherwise>
<xsl:value-of select="$StringToTransform"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Whenever i want to diplay line breaks of a string with a <br/> html element
i just do :
<xsl:call-template name="CopyWithLineBreakBR">
<xsl:with-param name="string" select="'my
breaked
string'"/>
</xsl:call-template>
<xsl:template name="CopyWithLineBreakBR">
<xsl:param name="string"/>
<xsl:variable name="Result">
<xsl:call-template name="lf2br">
<xsl:with-param name="StringToTransform"
select="$string"/>
</xsl:call-template>
</xsl:variable>
<xsl:copy-of select="$Result"/>
</xsl:template>
hope this help,
matt
-----Message d'origine-----
De : Stuart Zakon [mailto:sz(_at_)objectsbydesign(_dot_)com]
Envoyé : vendredi 27 janvier 2006 19:02
À : xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Objet : [xsl] creating new lines in textarea input for HTML
The <textarea> input in HTML will take a value that has multiple lines CR/LF
but will not
preserve the line feeds (treated as whitespace).
On the other hand, if I add these using <xsl:text>
</xsl:text>, they
show up fine in
the textarea.
So the challenge is, how do I break up the string using XSLT and put in the
above?
I though string-before() would work but realized that it is treating
'
' as literal
text. Is there another way to do this?
Thanks,
Stuart Zakon
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--