-2

I know we can edit an XML file to include a reference to a stylesheet.

We want to display an external XML file (from a 3rd party job site's feed for a specific company) inside a WordPress webpage and style it somehow.

i.e. we can't insert a link to the stylesheet inside the XML file.

Steve
  • 2,066
  • 13
  • 60
  • 115
  • 3
    **We need far far more details**. Where is the XML file being loaded from? What software is it being loaded into? What's the context? There's a world of difference between loading an XML file from `fetch` into an existing web browser document vs. styling an XML document rendered in a desktop app's MSHTML view and everything in-between. And "XML" is just an arbitrary structured document: only application-specific XML schemas have provision for stylesheets, but most XML documents can be styled using XSLT. – Dai Mar 02 '22 at 13:32
  • 1
    You can't _simply load_ XML into an ` – Dai Mar 02 '22 at 13:37
  • i think you can't do it inside an iframe, you should consider to serve that xml through an php script that will download the xml, and insert stylesheet inside, then call your php page instead of original url – pavelbere Mar 02 '22 at 13:43

1 Answers1

2

HTML has a link element to link to external style sheets, but not every XML-based format will have such an element. If there is no suitable element, you can still attach external style sheets by means of the xml-stylesheet processing instruction like this:

<?xml-stylesheet href="my-style.css"?>
... rest of document here...

This processing instruction (PI) must come before the first tag of the document. The type="text/css" is not required, but it helps the browser: if it doesn't support CSS, it knows it won't have to download this file.

Just as with the link element of HTML, there can be multiple xml-stylesheet PIs and they can have attributes to set the type, medium and title.

Areg Nikoghosyan
  • 449
  • 5
  • 14
  • Thanks. How would we embed the XML file in the HTML page? – Steve Mar 09 '22 at 23:13
  • @Steve In order to formulate an appropriate response, please tell us what your current level of understanding of HTML is, and if you're working within an XHTML context. – Dai Mar 11 '22 at 16:44
  • @Dai, I am proficient in HTML, I don't think I would be using an XHTML context though. – Steve Mar 12 '22 at 09:35