Solved

C# XSLT problem, parameter passing in not working

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now