Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# XSLT problem, parameter passing in not working

Posted on 2011-03-10
2
Medium Priority
?
587 Views
Last Modified: 2013-12-17
I have a generic routing for passing parameters to an XSLT see code fragment 1
The test harness for is in code fragment 2

for some reason the parameter is not been passed to the XSLT

Can anyone help

FRAGMENT 1
 
public string Transform(string xslt,
                                string xmlBuffer,
                                string xsltParamsAsXml, 
                                string namespaceXML)
        {
            string functionReturnValue = null;

            try
            {

            XmlDocument xmlParamsDoc = new XmlDocument();

            xmlParamsDoc.LoadXml(xsltParamsAsXml);
            
            XsltArgumentList argsList = new XsltArgumentList(); 
            
            foreach (XmlNode xmlParam in xmlParamsDoc.SelectNodes("/Params/Param"))
            {
                string name = xmlParam.Attributes.GetNamedItem("name").InnerText;
                string value = xmlParam.Attributes.GetNamedItem("value").InnerText;
                argsList.AddParam(name, namespaceXML, value);
            }

                XmlDocument XMLDOM = new XmlDocument();
                
                XMLDOM.LoadXml(xmlBuffer);

                //' We create a new XslCompiledTransform object which supercedes the XslTransform class 
                XslCompiledTransform Transformer = new XslCompiledTransform();

                //XmlReader xmlReader = new XmlTextReader();

                //Convert to Bytes
                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                Byte[] bytes = encoding.GetBytes(xslt);

                MemoryStream ms = new MemoryStream(bytes);
                Stream xlstStream = (Stream)ms;

                XmlReader xmlReader = XmlReader.Create(xlstStream);

                //' We have to load the XSL style sheet before we perform any transformation 
                Transformer.Load(xmlReader);

                //' We are setting the XmlWriterSettings so that we match the conformance level of the XmlReaderSettings 
                XmlWriterSettings myWriterSettings = new XmlWriterSettings();
                myWriterSettings.ConformanceLevel = ConformanceLevel.Fragment;

                //' Create a string builder which will eventually contain our transformed results 

                StringBuilder myString = new StringBuilder();
                //' Perform the transformation using the XmlDocument, the Parameters created from the Iterator and 
                //' write it to the StringBuilder 

                Transformer.Transform(XMLDOM, argsList, XmlWriter.Create(myString, myWriterSettings));

                functionReturnValue = myString.ToString();

            } /* throw */
            catch (Exception ex)
            {
                GenericLogger.ErrorLog(_userName, _machineName, ex.Message);

                throw new Exception("xmlFunctions:: Transform " + ex.Message);
            } /* catch */

            return functionReturnValue; 

        }

Open in new window




FRAGMENT 2
fileXLST = @"\\server2\batchXSLTDatabasesForRuleEngine.xslt";
xlstBuf = uF.ReadFileToString(fileXLST);
string ParamXML = "<Params><Param name='Environment' value='DEV'></Param></Params>";
xmlBuf = uF.ReadFileToString(@"\\SERVER2\XML\AlphaStartup02.xml");
string xmlTransformedDB = xlst.Transform(xlstBuf, xmlBuf, ParamXML, "");
xmlTransformedDB = xlst.FormatXml(xmlTransformedDB);

Open in new window

0
Comment
Question by:peter3244
  • 2
2 Comments
 

Accepted Solution

by:
peter3244 earned 0 total points
ID: 35093516
Found problem

These lines ibn the XSLT file...

<xsl:template match="/">
<xsl:param name="Environment"></xsl:param>

 should be the other way around...

<xsl:param name="Environment"></xsl:param>
<xsl:template match="/">

Anyone know why?
0
 

Author Closing Comment

by:peter3244
ID: 35093530
lines in XLST FILE WRONG way around...


MANY THANKS
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question