xsl & textarea with no data

A

a113n

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.
 
M

Martin Honnen

a113n said:
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.
 
A

a113n

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.
 
M

Martin Honnen

a113n said:
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.
 
J

Joseph Kesselman

a113n said:
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?
 

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,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top