RE: [xsl] open and closed tag merged into one using HTML output

Subject: RE: [xsl] open and closed tag merged into one using HTML output
From: "Martinez, Brian" <brian.martinez@xxxxxxxx>
Date: Wed, 26 Feb 2003 13:56:13 -0700
> -----Original Message-----
> From: David Smith [mailto:david.smith@xxxxxxxxxxxxxx]
> Sent: Wednesday, February 26, 2003 1:20 PM
> Subject: [xsl] open and closed tag merged into one using HTML output
> 
> 
> Hi,
> I am trying to find the way that I should resolve a problem I 
> am having. 
> In the XSL file, I specify
> 
> <textarea name="text"><xsl:value-of 
> select="/root/description"/></textarea>
> 
> but when it is parsed, as there is no /root/description 
> element, or it's 
> empty, it comes out like this:
> 
> <textarea name="text"/>
> 
> which doesn't show right in any browser. I have got the output set to 
> HTML with the following
> 
> <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"; 
> version = "1.0"
>                                 
> xmlns="http://www.w3.org/TR/xhtml1/strict";>
> <xsl:output method = "html" indent="yes" version="4.0"/>
> 
> <xsl:template match="/">
> <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" >
> 
> 
> The parser I am using is the Xalan Java processor. I ran the 
> processor 
> XSL script and it gave this output
> Vendor: Apache Software Foundation
> Vendor URL: http://xml.apache.org/xalan-j
> 
> Can anyone suggest what I may do to make this work?

This problem rears its head fairly regularly.  Some processors (Xalan, as
you've discovered, is one) will minimize the <textarea> tag if it's empty.
This is from the spec:

"The html output method should not output an element differently from the
xml output method unless the expanded-name of the element has a null
namespace URI; an element whose expanded-name has a non-null namespace URI
should be output as XML. If the expanded-name of the element has a null
namespace URI, but the local part of the expanded-name is not recognized as
the name of an HTML element, the element should output in the same way as a
non-empty, inline element such as span." (Section 16.2)

I think Xalan handles this incorrectly because if you don't specify a URI
for the default namespace, then it should output empty textarea elements as
<textarea></textarea>, but I may be misinterpreting the above statement.
One suggestion I've made in the past is to explicitly include the -HTML flag
when invoking the transformation with Xalan, which seems to work on our
systems.

However, you've introduced a new wrinkle: you want the output to be
validated against the strict XHTML DTD, but you've specified the output to
be serialized as HTML 4.0.  These are not the same.  HTML output will omit
the close tags for empty elements such as <br>, <hr> and the like--which is
not valid XHTML.

If you require XHTML, you'll need to set the output to XML--but then you may
run into a problem with empty elements being reduced to <br/> intead of <br
/> (or the <textarea> issue noted above), which may not display correctly in
certain user agents.

This will get easier in XSLT 2.0, which provides for serializing output as
XHTML.

hth,
b.

| brian martinez                              brian.martinez@xxxxxxxx |
| senior gui programmer                                  303.708.7248 |
| trip network, inc.                                 fax 303.790.9350 |
| 6436 s. racine cir.                             englewood, co 80111 |
| http://www.cheaptickets.com/                   http://www.trip.com/ |

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread