DATABASE VALUE BIND IN XML AND VIEW IN ASPX PAGE USING XSLT
FIRST DESIGN IN ASPX PAGE:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="xslt._default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Xml ID="Xml1" DocumentSource="product.xml" TransformSource="product.xslt" runat="server" />
</form>
</body>
</html>
GETVALUE FROM DATABASE AND WRITE IN XML PAGE
Default.aspx
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Xsl;
namespace xslt
{
public partial class _default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data
Source=192.168.1.6;Initial Catalog=Sample_Ecommerce;Integrated
Security=True");
protected void Page_Load(object sender, EventArgs e)
{
string strSQL = "Select *
from Product_Master";
SqlDataAdapter dt = new SqlDataAdapter(strSQL, con);
DataSet ds = new DataSet();
dt.Fill(ds, "product");
ds.WriteXml(Server.MapPath("product.xml"));
}
}
}
NEXT CREATE IN XML PAGE(DECLARE IN PRODUCT.XML)
Product.xml
<?xml version="1.0" standalone="yes"?>
NEXT DESIN IN XSLT PAGE.(CREATE NAME INPRODUCT.XSLT)
Product.xslt
<?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="xml" indent="yes"/>
<xsl:template match="/">
<table border="1">
<tr>
<th>product_id</th>
<th>Productname</th>
<th>
Productdes
</th>
<th>
Image
</th>
<th>
Price
</th>
<th>
status
</th>
<th>
Createdby
</th>
<th>
created
</th>
<th>
uom
</th>
<th>
OpeningStock
</th>
<th>
OpeningDate
</th>
<th>
ClosingStock
</th>
<th> ClosingDate</th>
</tr>
<xsl:for-each select="NewDataSet/product">
<xsl:sort select="product_id" data-type="number"/>
<!--<xsl:if
test="product_id<'2'">-->
<tr>
<td>
<xsl:value-of select="product_id"/>
</td>
<td>
<xsl:value-of select="Productname"/>
</td>
<td>
<xsl:value-of select="Productdes"/>
</td>
<td valign="bottom" align="center">
//(THIS IS VIEW IN IMAGE FROM DATABASE)
<img>
<input type="image"
name="imagem" width="450px">
<xsl:attribute
name="src">
<xsl:value-of
select="image" />
</xsl:attribute>
</input>
</img>
</td>
<td>
<xsl:value-of select="Price"/>
</td>
<td>
<xsl:value-of select="status"/>
</td>
<td>
<xsl:value-of select="Price"/>
</td>
<td>
<xsl:value-of select="Createdby"/>
</td>
<td>
<xsl:value-of select=" created"/>
</td>
<td>
<xsl:value-of select="uom"/>
</td>
<td>
<xsl:value-of select="OpeningStock"/>
</td>
<td>
<xsl:value-of select="OpeningDate"/>
</td>
<td>
<xsl:value-of select=" ClosingStock"/>
</td>
<td>
<xsl:value-of select=" ClosingDate"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>