473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

xslt.transfer function, I need it return a string of sorts

I have done my best to answer this question but can not find the
proper set of commands. I would like
to transform an xml file (in code behind) and display its output in a
specific html tag, such as a div with
a runat=server. I can somewhat do this if I create a server control
and include the control within the html
div tag but this method (borrowed from ASP.NET Website Programming by
Wrox press thanks guys) does not give me
the full control over the xml.

In my app I need to load different xml docs (depended on
selections from a previous screen). I have
the following html code:
----------------------------------------------------------------------
<%@ Page Language="vb"
AutoEventWireup="false"
Codebehind="QuestionnairePage.aspx.vb"
Inherits="Battelle.QuestionnairePage" enableViewState="True"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Form Document</TITLE>
<meta content="Microsoft Visual Studio .NET 7.1"
name="GENERATOR">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET
7.1">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<link rel="stylesheet"
href="../Styles/QuestionStyle.css">
<script type="text/javascript" language="JavaScript"
src="../Config/Code/XMLactions.js" />
</HEAD>
<body MS_POSITIONING="GridLayout"
onload="formatUI(document.form1);">
<FORM id="form1" method="post" runat="server">
<DIV class="xml_Div" id="xmlData"
style="WIDTH: 100%; POSITION: absolute; HEIGHT: 100%"
runat="server"
MS_POSITIONING="GridLayout">
</DIV>
</FORM>
</body>
</HTML>
----------------------------------------------------------------------

The folling vb.NET code:
----------------------------------------------------------------------
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath
Public Class QuestionnairePage
Inherits System.Web.UI.Page
Protected WithEvents xmlSourceBox As
System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents xsltSourceBox As
System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents xmlData As
System.Web.UI.HtmlControls.HtmlGenericControl
Dim _err As Exception
#Region " Web Form Designer Generated Code "
--code takenout to save space.
#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If (Not IsPostBack) Then
Dim DocID As Integer =
CInt(Trim(Request.QueryString("DocID")))
Dim DocVersion As Double =
CDbl(Trim(Request.QueryString("Ver")))
Dim EmployeeID As String =
UCase(Trim(Request.QueryString("EmpID")))
Dim xDoc As New XmlDocument
Dim xslt As New XslTransform
If EmployeeID.Length = 0 Then
'get data
retrieveMasterDocument(xDoc, xslt, DocID, DocVersion)
Else
'get data
retrieveUserDocument(xDoc, xslt, DocID, DocVersion,
EmployeeID)
End If
'display xml
displayXML(xDoc, xslt)
End If
End Sub

Private Sub displayXML(ByRef xDoc As XmlDocument, ByRef xslt As
XslTransform)
Dim resolver As XmlUrlResolver = New XmlUrlResolver
resolver.Credentials =
System.Net.CredentialCache.DefaultCredentials
Dim xmlStream As Stream

' Transform the file.
'Get error here because xmlStream is Nothing.
xslt.Transform(xDoc, Nothing, xmlStream, resolver)
Dim htmlText As String = New
StreamReader(xmlStream).ReadToEnd()
xmlData.InnerHtml = htmlText

'This replaces all html on the page.
'xslt.Transform(xDoc, Nothing, Page.Response.Output, Nothing)

End Sub

Private Sub pageError(ByRef err As Exception)
Try
If err.Message.Length > 0 Then
Response.StatusDescription = err.Message
Response.Redirect("../Screens/RunTimeError.aspx")
End If
Catch ex As Exception

End Try
End Sub

Private Sub retrieveMasterDocument(ByRef xDoc As XmlDocument,
ByRef xslt As XslTransform, ByVal docID As Integer, ByVal version As
Double)
Dim _xsltPath As String = "../Styles/Question.xslt"
xslt.Load(context.Server.MapPath(_xsltPath))
Dim data As New
DataRetrieval(ConfigurationSettings.AppSettings("A nsweredQuestions_LOCAL"))
xDoc = data.selectMasterDocument(docID, version, _err)
pageError(_err)
End Sub

Private Sub retrieveUserDocument(ByRef xDoc As XmlDocument, _
ByRef xslt As XslTransform, _
ByVal docID As Integer, _
ByVal version As Double, _
ByVal emplID As String)
Dim _xsltPath As String = "../Styles/Question.xslt"
xslt.Load(context.Server.MapPath(_xsltPath))
Dim data As New
DataRetrieval(ConfigurationSettings.AppSettings("A nsweredQuestions_LOCAL"))
xDoc = data.selectAnsweredDocument(emplID, docID, version,
_err)
pageError(_err)
End Sub
End Class
----------------------------------------------------------------------

The sub displayXML tries to use a stream object to capture the
transformed
xml and then convert that stream into a string then into the
..innerHTML.
I am getting an error message because the stream object is Nothing.
My take is that
I should not be using the stream this way. Anyone have any ideas of
how to
transform an xml into a string so it can be placed surgically into the
html page?

Nov 12 '05 #1
0 2321

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Darren Davison | last post by:
given the following DOM snippet; <root> <sub1 foo="4">testing</sub1> <sub1 foo="0">hello</sub1> <sub1 foo="0">world</sub1> <sub1>hello again</sub1> </root> I need to transform with XSL to...
0
by: Jay Allard | last post by:
Hello I posted this in the vb.net group on the 2/25/2004, but didn't get any response. Here's attempt 2. Does anyone know of a more appropriate place to post this? One new piece of...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
1
by: Nick | last post by:
I am working on a website for a client and one of their requirements was to have a mailing list. I decided to XSLT to transform "templates" to HTML so that editing was very easy and less time...
3
by: shaun roe | last post by:
mild rant follows Working now for a couple of years with xslt and now xslt 2.0, does anyone else get the impression that xslt 2.0 somehow missed the point? Yes its got a fancy new data model...
12
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I...
4
by: Andrew Jackson | last post by:
I am writing a newsgroup client. I have the protocol figured out. But I get slow transfer speeds off any of the network objects read the data from For example one of the commands for a news...
2
by: Jonny B | last post by:
Hi all, I'm working on an a clientside xslt using jscript that passes a parameter to the xsl. I've got it working no problem in IE but cant get it to work in Mozilla. Can anyone help? This is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.