What part of my answer didn't you understand? It really ought to be possible to adapt the answer to a slightly different problem - if you can't do that then there's not much point giving you the answer, or you'll be back here every time the problem changes slightly.
Change the for-each to
<xsl:for-each select="main/content[content2/dept='Y']">
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference