XSL - problem finding CSS file, pictures etc.

  • Thread starter Thread starter Joachim
  • Start date Start date
J

Joachim

I have a piece of code that looks like this:

XPathNavigator l_nav =
xml_document.DocumentElement.CreateNavigator();
XslCompiledTransform l_xslt = new XslCompiledTransform();
l_xslt.Load(xsl_document_location);
l_xslt.Transform(l_nav, null, output_stream);
//l_xslt.Transform(l_nav, null, new
StreamWriter("TRANSFORMED.html"));

I have a link to a css document in the xsl code. If I uncomment the last
row, which stores the transform into a file, the file TRANSFORMED.html is
created and it looks just fine with the CSS styles applied. But if I only use
the line above and keep the resulting translation in RAM the css styles are
NOT applied when sending the translation to a
System.Windows.Forms.WebBrowser, even though I have put the CSS file just
about everywhere. What am I doing wrong? Can't the web browser resolve the
file? Do I have to give the file in some way to the WebBrowser? It that case
- how do I do that?
 
Joachim said:
I have a piece of code that looks like this:

XPathNavigator l_nav =
xml_document.DocumentElement.CreateNavigator();
XslCompiledTransform l_xslt = new XslCompiledTransform();
l_xslt.Load(xsl_document_location);
l_xslt.Transform(l_nav, null, output_stream);
//l_xslt.Transform(l_nav, null, new
StreamWriter("TRANSFORMED.html"));

I have a link to a css document in the xsl code. If I uncomment the last
row, which stores the transform into a file, the file TRANSFORMED.html is
created and it looks just fine with the CSS styles applied. But if I only use
the line above and keep the resulting translation in RAM the css styles are
NOT applied when sending the translation to a
System.Windows.Forms.WebBrowser, even though I have put the CSS file just
about everywhere. What am I doing wrong? Can't the web browser resolve the
file? Do I have to give the file in some way to the WebBrowser? It that case
- how do I do that?

This is not really a C# problem. However the issue will be that the path
of the CSS file will be relative. Ordinarily a web browser will use the
documents URL as basis to resolve relative URLs it finds inside it. If
though you write directly to the document then the document doesn't have a
URL on which to base the resolution of relative URLs.

You have a few options:

Inject all your CSS into a <style> element in the HTML (ugly).

Make all paths in the HTML (src and hrefs) absolute paths (also ugly)

Add a <base> element to the head of the HTML which specifies the path to a
folder which acts as a basis to resolve relative URLs.
 
Back
Top