Among them, "xml" is the processing instruction name, version="1.0" encoding="gb2312" is the processing instruction information.
4.2 XML and CSS
CSS can be used to set the display mode of XML files, that is, add the following statement at the head of the XML file, below the XML declaration:
Let’s use examples to introduce how to use CSS to display XML files. First create a css file, the code is as follows:
flowers.css: A CSS style that displays XML files
using using using using using using through through out through out through out through out through out through ‐ ‐ toward ‐ ‐‐ ‐ , and that the code is as follows:
flowers.css red}
price{display:block}
Then, use this css style in the flowers.xml file, that is, add the following statement below the XML declaration in the flowers.xml file:
The complete program code is as follows:
ex4_3_01.xml: Use CSS to display XML files
shop1
lower>
;/Vendor>
shop3 How this example appears in the browser The effect is shown in Figure 4.2. Figure 4.2 Using CSS to display XML files When using CSS to display XML files, there is no selectivity. That is to say, all data under the root element will be displayed, and the structure and structure of the original file cannot be changed. The order of content. In addition, CSS does not support Chinese tags because CSS is not a style language specifically developed for XML, but the XSL introduced below will do. XSL is specially designed for XML and is more complex than CSS. 4.3 XSLThe effect of using CSS to display XML files introduced in the previous section is not very satisfactory. In fact, CSS is mainly suitable for HTML files. For data files such as XML, CSS is not suitable, especially for those When the file contents need to be rearranged and displayed according to different conditions, XSL can be used. XSL is currently the most powerful and flexible style language. It is specially designed for applying XML. It is much more complex than CSS. However, it is currently not well supported and not yet finalized. Use XSL to set the display mode of the XML file, that is, add the following statement to the head of the XML file, below the XML declaration: Below we use examples to introduce how to use XSL to display XML files. First create an xsl file, the code is as follows: flowers.xsl: xsl file used to display XML files
sl:for-each select ="//Flowers/Flower">
We can watch Output: An XSL file is just like an empty HTML file, and a traditional HTML file is produced by filling in an XML file.
An XSL file must first have an XML declaration (i.e. the first line), because XSL is actually a special XML file. The root element of XSL is xsl:stylesheet, that is, an XSL document must start with the tag and end with the tag. The xmlns:xsl attribute is used to set the XSL name domain.
The root element of XSL is usually composed of one or more template elements. In this example, it only contains a single template. It starts with the tag and ends with the tag. Use The match attribute can select qualified nodes in the XML file, that is, set the template name. For the top-level template, match is set to "/", which represents the root element of the entire XML file.
Then get the required data from the XML file. The easiest way to get the data is:
If you want to get multiple elements, you need to Use the xsl:for-each element in the following format:
…..
Connect Next, we need to use this xsl file in the flowers.xml file, that is, add the following statement under the XML declaration in the flowers.xml file:
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