Functions that depend on the base URI of the static
context, notably the document() function, don't work
correctly in a simplified stylesheet. More generally,
they take the base URI from the containing xsl:template
element rather than from the immediately containing
element in the stylesheet. With a simplified stylesheet
there is no containing xsl:template and the base URI is
therefore null. If xml:base is used within a template,
or if external entities are used, then the wrong base
URI will be used.
This happens because optimization (a call on analyze)
now happens at two levels, firstly at the level of an
individual XPath expression, and then again at the
level of an xsl:template (or xsl:function, etc).
Functions such as document() make a note of the base
URI during this process. The fix is to change the
analyze() methods of these functions so they only
remember the base URI on the first such call.