Wherever you see something like
<xsl:for-each select="x/y/z">
<xsl:if test="a = b">
... something ...
</xsl:if>
</xsl:for-each>
it can be replaced by
<xsl:for-each select="x/y/z[a = b]">
... something ...
</xsl:for-each>
The only difference is that it changes the values of position() and last() to reflect the items you are actually processing.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference