<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:fg="http://www.fgeorges.org/xslt/samples"
                version="2.0">

   <xsl:template match="/">
      <html>
         <head/>
         <body>
            <xsl:apply-templates select="*" mode="y"/>
         </body>
      </html>
   </xsl:template>

   <xsl:template match="*" name="nana" mode="y">
      <b>
         <xsl:value-of select="name(.)"/>
         <xsl:sequence select="fg:fun(*)"/>
      </b>
   </xsl:template>

   <xsl:template match="xsl:function/xsl:choose | aa//bb" mode="y">
      <b>
         <xsl:sequence select="fg:fun(*)"/>
      </b>
   </xsl:template>

   <xsl:function name="fg:fun">
      <xsl:param name="n" as="node()*"/>
      <xsl:choose>
         <xsl:when test="$n[0][name() = 'inexistent']">
            <xsl:apply-templates mode="y" select="
                $n[position() mod 2 eq 0]"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates mode="y" select="$n"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:function>

   <xsl:template match="xsl:otherwise" mode="y">
      <xsl:if test="@test">
         <xsl:sequence select="'&#10;'"/>
      </xsl:if>
      <dummy>
         <xsl:sequence select="
             error(xs:QName('fg:ERR007'), 'My error message')"/>
      </dummy>
   </xsl:template>

</xsl:stylesheet>
