Subject: RE: [xsl] creating new lines in textarea input for HTML From: "Matthieu Ricaud" <matthieu.ricaud@xxxxxxx> Date: Fri, 27 Jan 2006 19:24:39 +0100 |
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@xxxxxxxxxxxxxxxxxxx] Envoyi : vendredi 27 janvier 2006 19:02 @ : xsl-list@xxxxxxxxxxxxxxxxxxxxxx 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] creating new lines in textare, Stuart Zakon | Thread | [xsl] Selecting previous node in ne, Tim Lebo |
RE: [xsl] Shallow copy and base URI, Michael Kay | Date | RE: [xsl] How might I reproduce a t, footh |
Month |