XSLT Error Reference

XPDY0002

XSLT 2.0+ XPath dynamic error
Error message
The context item for axis step ./foo is absent

An expression uses a relative path (./foo, foo/bar) in a place where there is no context node — typically inside xsl:function or a stylesheet-level variable.

What it means

Relative XPath expressions need a context item (“where am I?”). In some places — notably inside xsl:function bodies — no context item exists, so any relative path fails at runtime with XPDY0002.

Common causes

  1. Relative paths inside xsl:function. Functions are called with arguments only; they have no context node.
  2. Global xsl:variable using a relative path when the processor is invoked without a source document (e.g. starting at a named template with xsl:initial-template).
  3. Calling a named template that assumes a context established elsewhere.

How to fix it

Pass the nodes you need as parameters instead of relying on context:

<!-- Before: XPDY0002 — ./price has no context inside the function -->
<xsl:function name="my:total">
  <xsl:sequence select="sum(./item/price)"/>
</xsl:function>

<!-- After: receive the nodes explicitly -->
<xsl:function name="my:total">
  <xsl:param name="order" as="element()"/>
  <xsl:sequence select="sum($order/item/price)"/>
</xsl:function>

If you run a stylesheet with no source document, make global variables absolute or lazy — or supply an input document. In XSLT Playground add the XML input in the Input panel so the context item exists.