Home  >  Article  >  Backend Development  >  Detailed introduction to formatting XML documents using CSS stylesheets

Detailed introduction to formatting XML documents using CSS stylesheets

黄舟
黄舟Original
2017-03-21 16:33:532107browse

This article is suitable for friends who have a certain CSS foundation. If you don’t have the foundation of CSS, you can go to Chinesew3schools to learn.

1XML is introduced in CSS styles.

Introduced CSS style sheet into XML Two methods. One is to embed the CSS style directly in the XML document; the other is to introduce it externally (it seems to be in # Many introduction methods in ##WEB have these two methods). The method to directly embed the CSS style in XML is as follows:

1 <?xml version="1.0" encoding="utf-8"?>
 2 <?xml-stylesheet type="text/css"?>
 3 <xml>
 4   <HTML:STYLE xmlns:HTML="http://www.w3.org/profiles/XHTML-transitional">
 5     book{
 6       display:block;
 7       background-color:#FFE4C4;
 8       margin:5px;
 9     }
10     name{
11       display:block;
12       line-height:30px;
13     }
14     author{
15       display:block;
16       line-height:30px;
17     }
18     date{
19       display:block;
20       line-height:30px;
21     }
22   </HTML:STYLE>
23   <book>
24     <name>Xml应用系列</name>
25     <author>学路的小孩</author>
26     <date>2009-03-23</date>
27   </book>
28 </xml>

 ​ Code Description: The first line is the header declaration of the XML file, as a well-formed Xml documents should add header declaration information. The second line is the declaration of the CSS style, where xml-stylesheet means XMLAdd a style sheet to the document, type="text/css" means the type of style sheet is CSS Style sheet. The content between the fourth line and the 22nd line is the CSS style content, of which the fourth line is used to declare the addition of CSSCode, line 22 is its closing tag. The following lines are the contents of the XML document. After adding the CSS style, we open this XML in IE Document, the effect is as follows:

    

 第二种方式是外部引用。外部引用的代码示例如下:

1 <?xml version="1.0" encoding="utf-8"?>
2 <?xml-stylesheet type="text/css" href="bookstyle.css"?>
3 <xml>
4   <book>
5     <name>Xml应用系列</name>
6     <author>学路的小孩</author>
7     <date>2009-03-23</date>
8   </book>
9 </xml>

     代码说明 第一行为Xml文档的声明;第二行中添加了一个href属性,它表示引入外部的CSS文件,文件的名字是bookstyle.css。后面的几行是XML文档的内容。我在bookstyle.css中写入的样式如下:

 1     book{
 2       display:block;
 3       background-color:gray;
 4       margin:5px;
 5     }
 6     name{
 7       display:block;
 8       line-height:30px;
 9     }
10     author{
11       display:block;
12       line-height:30px;
13     }
14     date{
15       display:block;
16       line-height:30px;
17     }

     这个样式跟第一个样式的唯一区别就是背景改为了gray,在IE中显示的效果为:

     

2CSS设置XML文档的显示效果

Use selectors in CSS to format XML documents. The selector is generally one or more XML tags, such as the above book, name , etc., the attributes and attribute values ​​displayed in curly braces are separated by colons. Using CSS, you can set whether the label content is displayed through the dispaly attribute. The attribute value is none, block, inline, list-item. In addition, CSS can also set the font, color, text, margin, border, filling and positioning display of XML. These usage methods are the same as those used in HTML, so they will not be explained in detail here. The next article will explain how to use XSLT to template XML documents. Friends who like it, please continue to pay attention.

The above is the detailed content of Detailed introduction to formatting XML documents using CSS stylesheets. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn