Search

I have a comments section on a website that I built... Lately some people who do link building have been bothering me with nonsense comments and links... Their posts are so obvious and we show formatted comments. I think adding rel="nofollow" would discourage them for posting because it nullifies their efforts.

Currently I just use this single line to get formatted comment from data-source:

<xsl:copy-of select="comment" />

Can anybody tell me how can I enhance < a > tags get with rel="nofollow" and target"_blank" attributes on the fly?

Very easily, using the HTML Manipulation utility and one special template:

<xsl:template match="a" mode="html" priority="1">
    <a rel="nofollow" target="_blank">
        <xsl:apply-templates select="* | @* | text()" mode="html"/>
    </a>
</xsl:template>

Instead of a

<xsl:copy-of select="comment" />

you'd then be using

<xsl:apply-templates select="comment/*" mode="html"/>

Please note though that it's not really recommended to use target="_blank".

Learn the way of the XSLT ninja :-)

Thanks! Incredibly quick reply... Testing it now :)

Can I ask what are your objections against using target="_blank" in a comments section? Even Google search results pop up in new tabs/windows these days...

People on that particular site often use hyperlinks to link back to references and link builders have been abusing this feature. I think it's more logical to open those links in new windows as we do not want people leaving the discussion... Those links are only supposed to be for reference...

Can I ask what are your objections against using target="_blank" in a comments section?

Probably more from a technical perspective. Unless you're using HTML 4.01, the target attribute no longer exists. So if you want your HTML to be valid, the new window should be opened unobtrusively using JavaScript (perhaps give the link a class or rel of external or something). It's not a big deal — I still use target="_blank" when validation doesn't matter so much.

target="_blank" is valid again in HTML 5.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details