Follow me. XSL (2) Introduction to XSL

Source: Internet
Author: User
Tags html tags tag name xsl

In the last period we talked about formatting XML documents with CSS (cascading style sheets), and the effect was not very satisfying. In fact, CSS is a good place to format HTML tags, just because it's simple to use in the example above.
XML is just a data file in more time, how can it be changed into the HTML format that we see everyday? If we compare an XML file to a structured raw material, then the XSL is like "sieve" and "die", and the sieve chooses the raw material that it needs, which then forms the final product through the mold: HTML.
The model is roughly the same: we first design the page of performance, then "Dig out" the part of the content that needs to be fetched from the XML, and then use the XSL statement to sift out the relevant data from the XML to populate it. A word to alarm: This XSL is actually a "shell" of HTML, which uses the "shells" to generate "traditional" HTML.
XML in the expansion is a tree structure, we will be in the tree structure of custom tags called nodes, there is a parent-child relationship between the nodes, we want to access the node from the root node to the "/" to the layer of entry.
In the XSL shell, we need to extract the relevant data from the raw Material library XML and use the modal query language provided by the XSL. The so-called modal query language is the specific statement that extracts data from XML through relevant pattern matching rule expressions, that is, the "sieve" mentioned above.

Referring to Microsoft's "XSL Developer's Guide", we can roughly divide the pattern language into three categories:

Select mode:
<xsl:for-each>, <xsl:value-of> and <xsl:apply-templates>

Test mode:
<xsl:if> and <xsl:when>

Match mode:
We are now going to introduce them separately.
First, the choice mode
The select-mode statement extracts data from XML as a simple way to get data, which has a select attribute that selects data from specific node names in the XML.
1, <xsl:for-each>
If you have such data in XML:
<name> Xiao Yu </name>
<name> Chun </name>
<name> Qiushi </name>
Are we going to read the names of these three authors, one by one, by the "Author/name" method, and can we have more than one name? If there is a procedural statement to iterate read how good Ah!
That's right, XSL provides such a program-language-like statement:<xsl:for-each>
The method used to read the names of these three authors is as follows:
<xsl:for-each select= "Author/name" >
Select, as the name suggests, selects, it can select a specific unique tag in the XML, or you can choose the same kind of tag, which we call the set of nodes.
<xsl:for-each select= "pattern" order-by= "sort-criteria-list" >
Use this style description to determine which type of node set (satisfies the select condition) based on the XSL style query context. As a simplified representation, you can make a select equal to the tag name of this element if you want to format the display of the content of one of the tags in the document. For example, to format a tag Xml_mark, you can represent it in the following way:
<xsl:for-each select= "Xml_mark" >
<!--style definition-->
a semicolon (;)-delimited list of sorting criteria. Adding a plus sign (+) before a list element means that the contents of this tag are sorted in ascending order, and a minus sign (-) is used to indicate the order of reverse orders. As a simplified representation, the sorting criteria list is a sequence of tokens that are specified by select, separated by (;) between each tag.

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: 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.