Geeks With Blogs

News


Rodney Vinyard - .NET & SQL Developer When all is said and done, more will be said than done

Private Sub GetXSLT()

Try

Dim parms As Specialized.HybridDictionary = New Specialized.HybridDictionary

Dim df As New DataFactory

Dim dataset As DataSet = df.GetDataSet("storedProc_GetBusinessUnitsAndEmployees", parms)

'--------------------------------------------------------------------

'Get the primary key column from the master table

'--------------------------------------------------------------------

Dim primarykey As DataColumn = dataset.Tables("Table").Columns("CODE_LIST_ID")

'--------------------------------------------------------------------

'Get the foreign key column from the detail table

'--------------------------------------------------------------------

Dim foreignkey As DataColumn = dataset.Tables("Table1").Columns("CODE_LIST_ID")

'--------------------------------------------------------------------

'Assign a relation

'--------------------------------------------------------------------

Dim relation As DataRelation = dataset.Relations.Add(primarykey, foreignkey)

'--------------------------------------------------------------------

'Alternative code when multiple columns in keys:

'--------------------------------------------------------------------

'--------------------------------------------------------------------

'Get the primary key column from the master table

'--------------------------------------------------------------------

Dim primaryColumns() As DataColumn

Dim foreignColumns() As DataColumn

primaryColumns = New DataColumn() {dataset.Tables("Table").Columns("EMPLOYEE_ID"), dataset.Tables("Table").Columns("CODE_LIST_ID")}

foreignColumns = New DataColumn() {dataset.Tables("Table1").Columns("EMPLOYEE_ID"), dataset.Tables("Table1").Columns("CODE_LIST_ID")}

'--------------------------------------------------------------------

'Assign a relation

'--------------------------------------------------------------------

Dim relation As DataRelation = dataset.Relations.Add(primaryColumns, foreignColumns)

'--------------------------------------------------------------------

'Ask ADO.NET to generate nested XML nodes

'--------------------------------------------------------------------

relation.Nested = True

'--------------------------------------------------------------------

'Create a virtual XML document on top of the DataSet

'--------------------------------------------------------------------

Dim doc As XmlDataDocument = New XmlDataDocument(dataset)

'--------------------------------------------------------------------

'debug - write doc to string

'--------------------------------------------------------------------

Dim docString As String = doc.InnerXml

'--------------------------------------------------------------------

'Load the XSLT file.

'NOTE: Here it is compiled as an embedded resource file

'--------------------------------------------------------------------

Dim myAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()

Dim xslTransform As New Xsl.XslTransform

Dim xslStream As Stream = myAssembly.GetManifestResourceStream("myAssembly.BusinessUnitSummary.xslt")

Dim xmlTextReader As New XmlTextReader(xslStream)

xslTransform.Load(xmlTextReader, Nothing, Nothing)

'--------------------------------------------------------------------

'Transform the results to stringWriter

'--------------------------------------------------------------------

Dim stringWriter As New System.IO.StringWriter

xslTransform.Transform(doc.CreateNavigator(), Nothing, stringWriter, Nothing)

'--------------------------------------------------------------------

'convert stringWriter to html string

'--------------------------------------------------------------------

Dim html As String = stringWriter.ToString()

'--------------------------------------------------------------------

'load string (HTML) into Label1

'--------------------------------------------------------------------

Label1.Text = html

Catch ex As Exception

Dim x As String = ex.ToString

Throw ex

End Try

End Sub

Posted on Thursday, December 28, 2006 1:22 PM XML & Datasets | Back to top


Comments on this post: Dataset to XML then transform with XSLT to HTML on WebForm

# re: Dataset to XML then transform with XSLT to HTML on WebForm
Requesting Gravatar...
I stumbled on this post by chance, but could not tear myself away from it to the end. Great job! I'm looking forward for your future releases on this subject.
Left by writing services on Jun 10, 2010 3:45 AM

# re: Dataset to XML then transform with XSLT to HTML on WebForm
Requesting Gravatar...
gr8 job
Left by Unknown on Oct 21, 2010 4:33 AM

# re: Dataset to XML then transform with XSLT to HTML on WebForm
Requesting Gravatar...
Good work! I always like to leave comments whenever I see something unusual or impressive. I think we must appreciate those who do something especial. Keep it up, thanks
Ingrit Ray
Left by live cricket on Feb 08, 2012 12:51 PM

Your comment:
 (will show your gravatar)


Copyright © Rodney Vinyard | Powered by: GeeksWithBlogs.net