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 486999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:33:37+00:00 2026-05-13T01:33:37+00:00

I have modified the title of the question after finding the answer :) :P

  • 0

I have modified the title of the question after finding the answer 🙂 😛

I am loading an XML file and an XSL file by a C# program and triggering the XSL transformation .. here is the code for it:

static void Main(string[] args)
{

    // Create the XslCompiledTransform and load the stylesheet.
    XslCompiledTransform xslt = new XslCompiledTransform();
    xslt.Load("input.xsl");    //located in Debug folder
    //Load XSL argument list
    XsltArgumentList xslArg = new XsltArgumentList();

    // Transform the file.
    using (XmlWriter w = XmlWriter.Create("output.xml"))
    {
        xslt.Transform("input.xml", xslArg, w);    //located in Debug folder
    }
}

The error is I am not able to load XML file.

The XSL file contains some C# code which is meant to calculate the difference between two DateTime strings .. well, I can transform the XML file manually using the same XSL file .. But when I try to trigger the transformation using C# code .. then it says “It can’t load XML file”

Here is my (part of) XSL code ..

<span bgcolor="#EEEEEE">

   &lt;xsl:variable name="date1" select="//date1"/&gt;
   &lt;xsl:variable name="date2" select="//date2"/&gt;

   &lt;msxsl:script language="C#" implements-prefix="cs"&gt;
   &lt;![CDATA[
         public string datediff(string date1, string date2) {

            DateTime startTime = new DateTime(Convert.ToInt32(date1.Substring(6, 4)), Convert.ToInt32(date1.Substring(0, 2)), Convert.ToInt32(date1.Substring(3, 2)), Convert.ToInt32(date1.Substring(11, 2)), Convert.ToInt32(date1.Substring(14, 2)), Convert.ToInt32(date1.Substring(17, 2)), 0);

            DateTime endTime = new DateTime(Convert.ToInt32(date2.Substring(6, 4)), Convert.ToInt32(date2.Substring(0, 2)), Convert.ToInt32(date2.Substring(3, 2)), Convert.ToInt32(date2.Substring(11, 2)), Convert.ToInt32(date2.Substring(14, 2)), Convert.ToInt32(date2.Substring(17, 2)), 0);

    return(endTime.Subtract(startTime));

         }
     ]]>
   &lt;/msxsl:script&gt;<br>
   &lt;xsl:template match="datediff"&gt;<br>
    &lt;xsl:element name="{local-name()}"&gt;<br>
      &lt;xsl:value-of select="cs:datediff($date1, $date2)" /&gt;<br>
    &lt;/xsl:element&gt;<br>
   &lt;/xsl:template&gt;<br></span>

Is that, because of script(C# code to calculate date diff..) I am getting this error?
By the way C# code runs perfectly when I use some other input XML and XSL files ..

please help me to overcome this error ..

  • 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-13T01:33:37+00:00Added an answer on May 13, 2026 at 1:33 am

    As Steve cooper has mentioned .. you need to enable the XSLT script .. and here is the way to do it:

    first define a new settings instance:

    var settings = new XsltSettings();
    

    then enable the script

    settings.EnableScript = true;
    

    Create the XslCompiledTransform object and load the style sheet, passing in the settings object.

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

Sidebar

Related Questions

I have modified a working Windows service that had always been starting beforehand. After
I have cloned a remote SVN repository with git-svn. I have modified a pom.xml
EDIT : You're not allowed to have the word question in the title. Q-mark
Alternate question title would be: How to explicitly have the compiler generate code for
The title may be a bit vague, but here's my goal: I have a
I have modified a slider script to mimic ebay's slider on home page. I
I have modified the Nerd Dinner application to allow editing of child records by
I have modified my MOSS 2007 configuration to query a given target AD successfully.
I have modified a website with a redirection to a single page: RewriteCond %{REQUEST_FILENAME}
I have modified unobtrusive validation script to replace error messages with qtips. To do

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.