xsl & textarea with no data

Discussion in 'XML' started by a113n, Dec 31, 2007.

  1. a113n

    a113n Guest

    I have the following XSL code to handle textareas:
    <!-- Match TEXTAREA -->
    <xsl:template name="TEXTAREA" match="TEXTAREA">
    <TEXTAREA ROWS="{@ROWS}" COLS="{@COLS}" NAME="{@NAME}">
    <xsl:if test="@READONLY">
    <xsl:attribute name="READONLY"><xsl:text>READONLY</xsl:text></
    xsl:attribute>
    </xsl:if>
    <xsl:value-of select="."/>
    </TEXTAREA>
    </xsl:template>

    The problem is that when there is no data, this comes out to be
    something like this: <TEXTAREA .... /> instead of <TEXTAREA ...></
    TEXTAREA>.

    For some reason the browser treats everything after the textarea when
    this occurs as apart of the textarea, which is obviously bad. Does
    anyone know how I can get the browser to not do this or some way to
    get the XSL to print out the ending </TEXTAREA> when there is no data
    for the text area? Thanks in advance for your help.
     
    a113n, Dec 31, 2007
    #1
    1. Advertising

  2. a113n

    a113n Guest

    Also, I am using the following doctype:

    <HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
     
    a113n, Dec 31, 2007
    #2
    1. Advertising

  3. a113n wrote:
    > I have the following XSL code to handle textareas:
    > <!-- Match TEXTAREA -->
    > <xsl:template name="TEXTAREA" match="TEXTAREA">
    > <TEXTAREA ROWS="{@ROWS}" COLS="{@COLS}" NAME="{@NAME}">
    > <xsl:if test="@READONLY">
    > <xsl:attribute name="READONLY"><xsl:text>READONLY</xsl:text></
    > xsl:attribute>
    > </xsl:if>
    > <xsl:value-of select="."/>
    > </TEXTAREA>
    > </xsl:template>
    >
    > The problem is that when there is no data, this comes out to be
    > something like this: <TEXTAREA .... /> instead of <TEXTAREA ...></
    > TEXTAREA>.


    With XSLT 1.0 all you can do is use
    <xsl:eek:utput method="html"/>
    and make sure you use a textarea element in no namespace.
    With XSLT 2.0 you can also use
    <xsl:eek:utput method="xhtml"/>
    and a textarea element (lower-case) in the XHTML namespace
    http://www.w3.org/1999/xhtml.

    If you are trying to output XHTML with XSLT 1.0 then it is not possible
    to ensure that an empty textarea element is output as <textarea
    ....></textarea>. You will need to switch to HTML 4.01 in that case.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 31, 2007
    #3
  4. a113n

    a113n Guest

    Thanks for your help Martin. Unfortunately changing the output over
    to HTML still gives me the same problem. I'm not sure what you mean
    by using the TEXTAREA element in no namespace, could you elaborate on
    this? I'm familiar with namespaces in reference to .NET, but not in
    terms of XSL transformations.

    How difficult is it to upgrade from XSLT 1.0 to 2.0? What bothers me
    most about this is that everything was working fine until I
    reformatted our server last nite, and now we have this problem. I've
    bandaid solved the problem by adding a space to the textarea, but I do
    not like this approach, something more delicate is required.
     
    a113n, Dec 31, 2007
    #4
  5. a113n wrote:
    > Thanks for your help Martin. Unfortunately changing the output over
    > to HTML still gives me the same problem. I'm not sure what you mean
    > by using the TEXTAREA element in no namespace, could you elaborate on
    > this?


    You need to do two things, you need to use
    <xsl:eek:utput method="html"/>
    and you need to use result elements in no namespace so you need to get
    rid of of the xmlns attribute in
    <HTML xmlns="http://www.w3.org/1999/xhtml"" xml:lang="en" lang="en">
    where you need to use
    <html lang="en">
    instead.

    As for upgrading to XSLT 2.0, there are three XSLT 2.0 processors
    currently, Saxon from <URL:http://saxon.sourceforge.net/> has a Java and
    a .NET version, Gestalt is an Eiffel implementation, and Altova provides
    it XSLT and XQuery tools as a native windows application.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 31, 2007
    #5
  6. a113n wrote:
    > The problem is that when there is no data, this comes out to be
    > something like this: <TEXTAREA .... /> instead of <TEXTAREA ...></
    > TEXTAREA>.


    XML considers those two forms identical. HTML doesn't. Are you sure you
    used the xsl:eek:utput directive to say you want to generate HTML rather
    than XML?

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Jan 2, 2008
    #6
    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. Thomas S.

    XSL: textarea with xsl code???

    Thomas S., Feb 5, 2004, in forum: XML
    Replies:
    1
    Views:
    1,191
    Markus Spath
    Feb 5, 2004
  2. Replies:
    1
    Views:
    3,636
    A. Bolmarcich
    May 27, 2005
  3. Augustus
    Replies:
    1
    Views:
    371
    Ken Schaefer
    Sep 10, 2003
  4. Textarea Inside of a textarea

    , Feb 4, 2006, in forum: ASP General
    Replies:
    6
    Views:
    344
    Anthony Jones
    Feb 5, 2006
  5. Replies:
    1
    Views:
    334
    Bart Van der Donck
    Jul 4, 2007
Loading...

Share This Page