In order to understand XSLT programming, you must first understand XML, because Xslt is not just responsible for converting XML and it is still a full-meaning XML standard language. In theory, you can write the XSLT style form responsible for your own format conversion. Of course, this is a full thing, just nothing.
Let us recall, XML is not a common language, XML is a metalanguage, which is the structure of the XML specification language (such as XSL and XHTML are XML specification languages). HTML looks very like XML, but actually violates some XML rules.
The XML language defines a label used to mark the data as an element (or can say node). For example, in terms of XHTML syntax, the
tag is equal to the start to mark a particular XML node. The XML node can contain attributes and contents. The property is the name / value pair consisting of strings. The contents can be a string and / or more XML node. This means that XML is a hierarchical structure that can represent a very complex data format. We may wish to consider one of the following XHTML fragments:
Hello World! Td>
td> tr> table >
In the above code segments, each node has its own open-closed tag, between the two tags and the text string. The IMG node has an SRC attribute without content, next to the label is a termination slope. This termination slope and text are nested in the
node, and the latter is nested in the
node. It is obvious that
nodes are nest in
.
The core idea of XSLT is to establish context environments, which is also a formatted data version that exists in this environment in a specific node or complete set of nodes in the XML document. To this end, the XSLT style form is broken down into discrete template, each template being responsible for processing a type of tag in the XML document. In these templates, XSLT is to be used, transmit parameters, cyclic conditions, and other elements of converting XML.
Element is the outermost element of any XSLT style form, you want to specify the version and one or more namespaces (Namespace): < / XSL: Template>
The XSLT processor will perform after discovering an explicit call in the style form or finding the matching node in the source XML document. The most common situation is that the matching node is encountered when the XSLT processor scans XML. Matching properties use the node taken in the template with the XPath expression. Activated element outputs the content it needs. These contents may be composed of text and non-xslt tags and written directly to a new document or more XSLT elements, which are executed in the context environment of matching nodes. Tracking the context environment is impossible. The XSLT element only processes the similar nodes activated by the template.
Multiple templates can match a node. In this case, the complex rules of mode and priority attributes determine which template should be processed to process nodes. The simplest style form contains only a template that matches the given node.
For those XML documents that mainly include tag text (such as HTML), your XSLT style form is likely to contain a template for each tag you can encounter. For the XML document that contains highly structured hierarchy, your style may only contain templates for top-level nodes. These templates know the structure of the data and directly access the child node instead of jump to other templates.
For example, the sample XML file contains a shorter tag book data. It consists of a node, which includes and multiple nodes. This template will perform each node within the top node:
this is chapter , entitled " Stuff happensthis is chapter 1, Entitled "How it begins" this is chapter 2, Entitled "What Transpires "this is chapter 3, Entitled" Where it ends "
Obviously, the node is ignored because their The parent node is processed, but the first is not in so simply prints things.