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.
Warning
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.
Sitemap
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="127.0.0.1"/>
</map:transformer>
where
- file — the actual counter file where
the record is kept.
- ignore — a comma separated list of
IP numbers to ignore.
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.
Content
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="http://www.paloose.org/schemas/Paloose/1.0"/>
After running through the transformer this element is replaced by another containing the
actual count
<paloose:page-hit>6</paloose:page-hit>
Finally
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.