extra blank lines appear when rendering <textarea> from xslt

Discussion in 'XML' started by Andy Fish, Dec 20, 2004.

  1. Andy Fish

    Andy Fish Guest

    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
    Andy Fish, Dec 20, 2004
    #1
    1. Advertising

  2. Andy Fish

    Andy Fish Guest

    "Andy Fish" <> wrote in message
    news:slAxd.3548$...
    > 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.

    > TIA
    >
    > Andy
    >
    >
    Andy Fish, Dec 21, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bartc

    Re: Extra blank lines from printf.

    bartc, Mar 24, 2010, in forum: C Programming
    Replies:
    1
    Views:
    1,678
    bartc
    Mar 24, 2010
  2. Eric Sosman

    Re: Extra blank lines from printf.

    Eric Sosman, Mar 24, 2010, in forum: C Programming
    Replies:
    1
    Views:
    326
    Eric Sosman
    Mar 24, 2010
  3. David Ainley
    Replies:
    3
    Views:
    154
    Jesús Gabriel y Galán
    Aug 4, 2010
  4. Cah Sableng
    Replies:
    0
    Views:
    230
    Cah Sableng
    Apr 23, 2007
  5. OccasionalFlyer

    Chrome Inserts Extra Blank Lines in Drop-Down list

    OccasionalFlyer, Apr 22, 2010, in forum: Javascript
    Replies:
    1
    Views:
    178
Loading...

Share This Page