You wrote:
<xsl:template name = "checkPosition1" match ="/node()">
<xsl:template match ="/node()">
You can't have one template inside another - I don't know what you would expect it to mean. match="/node()" matches any node that is a direct child of the document root - I don't know what you expected that to achieve either.
The construct
<xsl:when test="position()=last()">
does not test the position of a node in the source tree, it tests its position in the current sequence of nodes being processed. Sometimes that's the same thing, but not in this case, because you aren't processing nodes in tree order. In particular when you do it within
<xsl:for-each select="..">
the current node list contains a single node (the parent), so position() and last() are both equal to 1.
>i want to check if the parent is the last position
that's test="not(../following-sibling::*)"
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference