Click here to Skip to main content
15,791,963 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear All,

I encounter a puzzle, In my original logic the page rendered by Response.Output and via XML&XSLT, and in XSLT file where only have html controls tags.
Now, I need to modify the logic, make page display server control too, so use Response.Output I can't display the server control, and the server control tags in XSLT file can't parse by ASP.NET. How can I do to implement this case?

BTW, must use Response.Output to render html. as my code, the server control txt1 can't display.

--------------------the refer code and xml, xslt file as below --------------------
    <name>XYZ Inc.</name>
    <address1>One Abc Way</address1>
    <address2>Some avenue</address2>
    <city>Tech city</city>

--------test.XSLT as below--------
      xmlns:xsl="" xmlns:asp=""

<!-- indicates what our output type is going to be -->
<xsl:output method="html" />

        Main template to kick off processing our Sample.xml
        From here on we use a simple XPath selection query to
        get to our data.
    <xsl:template match="/">

          body,td {font-family:Tahoma,Arial; font-size:9pt;}
                <h2>Welcome to <xsl:value-of select="/company/name"/></h2>
                <b>Our contact details:</b>
                <xsl:value-of select="/company/name"/>
                <xsl:value-of select="/company/address1"/>
                <xsl:value-of select="/company/address2"/>
                <xsl:value-of select="/company/city"/>
                <xsl:value-of select="/company/country"/>
        <!--<input id="text1" type="text" value="A B C D E F G"/>-->
        <asp:textbox id="txt1" visible="false" runat="server" text="A B C D E F G H I J K L M N O P Q R S T"></asp:textbox>


-------------ASPX.CS code as below-----------
<pre lang="C#">protected void Page_Load(object sender, EventArgs e)

   protected override void Render(HtmlTextWriter writer)
       BindingFlags bind = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.GetField;
       ArrayList arr = (ArrayList)Response.Output.GetType().GetField("_buffers", bind).GetValue(Response.Output);
       Assembly systemWeb = Assembly.Load("System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
       Type type = systemWeb.GetType("System.Web.IHttpResponseElement");
       MethodInfo method = type.GetMethod("GetBytes");
       StringBuilder sb = new StringBuilder(5000);
       for (int i = 0; i &lt; arr.Count; i++)
           byte[] buffer = (byte[])method.Invoke(arr[i], null);
       byte[] fromXSLT = (byte[])method.Invoke(arr[0], null);
       string fromXSLTStr = Response.ContentEncoding.GetString(fromXSLT);
       char[] charBuffer = (char[])Response.Output.GetType().GetField("_charBuffer", bind).GetValue(Response.Output);
       int charBufferLength = (int)Response.Output.GetType().GetField("_charBufferLength", bind).GetValue(Response.Output);
       int charBufferFree = (int)Response.Output.GetType().GetField("_charBufferFree", bind).GetValue(Response.Output);
       for (int i = 0; i &lt; charBufferLength - charBufferFree; i++)
       string htmlStr = sb.ToString().Replace("xmlns:asp=\"\"&gt;", "&gt;");
   public void TransForm()
       string sourceDoc = @"D:/test.xml";
       string xsltDoc = @"D:/test.xslt";
       xmldom oXML = new xmldom();
           oXML.transformNode(xsltDoc, Response.Output);
       catch (FileNotFoundException filexc)
           throw new Exception("Can't find the special files.");

Updated 8-Mar-11 17:59pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900