开发者

XML basic style options

So I'm returning xml from a web service and I get this message in the browser (firefox)

This XML file does not appear to have any style information associated with it. The document tree is shown below.

Is this a simple fix by just passing a CSS style sheet? or is the a pre开发者_StackOverflow中文版ferred way of styling XML?


It is possible to style XML with CSS and with XSLT. Most browsers will apply both CSS and XSLT stylesheets and render the results, when the proper processing instruction is provided in the XML.

To apply CSS to an XML file add a processing instruction like this:

<?xml-stylesheet type="text/css" href="my-style.css" ?>

To apply XSLT to an XML file add a processing instruction like this:

<?xml-stylesheet type="text/xsl" href="my-transform.xsl" ?>

If your styling requirements are more display and decoration of the XML content, rather than transformation, then CSS styling might be easier.

Check out this W3C page: How to add style to XML


The preferred way of styling XML is XSLT. And if I'm not mistaken, XSL stylesheets are what the message actually refers to.

Without any further info, I cannot suggest anything specific. If you show some of your XML and say how it should be represented, I could get you started with a basic XSL stylesheet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜