1<xsl:stylesheet version="1.0"
2      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3      xmlns:fo="http://www.w3.org/1999/XSL/Format">
4<xsl:template match="doc">
5<doc>
6    <xsl:apply-templates select="//employee"/>
7</doc>
8</xsl:template>
9
10<xsl:template match="employee">
11    <fo:block>
12    Employee <xsl:apply-templates select="name"/> belongs to group
13	<xsl:apply-templates select="ancestor::department/group"/>
14    </fo:block>
15</xsl:template>
16<xsl:template match="group">
17<xsl:apply-templates select="name"/>
18</xsl:template>
19
20</xsl:stylesheet>
21