This attribute may be set on any instruction in the stylesheet, including a literal result element, though the recommended use is to set it on an xsl:template or xsl:function declaration. The permitted values are yes and no. If the value is yes, then at compile time Saxon outputs (to the standard error output) a representation of the optimized expression tree for the template or function containing that instruction. The tree is represented by indentation. For example, consider this source code:

<xsl:variable name="p" select="0"/> <xsl:template match="/" saxon:explain="yes" xmlns:saxon="" exclude-result-prefixes="saxon"> <a> <xsl:choose> <xsl:when test="$p != 0"><xsl:value-of select="1 div $p"/></xsl:when> <xsl:otherwise>12</xsl:otherwise> </xsl:choose> </a> </xsl:template>

This produces the output:

Optimized expression tree for template at line 8 in file:/e:/temp/test.xsl: <directElement name="a" validation="skip"> <valueOf> <literal value="12" type="xs:string"/> </valueOf> </directElement>

This indicates that the template has been reduced to an instruction to create an element with name a, whose content is a single text node holding the string "12". This is because Saxon has established at compile time that it will always take the "otherwise" branch of the xsl:choose instruction. There is no xsl:value-of instruction in the source code, but the literal text node "12" is compiled to the same code as if the user had written <xsl:value-of select="'12'"/>

To get this output for all templates and functions in the stylesheet, you can use the -explain option on the command line.