[jdom-interest] Problems outputting HTML

Robert Taylor rtaylor at mulework.com
Tue Apr 27 14:10:27 PDT 2004


> <script>//</script>

That did it! I had tried an empty space, but I think the XMLOutputter
removes white space before deciding to collapse the element.

Many thanks.

robert

> -----Original Message-----
> From: Robert Koberg [mailto:rob at koberg.com]
> Sent: Tuesday, April 27, 2004 4:52 PM
> To: Jason Hunter
> Cc: Robert Taylor; jdom-interest at jdom.org
> Subject: Re: [jdom-interest] Problems outputting HTML
> 
> 
> Jason Hunter wrote:
> 
> >> <script language="JavaScript" 
> >> src="http://www.newatlanta.com/shared/us.js"></script>
> >>
> >> Although the body of this tag is empty, it is expanded because, if it 
> >> is not, then
> >> some browsers won't import the script library.
> > 
> > 
> > I've hit that browser bug too.  I think adding a space of text content 
> > between the script tags is also helpful on some browsers, and a 
> > convenient workaround to the issue you have here.
> 
> When outputting XHTML I usually do:
> 
> <script>//</script>
> 
> A couple of others to watch out for are:
> 
> <title/> -- cause the page not to display
> 
> <textarea/> -- cause the rest of the page to be in the textarea.
> 
> (see XSL below)
> 
> 
> > 
> >> It appears that unless I set expandEmptyElements(true), then XMLOutputter
> >> will collapse empty elements (although this is not stated in the 
> >> Javadocs).
> >> (It seems like there should be an collapseEmptyElements(boolean flag) 
> >> since
> >> <tag></tag> is still well-formed XML..)
> > 
> > 
> > Semantically the expanded and unexpanded forms are identical.  You're 
> > just trying to work around browser bugs.  We have the 
> > expandEmptyElements() option specifically for this.
> > 
> >> Not a problem...until <br/> tags are expanded. The browser interprets 
> >> both
> >> <br> and <br/> as line breaks!
> > 
> > 
> > It's <br> and </br> actually, which a decent browser shouldn't see as 
> > two breaks.  Argh.
> 
> 
> You can run an identity transformation before it goes to tyhe browser:
> 
> <?xml version="1.0" encoding="utf-8" ?>
> <xsl:stylesheet version="1.0"
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    xmlns="http://www.w3.org/1999/xhtml">
> 
>    <xsl:output omit-xml-declaration="yes"
>      doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
>  
> doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>      encoding="UTF-8"
>      indent="no"
>      method="xml"/>
> 
> <!--
>    <xsl:output
>      encoding="UTF-8"
>      indent="no"
>      method="html"
>      doctype-public="-//W3C//DTD HTML 4.01//EN"/>
> -->
> 
>    <xsl:template match="html">
>      <html xmlns="http://www.w3.org/1999/xhtml">
>        <xsl:apply-templates/>
>      </html>
>    </xsl:template>
> 
>    <xsl:template match="node()|@*">
>      <xsl:copy>
>        <xsl:apply-templates select="@*"/>
>        <xsl:apply-templates/>
>      </xsl:copy>
>    </xsl:template>
> 
>    <xsl:template match="textarea">
>      <xsl:copy>
>        <xsl:apply-templates select="@*"/>
>        <xsl:text> </xsl:text>
>        <xsl:apply-templates/>
>      </xsl:copy>
>    </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> > 
> >> One solutions was proposed over a year ago (sublass XMLOutputter and 
> >> implement an HTMLOutputter...)
> >> http://www.servlets.com/archive/servlet/ReadMsg?msgId=335507&listName=jdom-interest 
> >>
> >>
> >> Is this still the case? Are there any other solutions?
> > 
> > 
> > No one's bothered with an HTMLOutputter yet.  For you adding a space in 
> > the script element and leaving empties unexpanded would fix the issue.
> > 
> > -jh-
> > 
> > _______________________________________________
> > To control your jdom-interest membership:
> > http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com 
> > 
> > 
> 



More information about the jdom-interest mailing list