JustinEzequiel
Programmer
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="1.0"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
<xsl:template match="/">
<portfolio xmlns:dt="urn:schemas-microsoft-com:datatypes">
<xsl:for-each select="investments/item[@type='stock']">
<stock>
<xsl:attribute name="exchange"><xsl:value-of select="@exch"/></xsl:attribute>
<name><xsl:value-of select="@company"/></name>
<symbol><xsl:value-of select="@symbol"/></symbol>
<price dt:dt="number"><xsl:value-of select="@price"/></price>
</stock>
</xsl:for-each>
</portfolio>
</xsl:template>
</xsl:stylesheet>
parse error properties:
errorCode: -1072897790
filepos: 489
Line: 10
linepos: 56
reason: Element "xsl:value-of" is not allowed in this context.
srcText: <price dt:dt="number"><xsl:value-of select="@price"/></price>
url: file:///I:/Temp/delme/xml/ms/io.xsl