0

What is the cause of a Stack usage error from libxml2/libxslt/lxml?

Phillip B Oldham
  • 18,807
  • 20
  • 94
  • 134

2 Answers2

1

It seems that you're using lxml extension functions. In this case, the "Stack usage error" (XPATH_STACK_ERROR internally) happens when a value is popped off the XPath stack and the stack is empty. The typical scenario is an extension function called with fewer parameters than expected.

nwellnhof
  • 32,319
  • 7
  • 89
  • 113
  • Yes, I'm using `lxml`. I've recently upgraded the libxml2 library and code that worked a week ago has now completely stopped working with this single error where previously other errors may have been raised. – Phillip B Oldham Nov 15 '13 at 18:30
0

As per @nwellnhof's answer, this stems from the fact that an extension function has been registered and called fewer parameters than expected.

In my case, it was because I was passing in the contents of a node and in some instances that node was empty. Previously this was fine, but something in my toolchain had changed and started to raise this error.

My original code looked something like:

<xsl:template match="foo">
  <xsl:value-of select="my:func(.)" />
</xsl:template>

When foo was empty, the "Stack usage error" was raised, often grouped with an "Unregistered function" error. The simple fix was to only match when there was content within foo, eg:

<xsl:template match="foo[./*]">
  <xsl:value-of select="my:func(.)" />
</xsl:template>
Community
  • 1
  • 1
Phillip B Oldham
  • 18,807
  • 20
  • 94
  • 134