Rather than describing your problem in terms of the user experience, it's much easier for us if you show the XML input and HTML output of your transformation, simplified as much as possible to remove irrelevancies.
Your code fragments mean nothing in the absence of a source document.
By the way
Code:
<xsl:variable name "currpage">
<xsl:value-of select="/pagelocation/page_info/@pagename">
</xsl:variable>
is a verbose and inefficient (and sometimes incorrect) way of writing
Code:
<xsl:variable name "currpage" select="/pagelocation/page_info/@pagename"/>
Get out of the habit before it's too late.