Read the transformed result of XslTransform and output the result (VB.net) : XslTransform « XML « ASP.NET Tutorial

Home
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
ASP.NET Tutorial » XML » XslTransform 
25.19.2.Read the transformed result of XslTransform and output the result (VB.net)
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="System.Xml.Xsl" %>

<script runat="server">
   sub Page_Load(Sender as Object, e as EventArgs)
      Dim objReader as New XmlTextReader(Server.MapPath("Data.xml"))
      
      Dim objDoc as XPathDocument = new XPathDocument(objReader)
      
      Dim objXSLT As XslTransform = New XslTransform()
      dim objWriter as XmlTextWriter = new XmlTextWriter(Server.MapPath("output.html"), nothing)

      try
         objXSLT.Load(Server.MapPath("Data.xsl"))
         dim objReader2 as XmlReader = objXslT.Transform(objDoc, nothing)
         While objReader2.Read()
            Response.Write("<b>" & objReader2.Name & "</b> " & _
               objReader2.Value & "<br>")
         End While

      catch ex As Exception        
         Response.Write(ex.Message)
      finally
         objReader.Close
         objWriter.Close
      end try
   end sub   
</script>

<html><body>
</body></html>


File: Data.xml


<?xml version="1.0"?>
<bookstore>
  <book genre="asdf">
    <title>asdf</title>
    <author>
      <first-name>asdf</first-name>
      <last-name>asdf</last-name>
    </author>
    <price>asdf</price>
  </book>
  <book genre="asdf">
    <title>asdf</title>
    <author>
      <first-name>asdf</first-name>
      <last-name>asdf</last-name>
    </author>
    <price>asdf</price>
  </book>
  <book genre="asdf">
    <title>asdf</title>
    <author>
      <first-name>asdf</first-name>
      <last-name>asdf</last-name>
    </author>
    <price>asdf</price>
  </book>
</bookstore>

File: Data.xsl

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:op="x-schema:books.xdr"
   version="1.0" >
   <xsl:template match="op:bookstore">
      <HTML><BODY>
      <TABLE width="450">
      <TR>
         <TD><b>Title</b></TD>
         <TD><b>Price</b></TD>
      </TR>
      <xsl:apply-templates select="op:book"/>
      </TABLE>
      </BODY></HTML>
   </xsl:template>
   <xsl:template match="op:book">
      <TR>
         <TD><xsl:value-of select="op:title"/></TD>
         <TD><xsl:value-of select="op:price"/></TD>
      </TR>
   </xsl:template>
</xsl:stylesheet>
25.19.XslTransform
25.19.1.Use XslTransform to trasnform XML data to HTML file (VB.net)
25.19.2.Read the transformed result of XslTransform and output the result (VB.net)
25.19.3.Display data from database in asp:Xml with xml transformation
25.19.4.Transform XML document to HTML
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.