Hello,

I've a problem with emptys anchors.
The documents I want to import have anchors like 'Basic Skill'. After importing the closing is deleted so that it is now 'Basic Skill'. I think thats a problem with the XSL stylesheets but I can't find it.

Do anyone have an idea what i can do to fix the problem?

Comments

dman’s picture

Anorexic Anchors are bad mojo semantically.
In XML/XHTML , <a name='this' href='that'></a> is structurally identical to <a name='this' href='that' />

Some browsers may or may not parse that right. Probably also makes a differents which compliance mode your DOCTYPE is in.
Your code paste didn't come through very well, so I'm not sure what your real problem is.

You can probably come up with a fix in your XSL import template

<xsl:template match='a'>
  <xsl:copy select='.'>#</xsl:copy>
</xsl:template>

.. or something. Some assembly required on that pseudo-code.

Better to actually fix the problem of unsemantic markup, however.

tafkad@drupalcenter.de’s picture

Yes, I've forgotten to use the Code Tags while I wrote.

The problem is that I've many large documents which use the following Type of anchor: <a name="basic_skills"></a><h2>headline</h2>

After I import that the same line shows the following content: <a name="basic_skills"><h2>headline</h2>

The main problem is after the import the closing </a> is deleted, only by anchors with no content between the leading and ending a tag.

A line like the following one makes no problems: <a name="next skills">content</a>

The problem only applies if there is no content between the <a></a> tags, then the last tag </a> is deleted after importing.

I hope you understand my problem now better.

dman’s picture

That code is deprecated. Empty tags were sorta OK in the 90s before CSS could hide the underlines from anchors, but nowadays, if you are going to link to something, link to IT, with an ID, not to a floating tag positioned next to it.

<h2 id="basic_skills">headline</h2>

Is what you should be doing.

However the point of import_html is to take bad old sites and make them good, so here's a work-around which, although it won't make your semantics any better, it won't break existing expected behaviour.

Work-around for anorexic anchors

Paste this into rewrite_href_and_src.xsl Or download the patched replacement from here or from CVS DRUPAL-5

   <xsl:template name="fattentags" match="node()[@name and (not(*|text()|comment()))]">
      <xsl:copy>
         <xsl:copy-of select="@*" />
         <xsl:apply-templates />
         <xsl:comment>Empty Anchor tags are non-semantic and should be deprecated</xsl:comment>
       </xsl:copy>
   </xsl:template>

Instead of collapsing
<a name='doh'></a>
into the (technically correct) XML singleton
<a name='doh' />
pad it with
<a name='doh'><!-- placeholder --></a>
So things will continue to work as expected.
<a name='doh' /> doesn't have a good effect in many browsers ... it's read as being left open and bad things happen.

... that should do the job. Please try it out.

tafkad@drupalcenter.de’s picture

Thank you

The problem seems to be solved.

dman’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)