[daisy] Open external links in a new window

Mario Brackeva Mario.Brackeva at persgroep.be
Tue Jun 3 13:25:16 CEST 2008


Olivier,

Works like a charm!

Tx a lot.


Kind regards,
Mario.

-----Original Message-----
From: daisy-bounces at lists.cocoondev.org
[mailto:daisy-bounces at lists.cocoondev.org] On Behalf Of Olivier Lange
Sent: maandag 2 juni 2008 13:11
To: open source CMS - general mailinglist
Subject: Re: [daisy] Open external links in a new window

Hello Mario,

> We would like to have external links in a Wiki page
> (http://...whatever...) open in a new browser window by default, 
> instead of the current window. Has anyone managed to set this up?
>  
> We're using Daisy 1.5.

I am using the following code fragment within document-to-html.xsl,
which inherits from and overloads the default skin:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  [...] >

  <xsl:import
href="daisyskin:/(default)(webapp)xslt/document-to-html.xsl"/>

  [...]

  <xsl:template match="a" mode="PartContent">
    <xsl:variable name="neLinkInfo" select="p:linkInfo"/>
    <!-- <xsl:variable name="bIsLinkEmail" select="starts-with( @href,
'mailto:')"/> -->
    <xsl:variable name="bIsLinkExternal" select="not( $bIsLinkEmail)
and( starts-with( @href, 'http:')
      or starts-with( @href, 'ftp:') or starts-with( @href, 'news:'))"/>
    <xsl:variable name="bIsLinkPDF" select="contains( @href, '.pdf')"/>
    <xsl:variable name="bIsLinkRSS" select="contains( @href, '.rss')"/>
    <a>
      <xsl:copy-of select="@*"/>
      <xsl:choose>
        <xsl:when test="$bIsLinkExternal">
          <xsl:attribute name="class">external</xsl:attribute>
          <xsl:attribute name="target">_blank</xsl:attribute>
        </xsl:when>
        <xsl:when test="$bIsLinkPDF"><xsl:attribute
name="class">pdf</xsl:attribute></xsl:when>
        <xsl:when test="$bIsLinkRSS"><xsl:attribute
name="class">rss</xsl:attribute></xsl:when>
        <xsl:otherwise/>
      </xsl:choose>
      <xsl:if test="$neLinkInfo/@documentName">
        <xsl:attribute name="title"><xsl:value-of
select="$neLinkInfo/@documentName"/></xsl:attribute>
      </xsl:if>
      <xsl:apply-templates mode="PartContent"/>
    </a>
  </xsl:template>

HTH,

--
Olivier


More information about the daisy mailing list