0

i have a user control in which i want to pass page url to my XSL sheet and apply it to my XML file . as a result of it should produce some HTML output. Please explain how to do this?

xml file name: myXml.xml 
Xsl file name: mwXsl.xsl
Parameter to be passed by usercontrol(.cs) file: url of parent page.

i've defined XSL stylesheet. All i need to pass the argument to that file. in usercontrol(ascx) file i have this code

<asp:Xml ID="BControl" runat="server" DocumentSource="/wsitemap.sitemap" TransformSource="/Bread.xslt"></asp:Xml>

where wsitemap.sitemap is a XML file. if my XSLT get the argument the above code will be able to produce the desired output. so i need c# code for that.

in usercontrol (.cs file) i have :

public static string Transform(string xml, string xsl, XsltArgumentList argsList) 
    { 
        XDocument selectedXml = XDocument.Parse(xml);
        XslCompiledTransform xmlTransform = new XslCompiledTransform();
        StringBuilder htmlOutput = new StringBuilder();
        XmlWriter writer = XmlWriter.Create(htmlOutput);
        xmlTransform.Load(new XmlTextReader(new StringReader(xsl)));
        xmlTransform.Transform(selectedXml.CreateReader(), argsList, writer);
        return htmlOutput.ToString();
    } 
    protected void Page_Load(object sender, EventArgs e)
    {
        string curPageId = Page.Request.Url.AbsoluteUri;
        XsltArgumentList xslArgs = new XsltArgumentList();
        xslArgs.AddParam("curPage", "", curPageId);
        string output=Transform("wsitemap.sitemap","bread.xslt",xslArgs);
        Response.Clear(); Response.Write(output);
    }

but this code is not working , any other approach plz tell me

AmateurCoder
  • 4,272
  • 3
  • 17
  • 31

1 Answers1

0

You have use , XsltArgumentList C# class to pass arguments. You can add all your parameters there and pass to the xsl.

Please look into following SO Link,

Passing parameters to XSLT Stylesheet via .NET

Community
  • 1
  • 1
Rajesh Subramanian
  • 6,400
  • 5
  • 29
  • 42