you are selecting all rows
<xsl:apply-templates select="xml/rs:data/z:row"/>
and then doingnothing sometimes
<xsl:template match="z:row">
<xsl:if test="not($excludes/ID=(_at_)submitid)">
<xsl:call-template name="addval"/>
</xsl:if>
</xsl:template>
which means your position()=last() test is doing the wrong thing (as you
said)
so instead, just select the rows you want so position() is only counting
the rows you are interested in.
<xsl:apply-templates
select="xml/rs:data/z:row[not($exculdes/ID=(_at_)submitid)]"/>
...
David
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list