self-closing tags

D

David Schwartz

I'm generating HTML using XSLT. It seems that the XSLT processor wants
to generate self-closing tags when possible, e.g., <a name="XYZ></
a> becomes <a name="XYZ"/>. It seems that at least IE7 doesn't
like this and, as a result, highlights the following content as of it
were part of an anchor tag.

Is there some way for forcing the browser to deal with self-closing
anchors properly? Is this a known problem?

TIA,
David
 
J

Jukka K. Korpela

Scripsit David Schwartz:
I'm generating HTML using XSLT. It seems that the XSLT processor wants
to generate self-closing tags when possible, e.g., <a name="XYZ></
a> becomes <a name="XYZ"/>.

Bad processor. Such an operation violates the compatibility requirements
that are explicitly stated in both XML and XHTML specifications. Naughty
processor.
It seems that at least IE7 doesn't
like this and, as a result, highlights the following content as of it
were part of an anchor tag.

Of course. IE does not grok XHTML. It's a tag soup slurper that simply
ignores the "/" said:
Is there some way for forcing the browser to deal with self-closing
anchors properly? Is this a known problem?

Huh? The _proper_ treatment of <a name="XYZ"/> by HTML rules up to and
including HTML 4.01 is to treat it as equivalent to <a name="XYZ">/ but
practically no browser gets this right.

Anyway, it is a known problem that an <a> element with empty content
causes problems to some browsers, even when it is written in the classic
HTML style <a name="XYZ"></a> and even though such markup is valid and
conforms to HTML specifications.

So I think the cure is to refrain from generating elements with empty
content. There's almost always some other way. In fact, <a name="XYZ">
is hardly needed these days, when you can use the id="..." attribute on
the element that should be the destination anchor.
 
D

David Schwartz

So I think the cure is to refrain from generating elements with empty
content. There's almost always some other way. In fact, <a name="XYZ">
is hardly needed these days, when you can use the id="..." attribute on
the element that should be the destination anchor.
But that would require javascript, right?

David
 
S

Steve Pugh

But that would require javascript, right?

Not at all.

<a href="#foo">link</a> will link to <h2 id="foo">heading</h2> in just
about any browser in use today. No JavaScript involved at all.

Steve
 
D

David Schwartz

<a href="#foo">link</a> will link to <h2 id="foo">heading</h2> in just
about any browser in use today. No JavaScript involved at all.


Cool! Works great! Thanks so much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top