问题是这样的,如果我把transformNode后的内容保存为html文件,然后用webbrowser去navigate这个文件,是对的,因为html文件里有这句:
<link href="2.css" rel="stylesheet" type="text/css" />
这个css文件和生成的html文件在一个目录下.
但如果我不保存html文件,直接用webbrowser显示transformNode后的内容,发现css没有起作用,
如果我把<link href="2.css" rel="stylesheet" type="text/css" />
里的2.css改成绝对路径,就对了.
因为我不想hardcopy一个绝对路径,也不想动态修改xml和xsl文件,应该怎么办?

解决方案 »

  1.   

    如果不保存为HTML文件再打开浏览器不知道路径啊浏览器就是通过HTML文件的路径来定位相对路径的不知道还有没有其它方法设置浏览器的默认路径
      

  2.   

    没错,我就是希望能找到办法告诉webbrowser默认路径是什么. 另外,我试了在显示前SetCurrentDirectory到css所在的路径,也是没用的
      

  3.   

    The easiest way to do this is to embed a <base> tag into the generated
    HTML. You don't have to save it to disk, or make visible to the user,
    just feed it in the stream with the rest of the content.Another way is to write a custom implementation of IMoniker interface.
    You only need a non-trivial implementation of two methods: BindToStorage
    should return the IStream with your HTML content, and GetDisplayName
    should return the base URL you want to use to resolve relative links.
    You then use IPersistMoniker to feed the content into MSHTML using this
    custom implementation, instead of IPersistStreamInit. Disclaimer: I have
    not done this myself, but I've seen people reporting successful use of
    this technique.Changed your LoadFromStream method to QI on the WebBrowser Document for
    IPersistMoniker then pass your implementation of IMoniker that
    implemented BindToStorage and GetDisplayName. In BindToStorage you simply use
    a TStreamAdapter and return the stream.