Fix for Ticket #871
Most of the code for this fix was taken from the main-page.xsl