Wednesday 11 April 2012

xsltproc: exslt functions, and SEGV

This has a habit of coming back to bite me when I have forgotten about it, but essentially there is an issue with performing XSLT within a block. If the XSLT within the result block is too extensive and results in a large return block or node-set, then it causes xsltproc to SEGV. There is a simple way to defend against this from ever happening, but it requires a little concious thought and consistency.

To prevent the func:result from throwing a wobbly, you must ensure you encapsulate your return value in a variable where you would otherwise return the result. Thus func:result:


<func:result>
  <xsl:for-each select="myns:isInteresting(exsl:node-set($nodes)/Thing)">
    <xsl:value-of select="@name"/>
  </xsl:for-each>
</func:result>

Becomes:

<xsl:variable name="ret">
  <xsl:for-each select="myns:isInteresting(exsl:node-set($nodes)/Thing)">
    <xsl:value-of select="@name"/>
  </xsl:for-each>
</xsl:variable>
<func:result select="$ret"/>