Stack Overflow problem transforming with a custom xslt

Posted by Flynn1179 on Stack Overflow See other posts from Stack Overflow or by Flynn1179
Published on 2010-06-01T14:06:25Z Indexed on 2010/06/01 14:33 UTC
Read the original article Hit count: 251

Filed under:
|
|

I've got a system that allows the user the option of providing their own XSLT to apply to some data that's been retrieved, as a means of specifying how that data should be presented. However, if the user includes code in the XSLT equivalent to:

<xsl:template match="/">
  <xsl:element name="data">
    <xsl:apply-templates select="." />
  </xsl:element>
</xsl:template>

this causes .NET to infinitely recurse trying to process it, and produces a stack overflow error. I need to be able to trap this before it crashes the app, as the data that's been retrieved is occasionally quite time-consuming to obtain, and the data is lost when this happens.

Is there any way of doing this? I know it's theoretically possible to identify any occurrences of xsl:apply-templates with "." in the select attribute, but this isn't the only way an infinite recursion could happen, I need a way of generically trapping it.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about xslt