Solved

C# XSLT problem, parameter passing in not working

Posted on 2011-03-10
2
578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

710 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