By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

xsl & textarea with no data

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
Also, I am using the following doctype:

<HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
Dec 31 '07 #2

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.