The HTML you're showing seems to be a browser's internal view of the DOM (an anchor element is required by the spec to have a closing tag, so because you didn't close the a tag, the browser tries to guess what you intended by cloning the a tag).
If you view the raw HTML source, my guess is you won't see the duplicated element(s).
That said; If you're trying to generate anchors for specific places on a page (e.g., /page/#chapter01) - are you aware of the fact that any element with a uniquie id is reachable in that way?
Oh boy - but it's definitely not XSLT generating the extra stuff.
Yes, I saw you close the tag, but some tags aren't allowed to self-close like that. Problem is, in XML there's no difference between a self-closing tag like <a name="blah" /> and one with an explicit close tag if the tag is empty (<a name="blah"></a>), and XSLT outputs XML (when output method is set to "xml" - and setting that one to html opens another can of worms in the MSXML parser...)
And yes, it'll work if you put something in the anchor tag so the XSLT processor doesn't self-close it - an nbsp will do (though it's technically illegal per spec, if I remember correctly) but I used to just put a comment in there:
<a name="coolNameHere"><xsl:comment /></a>
But who's listening anyway now - go with the ids :-)
Generate anchors like <a name="X" />
I am trying to generate some html anchors. But it ends up with some strange html code.
XSLT
HTML
Can anyone explain why there is an anchor around "TestBody" aswell ?
- Mikkel
Hi Mikkel,
The HTML you're showing seems to be a browser's internal view of the DOM (an anchor element is required by the spec to have a closing tag, so because you didn't close the a tag, the browser tries to guess what you intended by cloning the a tag).
If you view the raw HTML source, my guess is you won't see the duplicated element(s).
/Chriztian
Hi Chriztian
Thanks for a very quick reply :-)
Actually the dump is from Umbraco's "Visualize XSLT" with checkmark in "Encode/Decode result".
And I did close the tag: <a name="A" />
And I have tried with: <a name="A"></a>
With the same effect.
Correct there is a big different depending on the browser.
Example from IE7, where the A tag is never closed even though I made the <a...></a>
I can accept that there is a browser issue (just like I am used to in CSS). But any clues on how to make it work ?
-Mikkel
That said; If you're trying to generate anchors for specific places on a page (e.g., /page/#chapter01) - are you aware of the fact that any element with a uniquie id is reachable in that way?
So instead of this (often seen) pattern:
You can actually just do:
and still get the link behavior you want?
(It's also easier to generate with XSLT)
/Chriztian
Great thanks :-) I will use the id, it will do the job.
But it is still strange that the browsers is changing my html. BTW it works if I inserts a no-break-space in between the starting a-tag and end-tag.
-Mikkel
Hi Mikkel,
Oh boy - but it's definitely not XSLT generating the extra stuff.
Yes, I saw you close the tag, but some tags aren't allowed to self-close like that. Problem is, in XML there's no difference between a self-closing tag like <a name="blah" /> and one with an explicit close tag if the tag is empty (<a name="blah"></a>), and XSLT outputs XML (when output method is set to "xml" - and setting that one to html opens another can of worms in the MSXML parser...)
And yes, it'll work if you put something in the anchor tag so the XSLT processor doesn't self-close it - an nbsp will do (though it's technically illegal per spec, if I remember correctly) but I used to just put a comment in there:
But who's listening anyway now - go with the ids :-)
/Chriztian
is working on a reply...