DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Aqeel Khan Guest

    Displaying data read from a data source, on a dynamically generated HTML


    Hi there!

    Is it possible to display data from an external source, while using a XML
    Style Sheet template to generate a dynamic html page? If so how? So examples
    would be nice.

    Thanks in advance.

    Aqeel Khan



  2. #2
    dsg Guest

    Re: Displaying data read from a data source, on a dynamically generated HTML


    "Aqeel Khan" <khan_Aqeel@hotmail.com> wrote:
    >
    >Hi there!
    >
    >Is it possible to display data from an external source, while using a XML
    >Style Sheet template to generate a dynamic html page? If so how? So examples
    >would be nice.
    >
    >Thanks in advance.
    >
    >Aqeel Khan
    >
    >


    Here's an example. It uses OpenX from http://www.openx.ca. I believe you
    may port it for use with ADO as well.

    <%@ Language=VBScript %>
    <%
    Set oConn = Server.CreateObject("OpenX2.Connection")
    Set oCommand = Server.CreateObject("OpenX2.Command")
    Dim sResult, sSQL, sResultStr, sResultDoc
    Dim bError
    Dim i
    sSQL = "SELECT * FROM titles"

    On Error Goto 0

    Sub ProcessErr
    If Err.number <> 0 Then
    bError = true
    sResult = ""
    If oConn.ErrorCode <> 0 Then
    sResult = "OpenX2 Connection Error: " & oConn.ErrorInfo & ". Error
    #" & oConn.ErrorCode & " (" & oConn.ErrorCodeEx & ")<br />"
    Else
    If oCommand.ErrorCode <> 0 Then
    sResult = "OpenX2 Command Error: " & oCommand.ErrorInfo & ". Error
    #" & oCommand.ErrorCode & " (" & oCommand.ErrorCodeEx & ")<br />"
    End If
    End If
    If sResult = "" Then
    Rem you may reRaise the Error here if you want to allow IIS process
    rest of errors
    sResult = "ASP Error: #" & CStr(Err.Number) & ". " & Err.description
    & "<br />"
    End If
    End If
    End Sub

    Sub ProcessQuery
    bError = false
    oConn.Connect("ms_ox1")
    oCommand.Connection = oConn
    oCommand.CommandText = sSQL
    sResultStr = oCommand.XMLString
    oCommand.Close()

    oCommand.CommandText = sSQL
    REM // Set stylesheet locations
    Dim styleFile
    Set xmlTmpl = Server.CreateObject("Msxml2.XSLTemplate.2.6")
    Set xslStyle = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.2.6")
    styleFile = Server.MapPath("OpenX2.xsl")
    xslStyle.async = false
    xslStyle.load(styleFile)
    Set xmlTmpl.stylesheet = xslStyle
    Set xmlProc = xmlTmpl.createProcessor()
    REM // Get the XMLDocument from OpenX2
    xmlProc.input = oCommand.XMLDocument
    If xmlProc.transform() Then
    sResultDoc = xmlProc.output
    End If
    End Sub

    REM // Main Processing
    On Error Resume Next
    ProcessQuery
    ProcessErr

    %>

    <html>
    <head><title>OpenX2 Test #9 - XML Output</title></head>
    <%
    If Not bError Then
    %>
    <XML id="source"><%=sResultStr%></XML>
    <XML id="style" src="OpenX2.xsl"></XML>
    <script type="text/javascript" event="onload" for="window">
    showResult.innerHTML = source.transformNode(style.XMLDocument);
    </script>
    <%
    End If
    %>
    <body>
    <%
    If Not bError Then
    %>
    <h1>Server-Side XMLDocument Processing</h1>
    <div><%=sResultDoc%></div>
    <h1>Client-Side XML-Island (String) Processing</h1>
    <div id="showResult"></div>
    <%
    Else
    %>
    <div><%=sResultDoc%></div>
    <%
    End If
    %>
    <%= sResult %>
    </body>
    </html>

  3. #3
    dsg Guest

    Re: Displaying data read from a data source, on a dynamically generated HTML


    Here's the XSL Style (OpenX2.xsl)

    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:template match="RECORDSET"&gt;
    &lt;xsl:element name="table"&gt;
    &lt;xsl:for-each select="RECORD"&gt;
    &lt;xsl:element name="tr"&gt;
    &lt;xsl:for-each select="FIELD"&gt;
    &lt;xsl:element name="td"&gt;
    &lt;xsl:value-of select="."/&gt;
    &lt;/xsl:element&gt;
    &lt;/xsl:for-each&gt;
    &lt;/xsl:element&gt;
    &lt;/xsl:for-each&gt;
    &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="/"&gt;
    &lt;xsl:apply-templates select="RECORDSET"/&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="text()"&gt;
    &lt;xsl:value-of select="."/&gt;
    &lt;/xsl:template&gt;
    &lt;/xsl:stylesheet&gt;

  4. #4
    dsg Guest

    Re: Displaying data read from a data source, on a dynamically generated HTML


    "dsg" <info@openx.ca> wrote:
    >
    >Here's the XSL Style (OpenX2.xsl)
    >


    Here's the code (fixed group display problems)

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="RECORDSET">
    <xsl:element name="table">
    <xsl:for-each select="RECORD">
    <xsl:element name="tr">
    <xsl:for-each select="FIELD">
    <xsl:element name="td">
    <xsl:value-of select="."/>
    </xsl:element>
    </xsl:for-each>
    </xsl:element>
    </xsl:for-each>
    </xsl:element>
    </xsl:template>
    <xsl:template match="/">
    <xsl:apply-templates select="RECORDSET"/>
    </xsl:template>
    <xsl:template match="text()">
    <xsl:value-of select="."/>
    </xsl:template>
    </xsl:stylesheet>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links