Solved

C# XSLT problem, parameter passing in not working

Posted on 2011-03-10
2
572 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

820 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