Global Context Item - xspec/xspec GitHub Wiki
Global context item absent
When the XSpec <x:description>
element does not have @run-as
or has @run-as="import"
, the global context item is absent (the global .
is absent) during the test. Consequently:
- Named templates are called without a context item if you don't provide
x:context
. - Global parameters and global variables in your stylesheet are always evaluated without a context item.
For example, in this stylesheet
<xsl:stylesheet ...>
<xsl:param name="p" select="foo" />
<xsl:variable name="v" select="base-uri()" />
$p
and $v
rely on the global context item. Testing this stylesheet does not work (the test will be terminated prematurely), because .
is absent when evaluating @select
of $p
and $v
during the test.
One solution is to override $p
and $v
with global x:param
:
<x:description ...>
<x:param name="p" href="source-document.xml" select="foo" />
<x:param name="v" href="source-document.xml" select="base-uri()" />
<x:scenario ...>
Alternatively, you may want to refactor your stylesheet so that the global context item is always accessed indirectly as a single global parameter and then your XSpec can override it with a global x:param
. See tutorial/global-context-item/
.
Different global context item in each scenario
When /x:description/@run-as
is external
, every XSpec scenario has a different global context item depending on how the tested component is invoked. See its page for details.