I'm not sure why you find the repetition unexpected. When you do
<xsl:for-each select="$disc_action">
<xsl:for-each select="$inst_action">
you are processing all the inst_action elements repeatedly - you process them all for hte first disc_action, then again for the second, and so on. Then your condition
<xsl:if test="$disc_packid = $inst_packid">
uses variables whose values don't depend at all on the current nodes you are processing in the two for-each loops.
You don't want all these global variables, you want to select nodes relative to the context node.
Without knowing your data model I can't be more specific.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference