extra blank lines appear when rendering <textarea> from xslt

A

Andy Fish

Hi,

Now I have an xsl that generates an html page that allows the user to edit a
<textarea>. If he types in this:

frog[cr]toad

(i.e. presses the enter key between the two words) and posts it to the
server (ie 6 on winxp) the request value comes out as frog[cr][lf]toad,
which seems fair enough.

Next time round I want to display the value so he can edit it. my stylesheet
looks like this:

<textarea><xsl:value-of select="@value" /><textarea>

After processing it with xalan 2.4.1, the html looks like this

<textarea>frog
[cr][lf]toad</textarea>

so it's as if xalan has replaced the [cr] with an entity reference, and then
converted the [lf] to [cr][lf].

The browser now displays this with a blank line between the two words. Of
course, every time the form is posted, the number of blank lines is doubled.

I just need to preserve any newlines entered by the user. Any clues about
where I'm going wrong?

TIA

Andy
 
A

Andy Fish

Andy Fish said:
Hi,

Now I have an xsl that generates an html page that allows the user to edit
a <textarea>. If he types in this:

frog[cr]toad

(i.e. presses the enter key between the two words) and posts it to the
server (ie 6 on winxp) the request value comes out as frog[cr][lf]toad,
which seems fair enough.

Next time round I want to display the value so he can edit it. my
stylesheet looks like this:

<textarea><xsl:value-of select="@value" /><textarea>

After processing it with xalan 2.4.1, the html looks like this

<textarea>frog
[cr][lf]toad</textarea>

so it's as if xalan has replaced the [cr] with an entity reference, and
then converted the [lf] to [cr][lf].

The browser now displays this with a blank line between the two words. Of
course, every time the form is posted, the number of blank lines is
doubled.

I just need to preserve any newlines entered by the user. Any clues about
where I'm going wrong?

Eventually, I found this note in the documentation for Xalan:

"When your stylesheet asks for an explicit carriage-return character (
)
to be inserted into the output, it is output during the serialization
process in escaped form unless escaping has been disabled. When your
stylesheet asks for an explicit line-feed character (
) to be output,
the system-default line-break character(s) is/are output during the
serialization process. Also keep in mind that the XML parser normalizes
line-breaks to line-feeds when it sends character events to the processor."

so my solution was to remove all occurences of [cr] in the field value,
which changes all the [cr][lf] sequences into [lf]. Then xalan turns these
back into [cr][lf] again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top