<!--- Match toes element. ---> <xsl:template match="toes"> <!--- Loop over each toe. ---> <xsl:for-each select="toe"> <!--- Only output names of toe elements that have a nested name element. ---> <xsl:if test="name"> <!--- Output name of the context toe. ---> [<xsl:value-of select="name/text()" />] </xsl:if> </xsl:for-each> </xsl:template>