Learn XML and XSL with me

xiaoxiao2021-03-06  13

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 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: 禹 初/ Name> Male 1977.5 Database Design and Maintenance, Web Development 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: 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 is legal, and the following form 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 Chunhua Qiushi 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: 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: 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 Modified to Then establish a new File: Resume.xsl, its contents are as follows: < HEAD> Personal resume </ title> </ head> <body> <xsl: for-each select = "resume"> <p /> <table border = "1" cellspacing = "0"> <capension style = "Font-size: 150%; font-weight: bold"> Personal resume </ caption> <Tr> <TH> Name </ th> <TD> <XSL: value-of select = "name" /> < / TD> <TH> Gender </ TH> <TD> <xsl: value-of select = "sex" /> </ td> <TH> birthday </ th> <td> <xsl: value-of select = "BIRTHDAY" /> </ td> </ tr> <tr> <TH> Skill </ th> <TD colspan = "5"> <xsl: value-of select = "skill" /> </ 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.</p> <p>Now we make further modifications to files (personal resumes .xml): 1. Add a new tag <document> before tag <resume>; 2. Tag content between <resume> </ resume> (including this A pair of markers) copy and paste thereafter, and end in the last use of <document>. 3. Open the file resume.xsl in Notepad.exe, add a text after tag <HTML>: <xsl: for-each select = "document">; 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 <XSL: for-Each>, <XSL: Value-of>, 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): <xsl: template> <xsl: template> syntax: <xsl: template match = "node-context" language = "language-name"> Property: match - what kind of case is performed template.</p> <p>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 <XSL: Template> 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): <XSL: Apply-Templates> <xsl: Apply-Templates> Syntax: <XSL: Apply-Templates Select = "Pattern" ORDER-by = "Sort-criteria-list"> Property: SELECT - Determine what template should be performed in this context environment, that is, the template (block) created with the <XSL: Template> tag.</p> <p>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> < / 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"?> <document> <resume> <name> 初 初 </ name> <sex> male </ sex> <birthday> 1977.5 </ birthday> <Skill > Database Design and Maintenance </ Skill> <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"?> <Xsl: stylesheet xmlns: xsl = "http://www.w3.org/tr/wd-xsl"> <! - root template -> <XSL: Template Match = "/"> <html> <head> <title> Personal resume </ title> </ head> <body> <xsl: Apply-Templates Select = "Document / Resume" /> </ body> </ html > </ Xsl: template> <! - Resume Template -> <XSL: Template Match = "Resume"> <Table Border = "1" Cellspacing = "0"> <Caption> Personal Resume (<XSL: EVAL> Formatindex (ChildNumber (this), "I") </ xsl: eval>) </ CAPTION> <XSL: Apply-Templates Select = "Name" /> <xsl: Apply-Templates Select = "SEX" /> <XSL : Apply-Templates SELE CT = "birthday" /> <tr /> <TD> Skill </ TD> <TD Colspan = "5"> <Table Cellspacing = "0"> <XSL: Apply-Templates Select = "Skill" /> </ Table></p> <p></ Td> </ table> <br /> </ xsl: template> <! - Name Template -> <XSL: Template Match = "Name"> <TD> Name </ TD> <TD> <XSL : value-of /> </ td> <! - Gender Template -> <XSL: Template Match = "SEX"> <TD> Gender </ TD> <TD> <XSL: Value -of /> </ td> <! - Birthday Template -> <XSL: Template Match = "Birthday"> <TD> Birthday </ TD> <TD> <XSL: Value-of /> </ Td> </ xsl: template> <! - Skill Template -> <XSL: Template Match = "Skill"> <TR> <TD> <XSL: Value-of /> </ 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 <XSL: Apply-Template>, 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: <xsl: for-each>, <xsl: value-of> and <xsl: Apply-Template> 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 <XSL: IF> and multi-conditioned judgment <xsl: choose> and <XSL : when> catering this need, if you are familiar with the programming, you will feel that they have met.</p> <p>The IF in XSL, first, introduce the syntax structure of the XSL element <xsl: if>: <xsl: if> Syntax: <xsl: if expr = "script-expression" language = "language-name" test = "pattern"> 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.</p> <p>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"?> <document> <report> <class> Jia class </ class> <q1> 50 </ q1> <q2> 70 </ q2> <q3> 30 </ q3> <q4> 10 </ q4> </ repert> <report> <class> B class </ class> <q1> 20 </ q1> <q2> 30 </ q2> <q3> 40 </ q3> <q4> 50 </ Q4> </ repeort> <report> <class> Class Class </ class <q1> 70 <q1> <q2> 40 </ q2> <q3> 20 </ q3> <q4> 10 </ q4> </ report> </ document> We use the XSL template to combine today's <XSL: if>, 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"?> <Xsl: stylesheet xmlns: xsl = "http://www.w3.org/tr/wd-xsl"> <xsl: template match = "/ <HTML> <head> <title> 1999 Production statistics </ title> </ head> <body> <xsl: Apply-templates select = "Document;" /> </ body> </ html> </ XSL: Template> <XSL: Template Match = "Document"> <h3> 1999 Production statistics </ h3> <table border = "1" cellspacing = "0"> <tH> class </ tH> <TH> one Quarter </ th> <th> </ th> <th> in the third quarter </ tH> <th> Four quarter </ tH> <XSL: Apply-Templates Select = "Report" /> </ table> < / xsl: template> <xsl: template match = "report"> <tr> <TD> <XSL: Value-of SEL ECT = "class" /> </ td> <td> <</p> <p>XSL: Apply-Templates SELECT = "Q1" /> </ td> <TD> <XSL: Apply-Templates SELECT = "Q2" /> </ TD> <TD> <XSL: Apply-Templates SELECT = "Q3" /> </ Td> <td> <xsl: Apply-templates select = "q4" /> </ td> </ tr> </ xsl: template> <xsl: template match = "Q1 | Q2 | Q3 | Q4 "> <! - This is tested here, such as less than or equal to 20, add a Style attribute color, its value is RED (red) -> <xsl: if test =". [Value () $ 15] " > <Xsl: attribute name = "style"> Color: Red </ xsl: attribute> </ xsl: if> <xsl: value-of /> </ 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 <xsl: if>, 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 <XSL: if>), 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 <xsl: choose>.</p> <p>The grammar of the related element is described below: <XSL: Choose> Syntax: <XSL: Choose> Property: None, indicating a multi-select test start <xsl: when> syntax: <xsl: when expr = "script-expness" language = "Language-Name" test = "pattern"> 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. <Xsl: OtherWise> Syntax: <XSL: OtherWise> Properties: None, in a multi-selected test, if there is no condition that <xsl: when> 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.</p> <p>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" ?> <Document> <grade> <name> Big fat </ name> <English> 80 </ English> <math> 90 </ math> <crymest> 90 </ chymest> </ grade> <grade> <name > Small Flower </ Name> <English> 98 </ English> <Math> 70 </ Math> <crymest> 85 </ love> </ grade> </ document> To implement the score level display, its XSL document ( File name: grade.xsl) The content is as follows: <? XML Version = "1.0" encoding = "GB2312"?> <Xsl: stylesheet xmlns: xsl = "http://www.w3.org/tr/wd-xsl" > <XSL: Template Match = "/"> <html> <head> <title> transcript </ title> </ head> <body> <xsl: Apply-templates select = "document" /> </ body> </ Html> </ xsl: template> <xsl: template match = "document"> <table border = "1" cellspacing = "0"> <tH> Name </ tH> <TH> English </ tH> < TH> Mathematics </ TH> <TH> Chemical </ TH> <XSL: Apply-Templates Select = "grade" /> </ table> </ xsl: template> <xsl: template match = "grade"> <TR > <TD> <XSL: Apply-Templates SELECT = "Name" /> </ td> <TD> <XSL: Apply-Templates Select = "English" /> </ td> < TD> <XSL: Apply-Templates SELECT = "Math" /> </ td> <td> <xsl: Apply-Templates Select = "Chymest" /> <</p> <p>/ TD> </ tr> </ xsl: template> <xsl: template match = "name"> <xsl: value-of /> </ xsl: template> <xsl: template match = "English | math | chymest" > <Xsl: choose> <xsl: when test = ". [Value () $ GT $ 85]"> Excellent </ XSL: WHEN> <XSL: WHEN TEST = ". [Value () $ GT $ 70]" > General </ xsl: by> <xsl: when test = ". [Value () $ gt $ 60]> Sutra </ xsl: by> <xsl: OtherWise> Can't stand </ xsl: Otherwise> < / xsl: choose> </ xsl: template> </ xsl: stylesheet> Description: In <XSL: Choose> Select, start from the first <xsl: when>, test it one by one until a test condition will be met. The content output is no longer tested; if you do not satisfy any of the conditions, you will output the contents of <XSL: OtherWise>. Mark <XSL: WHEN> </ xsl: by> and <XSL: OtherWise> <XSL: if> or <xsl: choose>. Note: If copying source code, please delete the space to learn XSL (six) (return heading) 2000-05-08 · 禹 初 初 · CPCW operator, relationship and logical operator, special character, etc. we learn XSL Various operators meet the requirements of the XSL style prepared to write greater flexibility.</p> <p>Table 1. The operator describes the / select sub-elements and returns the direct child elements of the left element; if "/" is located at the left side to indicate the direct child element // recursive decrease in the selective root node, regardless of the depth, Search for specified elements; if you are in the left side, you will be recursively designed from the root node. Representation of the current element * wildcard, select any element, does not consider the name @ acquisition attribute value, as the prefix of the property name @ * wildcard, select Arbitrary properties, regardless of the name: Name scope separator, separate the name scope prefix with the element or attribute name! * Apply a specified method () * group on related nodes, clearly specify priority [] Apply filter style [] * Subscript operator, used to indicate element tables in the collection, logical operator comparison operator Option mode Description AND $ or logic with or $ or || Logic or NOT () $ not $ Logic Non-Table III, Relational Operators = $ EQ $ Equal = $ IEQ $ Equality (Not Case Size)! = $ NE $ 不 $ INE $ 不 不 不 不 ((Not Case) <$ lt $ 小 less than $ ILT $ Small than (not case sensitive) <= $ = $ less than equals $ ILE $ less than or equal to (not case sensitive)> $ GT $ greater than $ IGT $ greater than (not case sensitive)> = GE $ greater than equivalent $ IGE $ IGE $ Greater than or equal to (not case sensitive) $ all $ collection operator, return "true" $ ANY $ collect operator if all items in the collection meet the conditions, return "true" | collection operation if any project meets the criteria in the collection The inquiry, returning two sets of joint example 1: Find the name and E-mail of the person with the "Web Development" skills from the personal resume.</p> <p>Suppose the document structure is as follows: <document> <resume> <name> name </ name> <sex> sex </ sex> <birthday> birthday </ birthday> <skill> skill1 </ skill> <skill> skill2 < / Skill2> ... <Skill> Skilln </ Skill> </ resume> <resume> ... </ resume> ... </ document> Find all the name of the "Web Development" skill from the personal resume from the above structure The XSL document structure with e-mail is as follows: <table border = "1" cellspacing = "0"> <tH> Name </ th> <th> e-mail </ t> <xsl: for-each select = " Resume [$ ANY $ SKILL = 'Web Developer "> <TR> <TD> <XSL: Value-of SELECT =" Name "/> </ td> <td> <xsl: value-of select =" -Mail "/> </ td> </ tr> </ xsl: for-each> </ table> Description: 1. [] ─ ─ Represents the selection condition, only personal resume satisfying the condition is displayed; 2. $ Any $ - Since everyone has a variety of skills, add $ any $ as a prefix so that everyone's skills can be compared; 3.Skill = 'web development' - Filter Condition Example 2, still above The XML document is an example. If you want to choose from 1977/1/1, the name, skill and e-mail born before, the corresponding XSL document structure is as follows (assuming birthday format YYYY / MM / DD): <table border = "1 "CELLSPACING =" 0 "> <TH> Name </ th> <TH> Skill </ th> <th> e-mail </ th> <xsl: for-each select =" resume [Birthday $ lt $ '1977 / 1/1 ']> <tr> <td> <xsl: value-of select = "name" /> </ td> <td> <xsl: value-of select = "Skill [0]" /> <Xsl: for-each select = "SKIL l [index ()> 0] ">, <xsl: value-of select =". "/> </ xsl: for-each> </ td> <td> <xsl: value-of select =" E- Mail "/> </ td> </ tr> <</p> <p>/ xsl: for-each> </ table> Description: 1. Birthday $ lt $ '1977/1/1' - Search Conditions, use "<" to be wrong here, so use "$ lt $" to indicate less than . 2. Skill [0] ─ Represents the first item of Skill 3. Skill [index ()> 0] ─ item representing the second item (including second item) after Skill 4. XSL: Value -of select = "." ─ ─ ─ 选择 选择 选择 大 大 大 大,, in the previous and this example, some functions appear, such as index (), formatindex (), childnumber (), maybe everyone Not completely all of them? Please pay attention to the next lesson. Note: If you copy the source code, remove the space with me XSL (7) (Return Title) 2000-05-09 · 禹 初 初 · CPCWXSL function A period of learning XSL style method, that is, XSL element <xsl : for-each>, <xsl: value-of>, <xsl: template>, "" XSL: Apply-Templates> Match property, <XSL: if>, <xsl: when> TEST attribute, Filter the range of elements to provide greater flexibility. The XML is the same as DHTML (dynamic HTML), and these nodes are objects, and these objects are hierarchical, and the root node begins constitutes a hierarchical tree structure, which forms a document object model DOM. Through the properties of the object, the method reaches the purpose of the access control XML node. We don't intend to explain in detail one by one here, because this can be written into a more than one tutorial, we will discuss some common methods first, in order to have a general understanding of the object method of the DOM. Note: From this issue, all examples no longer provide complete source code. If you don't understand, please read the seven phases in front of the previous group and do it. First, End () Meaning: Returns the last element in the collection.</p> <p>Example: Output The last resume is assumed that the XML file format is: ... <resume> ... </ resume> ... <resume> ... </ resume> ... The corresponding XSL file content is: <xsl: for-each select = " Resume [end ()]> ... </ xsl: for-each> or <xsl: templates match = "resume [end ()]> ... </ xsl: templates> or <xsl: Apply-Template Select SELECT = "Resume [end ()"> ...... </ xsl: Apply-Template> II. Index () meaning: Returns the location of the element in the collection, the return value is an integer, where the first element returns 0 example : Return to the previous three resumes [index () $ 1: INDEX () is related to the parent element, see the case: <x> <y /> <y /> </ x> <x > <Y /> <y /> </ x> Returns the first <y> x / y [index () = 0] or x / y [0] in <x>, nodeName () meaning: Returns the name of the element, that is, the marker name: select any element, if its name (ie, the tagname) is equal to "name" * [nodename () = 'name'] or * [name] four, Number () meaning: Convert to a numerical form, if not a value, return empty, required parameters example: age (agn) Resume (AGE) RESUME [Number (AGE) $ LT $ 30] or Resume [Age $ LT $ 30] 5. Nodetype () Meaning: Return the node type, the result is a value.</p> <p>The following is the return value in the list: the form of characters node type node type nodes which are described Element 1 'element' Element Attribute 2 'attribute' Markup-Delimited Region of Text 3 'text' Processing Instruction 7 'processing_instruction' Comment 8 'comment 'Document Entity 9' Document '6, Value () Meaning: Returns the value of the element or attribute: value () is the default method of the element or attribute, the following representation is the equivalent Name! Value () = "name" with Name = "Name" @ attr = "attribute_value" with @ attr = "attribute_value" Note: @ is the attribute prefix, @ Attr Representation is attribute Attr Seven, Attribute () meaning: Return to all attribute nodes, equivalent "@ * "Sample: Find all the resume elements, meet the value of at least one attribute" ABC "Resume [$ any $ attribute () = 'abc'] or resume [$ @ * = 'ABC'] Looking for all The resume element, satisfying the condition at least one child element having a property of "ABC" Resume [$ any $ * / attribute () = 'abc'] or resume [$ any $ * / @ * = 'ABC'] Eight, Comment () Meaning: Returns all comments NOTE example: For example, Resume [$ any $ comment () = '禹 初 初 初 初 初'】 Looking for the comment statement <! - 禹 初 初 初 初 初 -> Element <Resume> Nine, CDATA () Meaning: Returns a collection of nodes of all CDATA types: For example, Resume [$ any $ cdata () = '禹 希 初 的 简 的'] means looking for the following statement (must be directly Sub Node) <! [CDATA [禹 初 初 初]]]]]]]]] 十::::::: 集 集 集 集 集 集 集 集 集 集 集 集 集 集 集 集 集 集 集 集 集Example: "* | PI () | Comment () | text () example: Find all Elements Resume, the name of its last node is" Skill "Resume [Node () [end ()]! Nodename () = 'Skill'] Find the first node of all Resume elements: resume / node () [0] 10 I. TEXTNODE () Meaning: Returns a collection of nodes of all text types: Looking for the second text node p / textnode (1) or P! TextNode (1) twelve, text () meaning : Returns a collection of nodes indicating the text string, equivalent to "CDATA () | textNode ()"; this issue is introduced, another function Date () is in my machine. The error enables the browser to shut down, and a function PI () I have not found an appropriate application method, and I will not introduce it, and the script will be used in XSL under XSL.</p> <p>With me XSL (8) (Back Title) 2000-05-10 · Ji Ji · CPCW Script and XSL's combination and application Sometimes, we may want the XML document to be output to add some statistics or What is numbered, it is not easy to achieve with the previous knowledge. Today will introduce two new elements <XSL: Eval> and <XSL: Script> so that we can easily handle this problem. <Xsl: evAl> meaning: Calculate script expressions, output a text string syntax: <xsl: evan, = "Language-name"> Property: Language ─ ─ ─ ─ ─ The name of the scripting language used, available attributes have "javascript" , "JScript", "VBScript", "VBS", etc., default is "jscript". <XSL: Script> Meaning: Declare global variables or definition functions. Syntax: <xsl: script language = "language-name"> Properties: Example with <xsl: evAl>: I don't know if you have an impression on the example of the fourth issue of "XML" with me. The XML document does not have a resume number, but the output has a larger number of Rome digital serial numbers. Today, I will give a slightly complex example: If we write a year-end production statistics, there is a small meter, the routine method is to calculate it in advance, do not have to be, we can only give only single statistics, A small count is statistics when it is displayed.</p> <p>Please find out the fifth phase of "learning XML", the XML file does not have to be modified, the modification of the XSL file is as follows: ... <xsl: template match = "document"> ...... <xsl: Apply-templates select = "report "/> <TR> <TD> Small Meter </ TD> <TD> <XSL: Eval> Total (this," Q1 ") </ xsl: eval> </ td> <TD> <XSL: Eval> Total (this, "q2") </ xsl: eval> </ td> <td> <xsl: evAl> Total (this, "q3") </ xsl: eval> </ td> <TD> <XSL: EVAL > Total (this, "Q4") </ xsl: evAl> </ td> </ tr> </ table> <xsl: script> function total (node, q) {temp = 0; Mark = '/ Document / Report / ' q; v = node.selectnodes (mark); for (t = v.nextnode (); t; t = v.nextnode ()) {TEMP = Number (T.Text);} Return Temp; / Small count value} </ xsl: script> </ xsl: template> Description: The black body portion is added, pay attention to the addition section is divided into two parts, <XSL: Script> </ XSL: Script> must be placed in </ table Afterward, remember. SelectNodes () ─ is a method of XMLDomobject, returning all the collections of all the nodes satisfied in the document, the value and <xsl: for-each> and SELECT attributes use the same way, you can add filter, subscript, etc. Limit, such as: Search for a quarter production greater than or equal to 50, Document / Report / Q1 [Value () $ GE $ 50] The above is more simple to write // q1 [value () $ GE $ 50] / / Indicates that all nodes are traversed from the root node, find the node that meets the conditions, if there is a different name in the document, but the node is different, it cannot be used, and it is not recommended. Take this as an example, if you want to count the total output of the statistics, you can find a summary of the string (recommended for the last one, this description will accurately find data required to summarize) // * [value () $ GT $ 0 ] Or // (Q1 | Q2 | Q3 | Q4) or / Document / Report / (Q1 | Q2 | Q3 | Q4) NextNode () - Returns the next number () in the node concentration Number () Parameter Conversion To the value of the XSL function 2, use in <XSL: Script> and <XSL: EVAL>, and <XSL: if> and <xsl: when> EXPR properties. It is recommended that readers are familiar with at least one of JavaScript, JScript, VBScript, and if you can use XSL's work will be very limited. Due to the relationship, this is not described in detail.</p> <p>Note: If copying source code, remove the space to XLINK introduction 2000-03-02 · Cai Yizi Translation · Chinese XML If each of the data in this world can be identified, the address and link, that will be What kind of exciting thing! Xink is how to do this specification file on the web. HTML's linkage due to WWW's popularity, most of the people are familiar with the basic concept of hyperbraps, which is "a link with two endpoints and one direction, two endpoints we are usually called Anchor. This link can be from one starting point Even the target point of any network resource, these links may be a picture, a volume of film, a sound, a program, an HTML file, or the elements, etc. If you often use a browser, you will know that when you press the right button on the junction, a menu will appear, and one of them is "On the new window". In HTML, it is made of these links with a "Anchor" flag. If you are a master writing HTML, you must know that there is a special sign in the Head sign called Link, which provides a variety of linkages: Compared to the way to link to the style sheet (new browser will provide more than one Select, let it choose which style sheet to use), or connect to a place with music (playback can be automatically played after downloading), or connect to another web page (allowing the browser to preload the page in advance, Take the time to wait for time), etc. The above described above is the function, in fact, there are many other hypertext linkages that have no way HTML, even if the hypercanic linking system provided by the early (late 1960-1970) HTML has no way. However, HTML will succeed because it uses the easiest way to use the ultra-connected knot, and the user can make a web page. Multi-purpose link! Sometimes we see "link", we find that it looks not like a link, but in fact, why? Many things include electronic addresses, identification words, location, or queries, etc., all can have this action. When you think of the relationship between "Relationship", "ROLE", "Pointer" or "HAS A", there are "HAS A", or "HAS A", which can be labeled in XML (ExtensibleMarkUplanguage). Readers should have a concept. In HTML4.0, the defined hypertext linkage is not all of the features, so we will make a clearer definition for connectivity: 1. One link can have one Two or even many ends, and each end can be an indicator, in fact, the connection itself can be clearly specified as an external (External "connection, thus being connected to each end. 2. A link does not have to have a direction, but it can also have a lot or no direction, in addition to this, the direction of the connection should not be from "context" to "part". 3. The connected end can be a range, not necessarily to connect to the entire resource or place. 4. Connect the expression of the node is the role of the joint, "capturing" and "replacing" are only one of the possible behaviors. Therefore, the user setting is one of the performances of the connection between the user settings and replaces the screen.</p> <p>What is the use of XML link? In short, it can be used in the data type of data modeling, data exchange, hyperbraplen linking, or any different relationships. XLINKS has an important function to build "TopicMaps", which is a way to connect to various different network resources based on Metadata. TopicMaps allows different materials to have an external annotation. Therefore, we can say that TopicMaps are structural Metadata, which can be connected to different network resources based on all characteristic associated topics. XLINKSXLINK defines several commonly used linkages: Simple, Extended, Group, and Document. 1. Simple usage is close to the usage of the HTML within the A logo (shown below the HTML writing). 2.Extended usage contains elements of ARC and Locator and allows various types of expansion links. 3. The usage of GROUP and Document is to link the group to some special files. Here we will explain the syntax of the Simple, there are two ways to know if a link is XLINK: 1. Use the Simple word directly; 2. Expressed in XLink: Type. Let's take a look at the example below: 1. HTML is written as follows: 2. Writing with XLINK: the same link, another XLINK can also be written: XMLns: XLINK attribute is a name domain (Namespaces) announced Example, and so-called name domain, it is to facilitate the use of several file type declaration (Document TypeDeclaration). As for this approach, we believe in the future HTML versions will also work in this direction. Maybe we feel very strange, why will these ARCs will be connected together, but forming ExtendedLink? Some people may prefer (Figure 2), because this link does not "from" and "to", only HREF's address. Two originalities are included in the definition of Locator: HREF and ROLE. The HREF property contains the URL, and the Role property contains how to use the keywords. XLINK extends the use of URIS, where activuate and show are very important for XLINK, why: 1.Actuate's property can explain that Link is an Automatic or Man-Command tracking. 2. The attribute of SHOW means that the connection of the other end is to display a new window, or replace into the current window, or to analyze (if the link is coupled to the XML file). For HTML masters, the usage of the above HREF attribute is not usually because of the correct URL containing query conditions, and its main purpose is to query files. This URL uses a very special syntax, which is to ask questions (?) Before the URL is queried, and many of the links to the database use this skill. XPointer, which is developed in development, is a special query and a part of XLink. XPointer's grammar is? XPtr = plus XML PatHexpression [like ID (phone2)]. From the above example, the ID refers to the only identifier phone2. (This is the same as the usage of XLINK: ARC's from and To).</p> <p>XMLPATHEXPRESSION allows us to choose a special branch of ElementTreeOfstructure Data in different types. Author Blog:</p> <p>http://blog.9cbs.neet/myali88/</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-50695.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="50695" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.047</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'O24u_2F2rQYF5jgh0NQTEjykISjEd78vHixu8I2kdI6SMDk53OfdesxtZEPj6DLtaR_2F6QJ_2FHKvk_2BOaG6eIcJGBHA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>