469,602 Members | 1,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

xsl & textarea with no data

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 </TEXTAREAwhen there is no data
for the text area? Thanks in advance for your help.
Dec 31 '07 #1
5 4548
Also, I am using the following doctype:

<HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
Dec 31 '07 #2
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:output method="html"/>
and make sure you use a textarea element in no namespace.
With XSLT 2.0 you can also use
<xsl:output 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/
Dec 31 '07 #3
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.
Dec 31 '07 #4
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:output 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/
Dec 31 '07 #5
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:output directive to say you want to generate HTML rather
than XML?

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jan 2 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by J_axx | last post: by
4 posts views Thread by David Lozzi | last post: by
11 posts views Thread by Jeremy | last post: by
14 posts views Thread by Arne | last post: by
6 posts views Thread by Tony | last post: by
3 posts views Thread by KimberlyM | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.