Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transforming xml/xsl in vb using msxml:script

Status
Not open for further replies.

stevecvb

Programmer
Apr 11, 2002
6
US
I am trying to transform xml/xsl in a visual basic app. The transform works for straight forward xml/xsl. When using the msxml:scipt I am getting an invalid class string error when setting the xsltemplate.stylesheet. Here is my code

number.xml----
<?xml version='1.0'?>
<data>
<circle>
<radius>12</radius>
</circle>
<circle>
<radius>37.5</radius>
</circle>
</data>

calc.xsl-------
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;xmlns:msxsl=&quot;urn:schemas-microsoft-com:xslt&quot;
xmlns:user=&quot;urn:my-scripts&quot;>

<msxsl:script language=&quot;C#&quot; implements-prefix=&quot;user&quot;>
<![CDATA[
public double circumference(double radius){
double pi = 3.14;
double circ = pi*radius*2;
return circ;
}
]]>
</msxsl:script>

<xsl:template match=&quot;data&quot;>
<circles>

<xsl:for-each select=&quot;circle&quot;>
<circle>
<xsl:copy-of select=&quot;node()&quot;/>
<circumference>
<xsl:value-of select=&quot;user:circumference(radius)&quot;/>
</circumference>
</circle>
</xsl:for-each>
</circles>
</xsl:template>
</xsl:stylesheet>

visual basic app code ---
Dim xmlSource As New MSXML2.DOMDocument30
Dim xmlOutput As New MSXML2.DOMDocument30
Dim xslTemplate As New MSXML2.XSLTemplate30
Dim xmlStylesheet As New MSXML2.FreeThreadedDOMDocument30
Dim xslProcessor As MSXML2.IXSLProcessor

xmlSource.Load (&quot;C:\Clients\Netik\InterView Adapters\Transform\number.xml&quot;)

If xmlSource.parseError.reason <> &quot;&quot; Then
MsgBox &quot;ERROR: &quot; & xmlSource.parseError.reason & vbCrLf & &quot;SOURCE: &quot; & _
xmlSource.parseError.srcText, vbExclamation, App.Title
End If

xmlStylesheet.Load (&quot;C:\Clients\Netik\InterView Adapters\Transform\calc.xsl&quot;)

If xmlStylesheet.parseError.reason <> &quot;&quot; Then
MsgBox &quot;ERROR: &quot; & xmlStylesheet.parseError.reason & vbCrLf & &quot;SOURCE: &quot; & _
xmlStylesheet.parseError.srcText, vbExclamation, App.Title
End If

Set xslTemplate.stylesheet = xmlStylesheet

Set xslProcessor = xslTemplate.createProcessor

xslProcessor.input = xmlSource
xslProcessor.output = xmlOutput

xslProcessor.Transform

Transform = xmlOutput.xml

THANKS,
Steve
 
Is your C# code in the Global Assembly Cache?

Chip H.
 
This is just a simple example cut from the msdn. Ultimately I need to use a vbscript utilizing ADO in the msxml:script tag. It has not been added to the global assembly cahce. Any further help appreciated(pref. for vb script)
 
Add it to the GAC and try again.
Otherwise it's a private assembly, and the XML parser might not be able to find it.

Also - why are you using DOMDocument30? The 4.0 parser is much better.

Chip H.
 
Just upgrade to xml4.0 and seeing the same problem. I am trying this example using vb6.0. I am not using the .net framework, so adding this to the GAC would not make sense. The code I am using is actually vb in the script tag, not c# as shown above. Any further info appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top