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!

VB + MSXML3 parse error on XSL

Status
Not open for further replies.

JustinEzequiel

Programmer
Jul 30, 2001
1,192
PH
Code:
I am trying to load an XSL file for use in transforming an XML from one schema to another.

Why does .Load(...) on the XSL file return False?

my code:

Dim sInFile As String
Dim sIO As String

Dim oIn As MSXML2.DOMDocument30
Dim oOut As MSXML2.DOMDocument30
Dim oXSL As MSXML2.DOMDocument30

sInFile = "I:\Temp\delme\xml\ms\input.xml"
sIO = "I:\Temp\delme\xml\ms\io.xsl"

Set oIn = New MSXML2.DOMDocument30
Set oOut = New MSXML2.DOMDocument30
Set oXSL = New MSXML2.DOMDocument30

If oIn.Load(sInFile) Then
  If oXSL.Load(sIO) Then
    oIn.transformNodeToObject oXSL, oOut
    oOut.save "I:\Temp\delme\xml\ms\io.xml"
  Else
    With oXSL.parseError
      Debug.Print "errorCode:", .errorCode
      Debug.Print "filepos:", .filepos
      Debug.Print "Line:", .Line
      Debug.Print "linepos:", .linepos
      Debug.Print "reason:", .reason
      Debug.Print "srcText:", .srcText
      Debug.Print "url:", .url
    End With
  End If
Else
  MsgBox oIn.parseError.reason, , "Input"
End If

Set oIn = Nothing
Set oOut = Nothing
Set oXSL = Nothing



I got the XML and XSL files from [URL unfurl="true"]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmcongettingstartedwithxsl.asp[/URL]

XSL file contents:

<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;[/URL] version=&quot;1.0&quot;>
<xsl:template match=&quot;/&quot;>
<portfolio xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot;>
<xsl:for-each select=&quot;investments/item[@type='stock']&quot;>
<stock>
<xsl:attribute name=&quot;exchange&quot;><xsl:value-of select=&quot;@exch&quot;/></xsl:attribute>
<name><xsl:value-of select=&quot;@company&quot;/></name>
<symbol><xsl:value-of select=&quot;@symbol&quot;/></symbol>
<price dt:dt=&quot;number&quot;><xsl:value-of select=&quot;@price&quot;/></price>
</stock>
</xsl:for-each>
</portfolio>
</xsl:template>
</xsl:stylesheet>




parse error properties:

errorCode:    -1072897790 
filepos:       489 
Line:          10 
linepos:       56 
reason:       Element &quot;xsl:value-of&quot; is not allowed in this context.

srcText:      <price dt:dt=&quot;number&quot;><xsl:value-of select=&quot;@price&quot;/></price>
url:          file:///I:/Temp/delme/xml/ms/io.xsl
 
afaics, theres nothing wrong with you program or the xml. I cannot replicate your error with my testing software and i dont have vb.

by all accounts, load() should definately return a boolean. check for wierd/unseen newline characters in the file that may be messing up the xml parsing.


 
Thanks flumpy.

I got rid of all line breaks.
However, I still get the same error.
Could this be due to a limitation of the MS XML parser?

Code:
errorCode:    -1072897790 
filepos:       471 
Line:          1 
linepos:       472 
reason:       Element &quot;xsl:value-of&quot; is not allowed in this context.

srcText:      <?xml version=&quot;1.0&quot;?><xsl:stylesheet xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;[/URL] version=&quot;1.0&quot;><xsl:template match=&quot;/&quot;><portfolio xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot;><xsl:for-each select=&quot;investments/item[@type='stock']&quot;><stock><xsl:attribute name=&quot;exchange&quot;><xsl:value-of select=&quot;@exch&quot;/></xsl:attribute><name><xsl:value-of select=&quot;@company&quot;/></name><symbol><xsl:value-of select=&quot;@symbol&quot;/></symbol><price dt:dt=&quot;number&quot;><xsl:value-of select=&quot;@price&quot;/></price></stock></xsl:for-each></portfolio></xsl:template></xsl:stylesheet>
url:          file:///I:/Temp/xmlxsldemo/2/io.xsl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top