What's the use of XSLT?

Source: Internet
Author: User
Tags format object javascript extension xpath xsl xslt access
Adun asked me today what the use of XSLT really is. There is a need for it to exist relative to other technologies.
The main function of XSLT is the transformation of the XML structure, which is a language that describes the rules of structure transformation. But you can also compare it to the template language that we are more familiar with for generating HTML (structs).
1. Both can be directly generated in XML format text (structure)
2. Both have loops and judgments and other logical processing statements.
3. The template language can obtain source data in languages such as El expressions, and XSLT obtains source data through XPath syntax.
4. Template language through the custom tag and other mechanisms to achieve decomposition and combination, XSLT through xsl:call-template and other syntax to achieve decomposition and combination.

The template language such as TPL directly manipulates the objects in Java, which embodies the graph model and encapsulates some of the dynamics through object functions. General visits are done through short-range relationships, such as X.y.funca (). B. With the Apache project group's Jxpath package, we can also use XPath-like syntax for global access on the object graph.
XSLT accesses the tree structure using strictly defined XPath syntax, and has strong data manipulation capabilities, such as we can easily implement the aggregation of nodes through syntax such as//mynode, and construct new structures. In the implementation of the general XSLT package, a JavaScript extension is provided, which can be constructed using JavaScript as a data node.

In a template language such as TPL, the structure of the data object in Java is two points from the template structure in the TPL (the structure of the processing rule), whereas the body that enters the data structure in XSLT with the rules that the XSLT itself processes is unified. In fact, the template language such as TPL is mainly based on process semantics, that is, doing first ... , used to ... And then... , and XSLT has a clear global assumption of the structure of the input data, primarily a conversion semantics, that is, whenever you encounter ... , just do .... In XSLT, you can specify the trigger conditions for the processing rule for data (input structure) through XPath syntax, whereas in the TPL you can specify a converter for the TPL label only through , but not the processing rule for the data.

In the aspect of data access model, XSLT and template language have advantages in principle. In fact, in the process of HTML generation, the global access and matching ability of XPath is difficult to be played, and the restriction of XML format hinders the use of flexible data supply to some extent, which has some advantages in template language. However, XSLT is more restrictive and inherently beneficial, it uses XML data and outputs XML data, maintains the homogeneity of the structure and facilitates pipeline operation. Because the assumption is more explicit, XSLT's ability to manipulate and encapsulate XML-formatted data is stronger than the template language. For example, it can be used to append properties to a node.

One of the main disadvantages of XSLT when it comes to XHTML generation is that it is a description of the decomposition of the transformation rules, and what we want is the final result, which is the result of the combined application of these rules. Although the syntax of XSLT is an XML language, it is consistent with XHTML in syntactic format. But in XSLT, the tags of XSLT destroy the semantic structure of XHTML, making it impossible to do what you see now. We have to run the XSLT rules in our minds to imagine the end result, which is painful indeed. The template language is much easier in this regard.

Another problem with XSLT is that sometimes XML syntax seems too verbose. When manipulating some local structures, XML nodes are not necessarily appropriate expressions. For example

contrast ${x},




Contrast

In terms of calling a child template, it is clear that the abstraction level of the XSLT encapsulation is also weaker than the TPL template language.


XSLT, as an XML-formatted structural transformation language, maintains the conceptual integrity of the XML world, and its significance is undoubtedly significant. But not all of the time XML is the optimal description model. We'd better use it in conjunction with other technologies. Currently, in the Witrx platform, our use of XSLT is primarily to layout and filter the TPL template, that is, XSLT is used to transform processing rules, and the most meticulous work of generating HTML based on data is left to a TPL template language that is more capable of process and encapsulation.



Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.