-
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
-
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>
-
Re: Displaying data read from a data source, on a dynamically generated HTML
Here's the XSL Style (OpenX2.xsl)
<?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>
-
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>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks