XSLT Error Reference

XTSE0010

All versions XSLT static error
Error message
Element xsl:otherwise is not allowed at this location / xsl:X must not appear directly within xsl:Y

An XSLT element appears somewhere the language grammar does not allow: wrong nesting, wrong order, or content at the stylesheet top level that must live inside a template.

What it means

The stylesheet is well-formed XML, but an element sits in a position the XSLT grammar forbids. Saxon names the offending element and its location.

Common causes

  1. Output markup at the top level. Literal result elements (your <html>, <result>…) must be inside an xsl:template, never directly under xsl:stylesheet.
  2. Wrong order inside xsl:choose — every xsl:when must come before xsl:otherwise; nothing else is allowed inside xsl:choose.
  3. xsl:param after other content. In a template, all xsl:param declarations must be first.
  4. xsl:import not first. xsl:import must precede every other declaration in the stylesheet.
  5. Instructions used as declarations — e.g. xsl:value-of directly under xsl:stylesheet.

How to fix it

The message is specific — it tells you which element and where. Typical corrections:

<!-- Before: literal element at top level → XTSE0010 -->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <result/>
</xsl:stylesheet>

<!-- After: wrap it in a template -->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <result/>
  </xsl:template>
</xsl:stylesheet>