[xsl] Self-closing elements upset some browsers

Subject: [xsl] Self-closing elements upset some browsers
From: "Marroc" <marrocdanderfluff@xxxxxxxxxxx>
Date: Fri, 14 Mar 2008 12:48:24 -0000
I sent this yesterday but haven't seen this appear on the list - I apologize
for repeats but I really would like to resolve this elegantly. R

(.NetXslTransform engine for xslt 1.0) 

Hi all,

Has anyone got any information on this?

The identity transform part of my xsl is transferring html <a> links from
the input to the output as follows:

Input: <a name="o1399"></a><h2 class="heading2">Licensing</h2>
Output: <a name="o1399" shape="rect"/><h2 class="heading2">Licensing</h2>

Transform:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml";
	      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
		xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
		xmlns:map="local" 
		xmlns:msxsl="urn:schemas-microsoft-com:xslt"
            exclude-result-prefixes="xhtml map">

<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 
 
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; 
            indent="no" encoding="UTF-8" method="xml"/>

  <xsl:template match="node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template name="attribute" match="@*">
    <xsl:copy/>
  </xsl:template>

I tracked down the source of the shape="rect" to this line in the DTD:

<!ATTLIST a
  %attrs;
  %focus;
  charset     %Charset;      #IMPLIED
  type        %ContentType;  #IMPLIED
  name        NMTOKEN        #IMPLIED
  href        %URI;          #IMPLIED
  hreflang    %LanguageCode; #IMPLIED
  rel         %LinkTypes;    #IMPLIED
  rev         %LinkTypes;    #IMPLIED
  shape       %Shape;        "rect"
  coords      %Coords;       #IMPLIED
  target      %FrameTarget;  #IMPLIED
  >

- I don't want it, so if you can suggest how I can avoid it then good but,
my major problem, with these links (and similarly with <script /> elements
is that browsers do not like these 'self-closing' elements.

My solution for the script elements was to insert an <xsl:text> </xsl:text>
and thereby stretch them into a begin and end tag. You can see that I can't
do the same for the links because the space would appear (with blue
underline) in the output.

Any suggestions for forcing empty elements to use a start and end tag?

Thanks all,
Richard

Current Thread