Page 1 of 1

Adding a CSS stylesheet to xml

Posted: Sun Jun 04, 2017 3:25 am
by felix1845
I am very confused about using a css stylesheet to alter the formatting of xml in a browser. I have an xslt stylesheet, and that works fine, but the css doesn't appear to make any difference.

At the top I have <?xml-stylesheet href="text.css" type="text/css"?>. Is this wrong? The css file is called "text.css".

I know there have been posts on this before, but I've read them and can't make sense of them.

Re: Adding a CSS stylesheet to xml

Posted: Mon Jun 05, 2017 8:02 am
by Radu

If you open an XML document with an associated CSS in a web browser, the CSS selectors must match those particular XML elements and style them. So you cannot have the CSS match HTML element names, they need to match the XML element names as you have not converted the XML to HTML.