Home Backend Development XML/RSS Tutorial Detailed introduction to formatting XML documents using CSS stylesheets

Detailed introduction to formatting XML documents using CSS stylesheets

Mar 21, 2017 pm 04:33 PM

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>
Copy after login

 ​ 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>
Copy after login

代码说明 第一行为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     }
Copy after login

     这个样式跟第一个样式的唯一区别就是背景改为了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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

See all articles