[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] how to close html tags : link, meta,...


Subject: RE: [xsl] how to close html tags : link, meta,...
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Wed, 13 Aug 2003 09:30:06 +0100

> > hi,
> > i'm using xslt to transform an xml file into a html file
> > my problem is that i really need to have the empty tags( meta, link,
> > img,...) closed and I don't know how to do this...
> 
> In which case you shouldn't transform to HTML. Use the "xml" output
> method:
> 
> <xsl:output method="xml" />

You will discover that using the xml output method will solve this
particular issue, but cause you no end of html style issues, such as:

<div style="background:blue">
  <div/>
</div>

Will make everything after the outer <div> have a blue background.  Of
course this is perfectly legal xml, and to any xml aware receiving
application <div/> and <div></div> are identical - but not to IE.  IE
will treat the empty element <div/> as an opening tag, the following
</div> as its closing tag, and then everything that follows as children
of the outer <div style="background:blue">.

The only way to use the xml output method is to ensure each html tag
doesn't get minimised, usually by placing a &_#160; in each template.

This leads to formatting issues - say you really do wan't a blue
background, you will notice lots of spaces with blue backgrounds.  Or
simply extra white space in the output.

So you could use a zero width space, but make sure your encoding and
font supports it.  If that's not an option, you need to use an
expression in the form of:

<span
style="background:expression(document.body.currentStyle.backgroundColor)
">&_#160;</div>

Which is still a pain (and has a processing expense) but at least your
output will look fine.

Soon, (maybe now?) you will be able to use Saxon's xslt 2.0 xhtml output
method with the backwards-compatibility mode @version="1.0" on your xslt
1.0 stylesheets, which will solve this issue.

andrew 

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



Current Thread
Keywords