The ASPX Page and XSLT to style the XML from SQL Server (VB) : to XML « ADO.net Database « ASP.NET Tutorial

ASP.NET Tutorial
1. ASP.Net Instroduction
2. Language Basics
3. ASP.net Controls
4. HTML Controls
5. Page Lifecycle
6. Response
7. Collections
8. Validation
9. Development
10. File Directory
11. Sessions
12. Cookie
13. Cache
14. Custom Controls
15. Profile
16. Configuration
17. LINQ
18. ADO.net Database
19. Data Binding
20. Ajax
21. Authentication Authorization
22. I18N
23. Mobile
24. WebPart
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.NET Tutorial » ADO.net Database » to XML 
18. 56. 2. The ASPX Page and XSLT to style the XML from SQL Server (VB)
<%@ Page Language="VB" 
         AutoEventWireup="false" 
         CodeFile="Default.aspx.vb" 
         Inherits="_Default" %>
         
         
<asp:xml id="Xml1" runat="server" transformsource="~/Data.xslt"/>

File: Data.xslt

Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs_
           Handles Me.Load
        Dim connStr As String = "database=Northwind;Data Source=.\SQLEXPRESS;" & _
                " User id=Tom;pwd=password"
        Dim As New XmlDocument()
        Dim xpathnav As XPathNavigator = x.CreateNavigator()
        Using conn As New SqlConnection(connStr)
            conn.Open()
            Dim command As New SqlCommand("select * from Customers as Customer " & _
                "for XML AUTO, ELEMENTS", conn)
            Using xw As XmlWriter = xpathnav.PrependChild()
                xw.WriteStartElement("Customers")
                Using xr As XmlReader = command.ExecuteXmlReader()
                    xw.WriteNode(xr, True)
                End Using
                xw.WriteEndElement()
            End Using
        End Using
        Xml1.XPathNavigator = xpathnav
    End Sub
End Class

File: Data.xslt

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <h3>List of Customers</h3>
        <table border="1">
            <tr>
                <td>Company Name</td><td>Contact Name</td><td>Contact Title</td>
            </tr>
            <xsl:apply-templates select="//Customer"/>
        </table>
    </xsl:template>
    <xsl:template match="Customer">
        <tr>
            <td><xsl:value-of select="CompanyName"/></td>
            <td><xsl:value-of select="ContactName"/></td>
            <td><xsl:value-of select="ContactTitle"/></td>
        </tr>
    </xsl:template>
</xsl:stylesheet>
18. 56. to XML
18. 56. 1. XML query
18. 56. 2. The ASPX Page and XSLT to style the XML from SQL Server (VB)
18. 56. 3. The ASPX Page and XSLT to style the XML from SQL Server (C#)
18. 56. 4. Retrieving XML from SQL Server 2000 using FOR XML AUTO (C#)
18. 56. 5. Retrieving XML from SQL Server 2000 using FOR XML AUTO (VB)
18. 56. 6. Run a query against a SQL Server database with an XML typed column. It then displays results in a tree-view.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.