Template rules match the nodes in the Document Tree by using the mode. Mode specifies a set of conditions for selecting the nodes to be processed. The pattern matching syntax can be used not only in the match attribute of the <XSL: Template> element, but also in <XSL: Apply-templates>, <XSL: value-of>, <XSL: For-each>, <XSL: copy-of>, <XSL: Sort>, <XSL: Variable>, and <XSL: param> is used in select attributes of an element.
The following lists common usage of pattern matching:1. matching the root node, for example, <XSL: template match = "/">, indicates matching the root node. 2. Matching Element nodes, for example, <XSL: template match = "employees">, indicate matching employees element nodes. 3. Use a wildcard such as <XSL: template match = "*"> to match any element. 4. Use @ to add a number name to the @ matching attribute to match the attribute node. For example, <XSL: template match = "@ mode"> indicates that the node matches the mode attribute. However, when traversing the tree structure of a node, the XSLT processor does not process attribute nodes. If you want the processor to process attribute nodes, you must explicitly call the <XSL: Apply-templates> element and use the select attribute to select attribute nodes. You can also use @ with the asterisk (*). For example, <XSL: template match = "@ *"> matches any attribute node. 5. Use a slash (/) to match a subnode, for example, <XSL: template match = "employees/employee">, to match any employee subnode under the Employees element node. 6. Use a double slash (//) to match the child node. Sometimes, you want to process a type of element node, regardless of the node's position in the tree structure, you can use a double slash (//) to match nodes. For example, <XSL: template match = "// name"> matches any name element node under the root node regardless of the node location. For example, <XSL: template match = "employees/Name"> matches any name element node under the Employees element node. 7. Use or operator (|) to selectively match multiple nodes. For example, <XSL: template match = "name | age"> matches any name or age element node. Example: <XSL: template match = "Employee/name! Monthly_pay/@ mode ">: matches any name subnode under the employee element node or the mode attribute node of the monthly_pay element node. 8. The [] operator can be used to specify a Boolean expression in [] to match a node more accurately in the node set. For example, if you only want to match the first employee element, you can write <XSL: template match = "Employee [1]"> to match the first employee child element node. This is equivalent to the preceding statement: <XSL: template match = "Employee [position () = 1]"> position () is a function call, returns the current position of the node in the context and determines whether the position is equal to 1. 9. Use node () to match any node except the attribute node and the root node. Example: <XSL: template match = "Node ()">. 10. Use text () to match any text node. For example, <XSL: template match = "text ()">. 11. Use processing-instruction () to match the processing command processing-instruction () to represent any processing command nodes that match. For example, <XSL: tempate match = "processing-instruction ()">. Processing-instruction () can also contain a parameter used to specify the name of the Processing Instruction target. In this way, only the Processing Instruction with the same name can be matched. 12. Use comment () to match any comment node, for example, <XSL: template match = "comment ()">. 13. Using ID () to match an ID type property uniquely identifies an element in the XML document. For example, <XSL: template match = "ID ('e-100')"> indicates matching an element that has an ID type property and its value is equal to the E-2001320001. To work in this way, you must declare the ID type attribute in the DTD of the source XML document, which can be an internal or external DTD, if the source document does not have a DTD, the ID () function cannot work normally.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.