Instead of having your XSLT generate Javascript which when executed does calls like document.write() to create elements in the HTML page, why not simply have your XSLT generate the HTML elements directly? It's too late at night to do the detail, but you want to replace
<script type="text/javascript">
{
var getID= '<xsl:copy-of select="$grID"/>'
document.write('<a onclick='showWindow(getID)' href="#"><xsl:value-of select="$grID" /></a>')
document.write('<div id="' + getID + '" style="display: block">HELLO WORLD</div>')
}
</script>
with something like
<a onclick="showWindow({position()})" href="#">This is line <xsl:value-of select="position()"/>.</a>
<div id="{generate-id()}" style="display: none">HELLO WORLD</div>
<br>
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference