Vb.net – xslt.Load(New XmlTextReader(New StringReader(xslt))) “xslt compile error”

vb.net

I have read the other posts and they are not resolving my problem.
The environment is VB 2008 (2.0 Framework)
The below code cause an XSLT Compile error on the xslt.Load line
Below that is the output from the error. I am passing the XSLT as a string, so not sure why I am getting the error I am.

Public Function xFrmTlogs(ByVal sXLST As String, ByVal sXML As String) As String
    Dim xslt As New XslCompiledTransform()
    Dim HTMLoutput As String
    Dim writer As New StringWriter()

    Try
        xslt.Load(New XmlTextReader(New StringReader(sXLST.ToString)))
    Catch ex As Exception
        xFrmTlogs = ex.ToString
    End Try

    Dim sourceReader As System.Xml.XmlReader = System.Xml.XmlReader.Create(New System.IO.StringReader(sXML))

    Try
        xslt.Transform(sourceReader, Nothing, writer)
    Catch ex As Exception
        xFrmTlogs = ex.ToString
    End Try

    HTMLoutput = writer.ToString()
    writer.Close()
    xFrmTlogs = HTMLoutput
End Function

System.Xml.Xsl.XslLoadException: XSLT compile error. An error occurred at (3,2). —
System.IO.DirectoryNotFoundException: Could not find a part of the path 'H:\Program
Files\common\tr_period.xsl'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32
rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options,
SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare
share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type
ofObjectToReturn)
at System.Xml.Xsl.Xslt.XsltLoader.CreateReader(Uri uri, XmlResolver xmlResolver)
at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(Uri uri, Boolean include)
at System.Xml.Xsl.Xslt.XsltLoader.LoadInclude()
at System.Xml.Xsl.Xslt.XsltLoader.LoadRealStylesheet()
at System.Xml.Xsl.Xslt.XsltLoader.LoadDocument()
at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)
— End of inner exception stack trace —
at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)
at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver
xmlResolver)
at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver,
QilExpression& qil)
at System.Xml.Xsl.XslCompiledTransform.CompileXsltToQil(Object stylesheet, XsltSettings
settings, XmlResolver stylesheetResolver)
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings
settings, XmlResolver stylesheetResolver)
at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet)
at VfiSapphire.COMWrapper.xFrmTlogs(String sXLST, String sXML) in H:\Documents and
Settings\xxx\My Documents\Visual Studio2008\ProgramName\ModuleName\PdkBo.vb:line 709

Best Solution

The XSLT script that is stored in sXSLT likely contains a <xsl:include> or an <xsl:import> element which tries to include/import another XSLT script file at H:\Program Files\common\tr_period.xsl. Since that file doesn't exist, or is otherwise inaccessible, the transform fails.

Related Question