The first XML document With the development of the Internet, more and more information enters the Internet, information exchange, retrieval, preservation, and reuse such an urgent need to make HTML this most commonly used markup language has become more and more stretched. HTML integrates data content and performance, modifiable, data can retrieval, and XML draws on the advantages of HTML and database, program language, and separates the content and performance, not only makes it more convenient, but also users. The exchange between data is more convenient, and it is more reusable. XML is a meta-marker language, without many fixed tags, providing greater flexibility for web developers. When we use HTML, the tag is just a simple representation of the display, and there is no association with the contents of the representation, which is extremely inconvenient for the further processing of the document. For example, to represent your resume, use HTML's representation as follows:
Name
禹 初 初
Gender
Male
Birthday
1977.5
Skill
Database Design and Maintenance, Web Development Table> Body> HTML> Here, we can't learn from tag th, TD know its content What is said, if you use XML, the corresponding document (file name: personal resume .xml) can write as follows: XML Version = "1.0" Encoding = "GB2312"?> 禹 初/ Name> Male sex> 1977.5 birthday> Database Design and Maintenance, Web Development Skill> Resume> Description: Version - This version is specified in the XML document, this It can only be 1.0; Encoding, which specifies the encoding type of the XML document, which is "GB2312", which is "Simplified Chinese". Compare two cases, using XML we can customize the mark, indicate the meaning of the content. In this way, when communicating the information on the Internet, it provides a great convenience with the computer processing document, and we will not be able to make a bulldy steering when you read the source file. However, since XML does not display the display mode, we will see that the XML document is displayed in a manner, such as a table. Can we display a document like HTML? The answer is negative.
Taking a personal resume as an example, you need to build a format file to explain the display mode of each tag, its contents are as follows (assuming file names resume.css): Resume {Display: block; font-size: 120 %;} SEX {Display: Block; Text-Indent: 2em} Birthday {Display: Block; Text-Indenter: 2em} Skill {Display: Block; Text-Indenter: The above CSS style, recommended reader reference The relevant information is familiar with CSS, and must be used in later learning, which is not introduced by the space relationship. After establishing the file resume.css, add the following text after the first line of the personal resume .XML file: Xml: stylesheet type = "text / css" href = "resume.css"?> Description: This is a referenced one External CSS style file, where TYPE specifies the style type (which can be TEXT / CSS or Text / XSL), HREF specifies the file path. Save the file and open the file in IE5.0. how about it? The format is somewhat different. It seems that it is not satisfactory, the content of the document is clear, but the display effect is much better than the document written by HTML, and the document written by XML can only display this way? ! Tip: 1. In order to better understand and master XML, it is recommended to be familiar with HTML 4.0 and CSS 2.0 grammar; master the JavaScript, Vbscript at least one; programming experience, understanding of database theory and SQL can make everyone learn XML Benefit. 2. The tiba in the XML document must be paired, if it is empty mark, there must be the end "/" of the same name tag, or use this kind of text to represent an empty tag. 3. XML and the XSL documentation will be introduced next week, the attribute value must be enclosed in double quotes (") or single quotes ('). 4. XML documentation must be a good structure (XSL document is also one of the XML documents), That is to say that the tag must have end tags, the tag can nearer but not cross, such as inner> outer> is legal, and the following form Outer> inner> is wrong. If the XML document is wrong, most of them violate the rules mentioned above. Trying to XSL (2) (Back Title) 2000-05-04 · 禹 希At the beginning of the first CPCWXSL, we talked to the CSS (laminated style sheet) to format the XML document. Its effect is not very satisfactory. In fact, CSS is used to format HTML tags, just because it is simply In the case, XML is just a data file in more, how to change it to the file like the HTML format we have seen in our daily? If we share the XML file than the structured raw material, then XSL is It is better than "sieve" with "mold", and the sieve is selected from the raw materials you need, and these raw materials are re-formed by the mold to form the final product: HTML.
This mold is roughly like this: We first design the page of the performance, and then get the data in the XML to fill the contents "digging", and then use the XSL statement from the related data from the XML to populate. One words: this XSL is actually a "shell" of HTML, XML data utilizes this "shell" to generate "traditional" HTML. XML is a tree structure when the XML is expanded. We refer to a custom tag in the tree structure as a node, and there is a father and son between the nodes. Layer enters. In the case of XSL, we have to be from the raw library? ? The relevant data is extracted in XML, and the mode query language provided by XSL is used. The so-called moderative query language is the specific statement of data from the XML through the related mode matching rule expressions, namely what we say "Sieve". Refer to Microsoft's "XSL Developer Guide", we can roughly divide the pattern language into three: select mode , , and test mode XSL: IF> and Matching Matches We now introduce them. First, select the mode selection mode statement to extract the data from the XML, is a simple acquisition of data, these tags have a select property, select the data of a specific node name in XML. 1, such as this in XML: Xiao Yu name> Chunhua Name> Qiushi Name> Author> We want to read these three author names, is it one by one to read the "Author / Name" method, have multiple such names? If there is a procedural statement to loop how good! I think that XSL provides such a programming language-based statement to read these three author names: ... <./xsl: 201ach> SELECT, As the name refer: Choose, it can select a specific unique tag in XML, or select a certain tag, we call it a set. Syntax: Property: 1. SELECT Inquiry the context according to the XSL style query to determine which type of node set (meet the SELECT condition) Style description. As a simplified representation, if you want to format the display method of a tag in the document, you can let the SELECT equal to the marked name of this element. For example, if you want to format the marker XML_mark, you can use it as follows: xsl: for-each> 2. Order-by Segmentation (;) separated as a list of sorting standards. Adding a plus number ( ) before the list element indicates that the contents of this tag are sorted as ascending order, and the reduction ration (-) represents the reverse sequence.
As a simplified representation, the sort standard list is the sequence of the marker specified by SELECT, and each tag is separated between (;). 2, mode is just selecting the node, and does not remove the value of the node. It is like the monkey just climbed to a branch of the tree, then use Let's pick "Victory Fruit"! Syntax: Value property of the node: SELECT is used to match the XSL model that matches the current context.
Simply put, if you want to insert an XML tag somewhere in the XSL document (assuming is the XML_Mark tag), you can use it as follows: xsl: value-of> Or example: As an example of a personal resume in the previous period, we need to make certain modifications to the file (personal resume .xml), exactly the first Two lines Xml: stylesheet type = "text / css" href = "resume.css"?> Modified to Xml: stylesheet type = "text / xsl" href = "resume.xsl"?> Then establish a new File: Resume.xsl, its contents are as follows: XML Version = "1.0" encoding = "GB2312"?> < HEAD> Personal resume title> head>
Personal resume caption>
Name th>
< / TD>
Gender TH>
td>
birthday th>
td> tr>
Skill th>
td> < / TR> table> xsl: for-energy> body> html> Complete these will let us look at the achievements of hard work, how? Good effect. More cool is still behind.
Now we make further modifications to files (personal resumes .xml): 1. Add a new tag before tag ; 2. Tag content between resume> (including this A pair of markers) copy and paste thereafter, and end in the last use of . 3. Open the file resume.xsl in Notepad.exe, add a text after tag : ; Add text before tag html>: xsl: for- Each>, save the file. 4. Open the file in the browser (personal resume .xml). What did you see? Two personal resumes! In this way, using XML we can write a document that is separated from the style! Of course, the XSL file is more complicated than a general HTML file, but once it is completed, it can be used to format all the same kind of XML document. Note: If you copy the code, please delete the space with me XSL (3) (Back Title) 2000-05-05 · 禹 希 初 · CPCWXSL Template and matching mode After the previous few days, we learned the writing of XHTML documents And three XSL elements, can write a fairly flexible XSL document, today will learn about the XSL template. We all know that short documents, the program is very good, but after the size increases, its complexity is also increased faster. We learned , , etc., you can use them to simply format the output for XML data, but if you encounter more complex XML format output, XSL follow request Write down, one is the difficulty of design, the scalability is poor, which is not conducive to the division of labor; the other, the modification is very poor, maybe the situation will move the army, which is not conducive to maintenance. The method of modular design in the program has been applied here! The XSL template refers to the design of XSL into a template (block), and finally combines these templates (blocks) into a complete XSL; it is better than ship and containers, we don't pile up all the goods, but Put these containers on the ship and then put these containers on the boat. This method allows you to consider the entire XSL design from the whole, then refine some of the forms into different modules, and then design these modules, and finally integrate them together, so that the macro is combined with micro. People have nature, standardize the requirements. Container? ? Writing template (block): syntax: Property: match - what kind of case is performed template.
As a simplified description, the name of the tag is used here; where the top layer template must set the match to "/" Language - determine what scripting language in this template, which is valued with the Script tag in HTML The value of the Language property is the same. The default is the JScript Use the Match property to select a node that satisfies the condition from XML, and the template for forming a specific output form for these specific nodes. Hanging boxing box -? ? Call Template (block): Syntax: Property: SELECT - Determine what template should be performed in this context environment, that is, the template (block) created with the tag.
Order-by ─ Sort by sequencing standard, usually a sequence of sub-tags: Taking personal resume as an example, for ease of handling each of our hopes "skills" to use tags to < / skill> How many skills are enclosed, how many skills have such a marker pair, and the modified personal resume XML document is as follows: XML Version = "1.0" encoding = "gb2312"?> xml: Stylesheet TYPE = "text / xsl" href = "resume_template.xsl"?> 初 初 name> male sex> 1977.5 birthday> Database Design and Maintenance Skill> Web Development Skill> resume> document> then create a new XSL file resume_template.xsl, using template form, its contents are as follows: XML Version = "1.0" Encoding = "GB2312"?> Personal resume title> head> body> html > Xsl: template>
Personal Resume ( Formatindex (ChildNumber (this), "I") xsl: eval>) CAPTION>
Skill TD>
Table>
Td> table> xsl: template>
Name TD>
td>
Gender TD>
td>
Birthday TD>
Td> xsl: template>
TD> < / TR> xsl: template> xsl: stylesheet> Save the file, open the file (personal resume .xml), the effect is satisfactory. In fact, we must do the same effect, and use the methods described in front of the previous three weeks, but you have to take it as a whole. In the above XSL file, we use data items such as gender, birthday, skills to write separately, and then call , so that even if you want to make a corresponding modification of these templates. The expansion is also very convenient, not in the case of interference, mixing, unclear. This kind of first, layer-by-layer refinement design method, greatly reduces the degree of complex work, and greatly reduces the generation of errors, and can achieve multiplayer collaborative design. Note: If the different markers of the same name in the XML document, when writing a template for it, the parent mark should be used as its prefix, the format is (PARENT_MARK / CHILD_MARK). The template file must have a root template whose property match is "/". Note: If you copy source code, remove the space with me XSL (4) (Back Title) 2000-05-06 · One of the advantages of XML technology in the CPCW test mode is the selectivity of the data output, That is, the required data output is selected. As we mentioned in front: , and just simple selection of nodes arriving through the "/" symbolic layer, if we There is no need for XML data, but only some of them meet some of the data, "radish green, take the required", then the condition judges and multi-conditioned judgment and catering this need, if you are familiar with the programming, you will feel that they have met.
The IF in XSL, first, introduce the syntax structure of the XSL element : Syntax: Property: Expr ─ Script language expression, the calculation result is "true" or "false"; if the result is "true", and via Test, it is displayed in the output (omitted this attribute). Language ─ The script language type of Expression in Expl attributes, with the value of the value of the Language property of the HTML tag Script, default is "JScript" TEST - source data test conditions.
Example: This is a report as an example, the file name is Report.xml, its contents are as follows: XML Version = "1.0" encoding = "gb2312"?> Xml: stylesheet type = "text / xsl" href = "Report.xsl"?> Jia class class> 50 q1> 70 q2> 30 q3> 10 q4> repert> B class class> 20 q1> 30 q2> 40 q3> 50 Q4> repeort> Class Class class 70 40 q2> 20 q3> 10 q4> report> document> We use the XSL template to combine today's , we write an XSL document, requiring the quarterly production to be less than 20, indicating that the file name is Report.xsl, the content is as follows : Xml version = "1.0" encoding = "gb2312"?> body> html> XSL: Template>
1999 Production statistics h3>
class tH>
one Quarter th>
th>
in the third quarter tH>
Four quarter tH> table> < / xsl: template>
td>
<
XSL: Apply-Templates SELECT = "Q1" /> td>
TD>
Td>
td> tr> xsl: template> Color: Red xsl: attribute> xsl: if> xsl: template> xsl: styleSheet> Description: Q1 | Q2 | Q3 | Q4 - Tags Q1, Q2, Q3, Q3 are used to determine the output $ Le $ - is "less than or equal" in the relational operator, and other relationships are less than ($ lt $), greater than ($ GT $), is greater than or equal to ($ GE $), equal to ($ EQ $), not equal to ($ NE $), etc. - Represents the current tag [] ── indicate filtering, only the tag that satisfies the filter criteria can be selected Value () ─ ─XSL function, other usual XSL functions have text (), end (), index (), etc. Next, we will learn the additional three elements of XSL to perform multiple times of testing the same data, and generate the corresponding output according to different conditions. Learn to XSL (5) (Back Title) 2000-05-07 · 禹 希 初 · CPCWXSL's Choose in CPCWXSL We learned the XSL element , can determine different output by testing the value of XML data. Form (I don't know if you try it, it is actually portable "XSL: for-each" can also partially implement the function of ), but sometimes we want to test multiple conditions for the same data simultaneously, and output corresponding results according to different conditions. . Of course, we can use if, if we only have IF available. Fortunately, we have a better choice, then use .
The grammar of the related element is described below: Syntax: Property: None, indicating a multi-select test start syntax: Properties: expr ─ script language expression, the calculation result is "true" or "false"; if the result is "true", and through Test, it is displayed in the output. (This property can be omitted). Language ─ The script language type of the expression in the expr property is the same as the value of the Language property of the HTML tag script, which is default to "JScript". TEST - Source data test conditions. Syntax: Properties: None, in a multi-selected test, if there is no condition that specified, if you finally have this tag, the content in this tag is output. . Example: This is here for the student transcript as an example, requires excellent (> 85), generally (70 ~ 85), starting (60 ~ 69), and does not show scores.
The XML document (file name: grade.xml) (file name: grade.xml) is as follows: XML version = "1.0" encoding = "gb2312"?> Xml: stylesheet type = "text / xsl" href = "grade.xsl" ?> Big fat name> 80 English>