Search

Hi!

I'd like to share with you about one case of using the ninja techniques. Maybe someone will find it usefull. Or, on the other hand, someone may offer a better way of achieving the same results.

The problem.

I have a section called 'banners' wich contains all the banners I want to display on my site. There are fields which define the placement of a banner (bottom, top, right), the pages on which it must be displayed, and the field of the textarea type which holds the html code.

So, I decided to use this 'banners' section for keeping the counter for my site, as well. The counter I decided to use ('www.liveinternet.ru') is offered in two parts - JS code, which is a counter itself, and an html code for outputting the info on the screen:

<!--LiveInternet counter-->&lt;script type="text/javascript"><!--
new Image().src = "//counter.yadro.ru/hit?r"+
escape(document.referrer)+((typeof(screen)=="undefined")?"":
";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?
screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+
";"+Math.random();//-->&lt;/script><!--/LiveInternet-->

<!--LiveInternet logo--><a href="http://www.liveinternet.ru/click"
target="_blank"><img src="//counter.yadro.ru/logo?11.6"
title="LiveInternet:  views for 24 hours, visitors fo 24 hours and for today"
alt="" border="0" width="88" height="31"/></a><!--/LiveInternet-->

I decided not to use javascript in the counter, so I have combined these two parts in one:

<img src="//counter.yadro.ru/hit?r{$current-url}" whidth="1" height="1"/>
<a href="http://www.liveinternet.ru/click"
target="_blank"><img src="//counter.yadro.ru/logo?11.6"
title="LiveInternet:  views for 24 hours, visitors fo 24 hours and for today"
alt="" border="0" width="88" height="31"/></a><!--/LiveInternet-->

So, as you see, the new code contains the {$current-url} tag which needs to be replaced by the $current-url parameter value later when preparing the page.

Solution

I just show the relevant xsl code which might be, probably, sufficient to get the idea about the solution I have come to:

<xsl:import href="typography.xsl"/>
<xsl:import href="string-replace.xsl"/>

<xsl:template name="show-bottom-banners">
       <xsl:apply-templates select="/data/banners-bottom-ds/entry" mode="banners"/>
</xsl:template>

<xsl:template match="banners-bottom-ds/entry" mode="banners">
      <xsl:apply-templates select="body/*" mode="html"/>
</xsl:template>

<xsl:template match="img/@src" mode="html" priority="1">
 <xsl:attribute name="src">
 <xsl:call-template name="string-replace">
                <xsl:with-param name="haystack" select="." />
                <xsl:with-param name="search" select="'{$current-url}'" />
                <xsl:with-param name="replace" select="$current-url" />
        </xsl:call-template>
 </xsl:attribute>
 </xsl:template>

So, that's how I've done it in my dilettant way.
I'm open for suggestions.

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