首页 > 代码库 > XSLT工作原理

XSLT工作原理

1、XSL processing flow

clip_image001

An XML document and an XSL stylesheet are input to the XSL processor. Let‘s look at the steps in Figure 1 in more detail:

  1. Match template patterns. As the XML document content is accessed (element by element), the match attribute for each template rule is compared against that portion (element and its children) of the XML document. The XSL processor accesses the XML document from top to bottom, so the matching process is sequential.
  2. Determine correct template. The XSL processor selects a template rule pattern that matches the XML document. The pattern for a match attribute can be very concise, specifying the path to a particular element or a particular attribute, or more general, allowing matches to any occurrence of an element or attribute within the XML document regardless of its parentage. The determination process takes these factors into account.
  3. Create results for output. The XSL processor deals with the template rule. Depending upon the rule body data, the literal data, XML document content, or both may be put into the output stream or other actions can take place. A result tree is created containing the results of the rule processing. As each rule is processed, information may be added to the results tree.
  4. Any more templates? After checking other templates that need to be processed, the XSL processor continues processing or outputs the results tree and ends the execution.

2、微软MSXML解析器的工作机制:

 

clip_image002

 

3、Diagram of the basic elements and process flow of Extensible Stylesheet Language Transformations.

clip_image003