Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am saving data from database in xml file as below:
public partial class HS_SearchResult : System.Web.UI.Page
{
    ConnectionLogin cl = new ConnectionLogin(); // user define class 
    public string SearchResults = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet ds = new DataSet("Category");
        ds = cl.dataset("select * from tblItem where cat_id = "+Request.QueryString["q"]);
        // get xml file from data set

        string XMLfile = ds.GetXml();
        
        SearchResults = GetHtml(Server.MapPath("~/HS/XSLTFILES/Searchcat.xslt"), XMLfile);
    }
    public static string GetHtml(string xsltpath,string xmlfile)
    {
        MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(xmlfile));
        XPathDocument xx = new XPathDocument(stream);
        StringWriter wr = new StringWriter();
        XslCompiledTransform xc = new XslCompiledTransform();
        xc.Load(xsltpath);
        xc.Transform(xx, null, wr);
        return wr.ToString();
    }
}

This code is working correctly.
when i am transforming this xml file into HTML through xslt file. code is given below in xslt file..
XML
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">

      <html>
        <head>
          <title></title>
        </head>
        <body style="color:black;">
          <h1>Your Result Here</h1>

            <table id="searchresult">
              <xsl:for-each select="Category/cat_id"> // i think the mistake is here can any body tell me what shoult be the right directory in select attribute
              <tr>

                <td class="labledata"> Name:</td>
                <td>
                  <xsl:value-of select="item_name"/>
                </td>
              </tr>
              <tr>
                <td class="labledata">Address:</td>
                <td>
                  <xsl:value-of select="item_owner"/>
                </td>
              </tr>

              </xsl:for-each>

            </table>
          rohihumai

        </body>
      </html>
    </xsl:template>
</xsl:stylesheet>


Result: Your Result Here i.e written in H1 tag of this file.
<xsl:for-each select="Category/cat_id"> // i think the mistake is here can any body tell me what shoult be the right directory in select attribute
Posted
Updated 22-Nov-13 20:53pm
v3
Comments
José Amílcar Casimiro 22-Nov-13 12:53pm    
Sql Injection -> ds = cl.dataset("select * from tblItem where cat_id = "+Request.QueryString["q"]);

Here is the xml file?

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