views:

43

answers:

2

I am following w3c schools to learn XSLT. in An example. In-line styling is performed here. How can I link an external (CSS) style sheet to style HTML compliant tags?

A: 

As long as the XSLT outputs normal HTML in the browser, this should do the trick:

HTML:

<html>
  <body>
  <h2>My CD Collection</h2>
  <table class="mytable">
    <tr>
      <th>Title</th>
 ...
</table>

CSS:

.mytable
{
border: 1px solid #000;
}

.mytable tr
{
background-color: #9acd32;
}

.mytable th
{
styles
}

Edit:

Seems you need to declare them in a different way, check out this link, it has a very good explanation:

http://www.w3.org/TR/NOTE-XSL-and-CSS

Hope that helps :)

Kyle Sevenoaks
I have a different working scenario.I am directly exploring xml document from the browser.An associated xsl style sheet defines the HTML like structure for xml nodes. The output is like HTML , means no collapsible hierarchical layout. Here I need to associate an external css to be included to this setup. Do I need to attach it in xsl, xml or in both and how?
Shoaib
Updated my answer.
Kyle Sevenoaks
A: 

The way XSL and CSS stylesheets are handled varies between browser. Take IE as example: when you include two process instruction (XSL and CSS) into a XML document, XSL takes precedence over CSS.

I think that the best cross-browser way would be: if you want an external CSS stylesheet for your HTML transformation output, you must add a html:link element into the result tree.

Check, www.aranedabienesraices.com.ar as an example.

Alejandro