473,379 Members | 1,330 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,379 software developers and data experts.

VB.NET XML XSL Transformation HELP!?!?

Please Help:

I have this wonderful function that takes as input an XML as a string and an XSLT as a string and using the XSLT, transforms the XML returning the result...

Public Function Trans(ByVal XMLStr As String, ByVal XSLTStr As String) As String
Dim TransObj As New MSXML2.DOMDocument
Dim OutputXML As New MSXML2.DOMDocument
Dim OutStr As String

If OutputXML.loadXML(XMLStr) Then
If TransObj.loadXML(XSLTStr) Then
OutStr = OutputXML.transformNode(TransObj)
End If
End If
Return OutStr
End Function

Problem being it makes use of the MSXML Interop COM Object, and I'm trying to upgrade it to VB.NET only code... no Interop COM.

I can't figure out how (and haven't seen an example of how to) using xml.xsl.xsltransform or whatever I need to use, how to do this process strictly in memory. The inputs _must_ be an XML contained in a string and the XSLT contained in a string. These are both being gerenated dynamically from the database, not from files or from Intenet locations.

Any Ideas? Anyone?

Thanks,

Currently Confused Dayton Gary
Apr 27 '06 #1
4 6217
Did you ever find out how to do this? I have also spent days looking for a solution and not quite figured out how to do it!

Thanks,

Darren

Please Help:

I have this wonderful function that takes as input an XML as a string and an XSLT as a string and using the XSLT, transforms the XML returning the result...

Public Function Trans(ByVal XMLStr As String, ByVal XSLTStr As String) As String
Dim TransObj As New MSXML2.DOMDocument
Dim OutputXML As New MSXML2.DOMDocument
Dim OutStr As String

If OutputXML.loadXML(XMLStr) Then
If TransObj.loadXML(XSLTStr) Then
OutStr = OutputXML.transformNode(TransObj)
End If
End If
Return OutStr
End Function

Problem being it makes use of the MSXML Interop COM Object, and I'm trying to upgrade it to VB.NET only code... no Interop COM.

I can't figure out how (and haven't seen an example of how to) using xml.xsl.xsltransform or whatever I need to use, how to do this process strictly in memory. The inputs _must_ be an XML contained in a string and the XSLT contained in a string. These are both being gerenated dynamically from the database, not from files or from Intenet locations.

Any Ideas? Anyone?

Thanks,

Currently Confused Dayton Gary
Oct 10 '06 #2
Hey Darren...

This is as close as I have gotten (but there is a bug in here and I haven't had the time to find it or fix it).

Public Function Transform(ByVal XMLStr As String, ByVal XSLTStr As String) As String
Dim XSLT As XslTransform = New XslTransform
Dim XR As New System.Xml.XmlTextReader(XMLStr, XmlNodeType.Document, Nothing)
Dim XSR As New System.Xml.XmlTextReader(XSLTStr, XmlNodeType.Document, Nothing)

Dim MyData As New System.Xml.XPath.XPathDocument(XR)
XSLT.Load(XSR, Nothing, Nothing)

Dim MyWriter As New System.IO.StringWriter
XSLT.Transform(MyData, Nothing, MyWriter, Nothing)
XSLT = Nothing
Return MyWriter.ToString
End Function

This **should be** as simple as:
Dim XSLT as new Xml.XslTransformer(XSLTString)
Return XSLT.Transform(XMLString).ToString
Oct 10 '06 #3
hey try this for XML to XSL transform

//create a dataset
DataSet dsReportData;
//fill this using any adaptor

XmlDataDocument XMLDoc, string strXSLFullFilePath;

XMLDoc = new new XmlDataDocument(dsReportData);
strXSLFullFilePath = @"C:\temp\anyxslfile.XSL";

System.IO.FileStream fs;
XmlTextWriter objXmlTxtWrt;
StringReader objStrRdr;
XmlTextReader objXmlTxtRdr;
XPathDocument objXPathDoc;
XslCompiledTransform objXslTran;



try
{
//'Create An Xpath Doc
objStrRdr = new StringReader(XMLDoc.OuterXml);
objXmlTxtRdr = new XmlTextReader(objStrRdr);
objXPathDoc = new XPathDocument(objXmlTxtRdr);



fs = new System.IO.FileStream(strExcelFile,
System.IO.FileMode.Create);

//'Create an XmlTextWriter for the FileStream.
objXmlTxtWrt = new XmlTextWriter(fs,
System.Text.Encoding.Unicode);
//'Transform the XML using the stylesheet.

objXslTran = new XslCompiledTransform();

strXSLFullFilePath = strXSLFullFilePath.Replace(XSLStyleSheetFolder, "");

strXSLFullFilePath = strExcelFile;
fs.Close();
objXslTran.Load(strXSLFullFilePath);

objXslTran.Transform(objXPathDoc, objXmlTxtWrt);


}

catch (Exception e)
{ Console.Write(e.Message); }
finally
{
objXPathDoc = null;
objXslTran = null;
//xslRes = null;
}
Oct 11 '06 #4
Hi Dayton Gary,

Your example seems to work fine for me. I have added argument support for the function and a simple try catch.

Hope this makes it a bit more useful...

Private Function ApplyXSLT(ByVal sXML As String, ByVal sXSLT As String, ByVal argsList As XsltArgumentList) As String
Try
Dim XSLT As XslTransform = New XslTransform
Dim XR As New System.Xml.XmlTextReader(sXML, XmlNodeType.Document, Nothing)
Dim XSR As New System.Xml.XmlTextReader(sXSLT, XmlNodeType.Document, Nothing)

Dim MyData As New System.Xml.XPath.XPathDocument(XR)
XSLT.Load(XSR, Nothing, Nothing)

Dim MyWriter As New System.IO.StringWriter
XSLT.Transform(MyData, argsList, MyWriter, Nothing)
XSLT = Nothing
Return MyWriter.ToString
Catch ex As Exception

End Try
End Function

Darren
Oct 11 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
4
by: Kevin Dean | last post by:
I'm trying to create an XSL transformation that will strip out development-specific attributes from deployment descriptors and other XML files. I have already successfully done so with web.xml but...
7
by: CK | last post by:
Hello, I have the 60 MB XML string and I am coding a program in Visual Basic to run a XSL transformation on it. Currently, I'm using the Microsoft standard MSXML 2.0 to create a DOM document, load...
4
by: Mike Conmackie | last post by:
Hi Folks, I've probably omitted something very basic but I have no idea what it might be. The results of my transformation _should_ be an xml file but all I get is the xml declaration...
0
by: pulvertum | last post by:
Hello, I need an org.w3c.dom.Document so I can pass them to do a transformation of my XML using XSL (to another XML as result). I've tried several solutions but didn't have the desired result:...
12
by: gipsy boy | last post by:
Hello, I have sort of a big problem. I would really appreciate any help you could give me. I made a web service in C++ that throws XML to the client (browser). But, the XSLT transormation...
1
by: Ali Asghar | last post by:
Hi, Please I need help.I have a problem of client side XSL transformation. I sent the XML and the XSL to the client in XML data islands. Using the transform Node method the HTML is returned....
6
by: Jain, Pranay Kumar | last post by:
Hi All, We have created a simple application that takes a dataset and generates the data in Excel schema format. It uses an xslt file to do the transformation for excel 2002 and so on. We are...
0
by: Hugo Ferreira | last post by:
Hi all, I'm having a problem here, to which I hope someone to be able to help me :) I need to apply a XSLT transformation to the output of all my ASPX webpages. I've recently found the tag...
14
by: Thomas Bauer | last post by:
Hello, I search a example like that. (1,0,0,1,4,5 ) -- moving (1,0,0,1,0,0 ) -- normal matrix (-1,0,0,1,0,0 ) -- Mirror Y-Axis (0,-1,0,1,0,0 ) -- Mirror X-Axis I caluculate all in mm.
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.