Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6873167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:01:37+00:00 2026-05-27T04:01:37+00:00

I am getting an intermittent System.Xml.Xsl.XslTransformException exception in our production environment when attempting an

  • 0

I am getting an intermittent System.Xml.Xsl.XslTransformException exception in our production environment when attempting an xslt transform, unfortunately I cannot replicate this in the development environment.

The exception spits out further details:

Execution of the ‘document()’ function was prohibited. Use the
XsltSettings.EnableDocumentFunction property to enable it. An error
occurred at C:\path\to\file\CDS.xsl(16,3).

However the EnableDocumentFunction property is set to true in the processing code:

private void Transform()
{
    var keepTrying = true;
    var tryCount = 0;
    const int maxRetrys = 3;

    while (keepTrying)
    {
        try
        {
            var xmlResolver = new XmlUrlResolver();

            using (var xmlFile = new XmlNodeReader(_xDoc))
            {
                var settings = new XmlReaderSettings
                                   {
                                       XmlResolver = xmlResolver,
                                       ProhibitDtd = false,
                                       DtdProcessing = DtdProcessing.Ignore
                                   };

                using (var xsl = XmlReader.Create(_xslPath, settings))
                {
                    var xslt = new XslCompiledTransform(true);
                    xslt.Load(xsl, new XsltSettings { EnableDocumentFunction = true }, xmlResolver);

                    var sb = new StringBuilder();
                    using (var writer = XmlWriter.Create(sb, xslt.OutputSettings))
                    {
                        xslt.Transform(xmlFile, null, writer, xmlResolver); // errors out here.
                    }

                    var xhtml = sb.ToString();
                    _transformedXml = xhtml;
                    _isTransformed = true;

                    xsl.Close();
                }
            }

            keepTrying = false;
        }
        catch (System.Xml.Xsl.XsltException ex)
        {
            ExceptionPolicy.HandleException(ex, "ExceptionLogging");

            tryCount++;
            if (tryCount > maxRetrys)
            {
                keepTrying = false;
                throw;
            }
        }
    }
}

The xslt file is provided by a third party and automatically updated, so rewriting it is not an option. Here is the top of it, slightly modified for privacy reasons:

<?xml version="1.0"?>

<!--
     Interaction_550.xsl : 20110916
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:example="http://www.example.com" version="1.0">
  <xsl:param name="D2DSeverityFilter"></xsl:param>
  <xsl:param name="D2HSeverityFilter"></xsl:param>
  <xsl:param name="DocumentationFilter"></xsl:param>
  <xsl:output method="html"/>
  <xsl:key name="d2d_sev_level-lookup" match="example:d2d_sev_level" use="@name"/>
  <xsl:key name="d2h_sev_level-lookup" match="example:d2h_sev_level" use="@name"/>
      <xsl:key name="d2l_sev_level-lookup" match="example:d2l_sev_level" use="@name"/>
      <xsl:key name="preg_cat-lookup" match="example:preg_cat" use="@cat"/>
  <xsl:key name="doc_level-lookup" match="example:doc_level" use="@name"/>
  <xsl:variable name="d2d_sev_level-top" select="document('')/*/example:d2d_sev_levels"/>
  <xsl:variable name="d2h_sev_level-top" select="document('')/*/example:d2h_sev_levels"/>
      <xsl:variable name="d2l_sev_level-top" select="document('')/*/example:d2l_sev_levels"/>

  <xsl:variable name="doc_level-top" select="document('')/*/example:doc_levels"/>
      <xsl:variable name="preg_cat-top" select="document('')/*/example:preg_cats"/>
  <xsl:template match="/">
    <head>
      <style type="text/css">
body {
font-family : arial,sans serif,helvetica;
}
...

How can I:

  • fix this so that it does not happen at all?
  • failing that, how could I go about replicating this in dev?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:01:38+00:00Added an answer on May 27, 2026 at 4:01 am

    Here is a general way to get rid of the document('')/*/someName expressions:

    The original transformation is processed with a special transformation that generates an equivalent transformation that doesn’t contain the document('') function call.

    Then you just need to use the generated transformation.

    Example:

    This transformation (lets name it tA), containing document(''):

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:my="my:my" >
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <my:paramDoc1>
      <x>123</x>
      <y>37</y>
     </my:paramDoc1>
    
     <my:paramDoc2>
      <x>456</x>
      <y>79</y>
     </my:paramDoc2>
    
     <xsl:variable name="vpDoc1" select="document('')/*/my:paramDoc1"/>
     <xsl:variable name="vpDoc2" select="document('')/*/my:paramDoc2"/>
    
     <xsl:template match="/*">
         <xsl:value-of select="$vpDoc1/x"/>
         <xsl:text>|</xsl:text>
         <xsl:value-of select="$vpDoc2/y"/>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on any document, produces:

    123|79
    

    Now we process the above transformation with this one (tGen):

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:x="a:a" exclude-result-prefixes="x">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:namespace-alias stylesheet-prefix="x"
          result-prefix="xsl"/>
    
     <xsl:variable name="vApos">'</xsl:variable>
    
     <xsl:variable name="vSelectPrefix" select=
      "concat('document(', $vApos,$vApos, ')/*/')"/>
    
     <xsl:template match="node()|@*" name="identity">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="xsl:stylesheet">
      <x:stylesheet xmlns:ext="http://exslt.org/common">
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
      </x:stylesheet>
     </xsl:template>
    
     <xsl:template match="xsl:variable">
      <xsl:variable name="vSelattr" select="@select"/>
      <xsl:choose>
          <xsl:when test="not(starts-with(@select, $vSelectPrefix))">
            <xsl:call-template name="identity"/>
          </xsl:when>
          <xsl:otherwise>
          <x:variable name="vrtf{@name}">
            <xsl:copy-of select=
            "/*/*[name()
                 = substring-after($vSelattr, $vSelectPrefix)
                 ]"/>
          </x:variable>
    
          <x:variable name="{@name}" select=
               "ext:node-set($vrtf{@name})/*"/>
          </xsl:otherwise>
      </xsl:choose>
     </xsl:template>
    
    </xsl:stylesheet>
    

    The result is a new transformation (tRes), which doesn’t contain expressions like document(''):

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:ext="http://exslt.org/common">
        <xsl:output omit-xml-declaration="yes" 
             indent="yes" xmlns:my="my:my" />
        <xsl:strip-space elements="*" xmlns:my="my:my" />
        <my:paramDoc1 xmlns:my="my:my">
            <x>123</x>
            <y>37</y>
        </my:paramDoc1>
        <my:paramDoc2 xmlns:my="my:my">
            <x>456</x>
            <y>79</y>
        </my:paramDoc2>
        <xsl:variable name="vrtfvpDoc1">
            <my:paramDoc1 xmlns:my="my:my">
                <x>123</x>
                <y>37</y>
            </my:paramDoc1>
        </xsl:variable>
        <xsl:variable name="vpDoc1" select="ext:node-set($vrtfvpDoc1)/*" />
        <xsl:variable name="vrtfvpDoc2">
            <my:paramDoc2 xmlns:my="my:my">
                <x>456</x>
                <y>79</y>
            </my:paramDoc2>
        </xsl:variable>
        <xsl:variable name="vpDoc2" select="ext:node-set($vrtfvpDoc2)/*" />
        <xsl:template match="/*" xmlns:my="my:my">
            <xsl:value-of select="$vpDoc1/x" />
            <xsl:text>|</xsl:text>
            <xsl:value-of select="$vpDoc2/y" />
        </xsl:template>
    </xsl:stylesheet>
    

    If we now apply this dynamically generated transformation (tRes) to any XML document, the result is exactly the same as when applying the original transformation (tA) to this document:

    123|79
    

    Therefore, we can use tGen to convert a transformation containing document('') expressions to an equivalent transformation that doesn’t contain such expressions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are getting intermittent problems on a production server that we cannot recreate. There
I'm getting an intermittent exception saying that asp.net mvc can’t find the action method.
We are seeing an intermittent issue on development and production machines whereby our log
We keep getting this error randomly in our web application. System.Data.SqlClient.SqlException: A network-related or
I am getting an intermittent out of memory exception at this statement: return ms.ToArray();
A user is getting an intermittent error Cannot create file C:...\Filename.ini. The requested operation
I’m getting an intermittent false negative on the following line of code in an
I'm getting some strange, intermittent, data aborts (< 5% of the time) in some
I have an ASP.NET 2.0 application that is working fine in our local environment.
We use MVC controllers that access System.File.IO in our application and they work fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.