Page-Hit Transformer

The Page-hit transformer provides a very simple mechanism to see how many times a particular page has been accessed. Individual pages can be targeted rather than a complete site. It is also possible to ignore certain IP numbers.

I have found that this transformer fails under some high load conditions. This only happens with continuous loads of 100 concurrent users, but until I find the cause, please treat with caution.


The root sitemap needs to have the PageHit Transformer declared as a component:

<map:components> <map:transformers default="xslt"> <map:transformer name="pageHit" src="resource://lib/transforming/PageHitTransformer"> <map:parameter name="file" value="context://logs/PageHit.cnt"/> <map:parameter name="ignore" value=""/> </map:transformer>


In order to use the transformer we need to put the following

<map:match pattern="**.xml"> <map:generate src="context://content/{1}.xml"/> <map:transform type="pageHit" > <map:parameter name="file" value="context://logs/pp-{1}.cnt"/> </map:transform> ... <map:serialize/> </map:match>

Note that the parameter file overrides the component declaration of file, so that we can have a counter for each page.


In order to use the transformer a single element is placed in your content file that you wish to record the page hits.

<paloose:page-hit xmlns:paloose=""/>

After running through the transformer this element is replaced by another containing the actual count



The only thing now is to format it as you want. For example you might have the following in your XSLT transformer file:

<xsl:if test="//paloose:page-hit"> <xsl:text>Hits: </xsl:text> <xsl:value-of select="//paloose:page-hit"/> </xsl:if>
Copyright 2006 – 2023 Hugh Field-Richards. All Rights Reserved.