[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: creating new lines in textarea input for HTML

Subject: RE: creating new lines in textarea input for HTML
From: "Matthieu Ricaud" <matthieu.ricaud@xxxxxxx>
Date: Fri, 27 Jan 2006 19:24:39 +0100
textarea linefeed
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,'&#xA;')">
				<!-- 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,'&#xA;')"/>
				<!-- 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,'&#xA;')"/>
					</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 :  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>&#x0a;</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
'&#x0a;' as literal
text.  Is there another way to do this?

Thanks,
Stuart Zakon

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.