XSL study notes are transferred from Bamboo Shoots

Source: Internet
Author: User
Tags case statement xsl xsl file xslt
XSL Study Notes (1)

Some people say that XSL is the replacement of CSS. Is it true?

1. Introduction
XSL is a language that describes style sheets, including XSLT, XPath, and XML format objects.
Unlike HTML, XML does not have predefined labels, so Browsers Do not know how to display XML documents, while XSL is used outside XML to show how to display.

2. XSLT
XSLT is a language that converts an XML document to another format. XML uses XSLT to convert the source XML tree to the result XML tree.

3. browser differences
Together with IE6, The MSXML parser fully supports javast1.0 and xpath1.0, and netscape6 does not fully support XSL (What about ns7 ?)

4. XSL style sheets
An XSL file is also an XML file, so the first line should also declare XML:

<? XML version = "1.0" encoding = "ISO-8859-1"?>

In the second line of the XSL Declaration, the following statement is completely consistent: <XSL: stylesheet version = "1.0"
Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">

And

<XSL: Transform version = "1.0"
Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">

When using the namespace above, you must have a description of version = "1.0.
ViewColumnExampleChild: XML file, XSL file, XML + XSL.

5. <XSL: Template> element
The XSL style sheet is composed of templates. Each template is a set of rules.
The match attribute of the template to associate the template with the elements in XML. For example, match = "/" associates the template with the XML root.

6. <XSL: value-of> Elements
This element is used to obtain the value of the selected XML node.
Select a node based on its select attribute. The select value is an XPATH expression. The XPath expression is very similar to the multi-level directory writing in * nix system. For example, "breakfast_menu/food.

7. <XSL: For-each> element
Complete the cyclic action in XSL. The select attribute is described in Section 6.
This element can be used for simple filtering, for example:

<XSL: For-each select = "catalog/CD [artist = 'Bob dylan']">

It can be used to find Bob Dylan's CD files. XSL defines four comparison operators: = ,! =, & Lt, & gt, two comparisons can be connected by and or.

8. <XSL: Sort> Elements
To sort the output, you only need to put it within <XSL: For-each> and use select to specify the comparison element.

9. <XSL: If> element
When the specified conditions are met, the <XSL: If> template will be used. The definition of the condition is indicated by its test attribute, and its operator is the same as 7.
Generally, <XSL: If> appears in <XSL: For-each>.

10. <XSL: Choose>, <XSL: When>, and <XSL: otherwise> Elements
These three conditions are combined to achieve multi-Condition Selection, similar to the case statement in C language. Example:

<XSL: Choose>
<XSL: When test = "Price & gt; 10">
... Some code...
</XSL: When>
<XSL: otherwise>
... Some code ....
</XSL: otherwise>
</XSL: Choose>

10. <XSL: Apply-templates> element
Use a template rule for the current element and its child elements, such as the delivery function in C, which implies the function of loop. Use the select attribute to specify the element. Match is used to determine what elements are sent from the template. From this point, the template is like an overloaded function in C ++.

11. XSL on the client
When we open an XML file that references XSL in a browser, the browser converts XML to XHTML before display.ConcealedAction.
This action can be explicitly completed using JavaScript on IE, provided that XML does not contain references to XSL.CodeAs follows:

<SCRIPT type = "text/JavaScript">
VaR xml = new activexobject ("Microsoft. xmldom ")
XML. async = false
XML. Load ("cdcatalog. xml ")
VaR XSL = new activexobject ("Microsoft. xmldom ")
XSL. async = false
XSL. Load ("cdcatalog. XSL ")
Document. Write (XML. transformnode (XSL ))
</SCRIPT>

12. XSL on the server side
For IIS, XML conversion can be easily implemented on the server side. As follows: <%
Set xml = server. Createobject ("Microsoft. xmldom ")
XML. async = false
XML. Load (server. mappath ("cdcatalog. xml "))
Set XSL = server. Createobject ("Microsoft. xmldom ")
XSL. async = false
XSL. Load (server. mappath ("cdcatalog. XSL "))
Response. Write (XML. transformnode (XSL ))
%>

What about other types of servers?

The above is just the basic content, and advanced learning is behind it. :)
The main reason is that the elements are not comprehensive, and the XSL functions are not.
Http://www.w3schools.com/xsl/xsl_w3celementref.asp
Http://www.w3schools.com/xsl/xsl_functions.asp

XSL Study Notes (2)

In the first part, I learned 7 elements and 24 other elements. Learn them one by one.

1. <XSL: Import>, <XSL: Include>, and <XSL: Apply-imports> Elements
<XSL: Import> compared with <XSL: Include>, both of them must be <XSL: stylesheet> subnodes, but the template rules defined by the former have a low priority, and must be the first child node. The functions of the two are the same. They all load another defined XSL file into the current XSL file.
<XSL: Apply-imports> specifies when and where to use the template rules.
Their syntax is:

<XSL: Import href = "Uri"/>
<XSL: Apply-templates/>

2. <XSL: attribute> and <XSL: Attribute-set> Elements
The former is used to add an attribute to an element, and the former is replaced by an attribute with the same name. The latter is a child node of <XSL: stylesheet>. It is used to define a set of attributes and apply them to the entire document. Syntax:

<XSL: attribute name = "attributename" namespace = "Uri"> <! -- Content: Template --> </XSL: attribute>
<XSL: Attribute-set name = "name" use-Attribute-sets = "name-list"> <! -- Content: XSL: attribute * --> </XSL: Attribute-set>

Namespace (optional) and use-Attribute-sets (optional) are used to use other predefined Attribute-set.

3. <XSL: param>, <XSL: Call-template>, and <XSL: With-param> Elements
<XSL: param> is used to define global parameters (Child points of <XSL: styelsheet>) or local parameters (in a template). <XSL: call-template> is used to call the specified template. <XSL: With-param> is used to call the template or to pass parameters when using the template. It must be noted that the value of the with-Param name attribute must be consistent with the predefined value. Syntax:

<XSL: Param name = "name" select = "expression"> <! -- Content: Template --> </XSL: param>
<XSL: Call-Template Name = "templatename"> <! -- Content: XSL: With-Param * --> </XSL: Call-template>
<XSL: With-Param name = "name" select = "expression"> <! -- Content: Template --> </XSL: With-param>

The Select statements are optional. The select statements of the former are used to specify the default values. The latter statements can be used to transmit values (or use the label content to transmit values ).

4. <XSL: Variable> Elements
Defines global or local variables. Once assigned, they cannot be changed. Syntax:

<XSL: variable name = "name" select = "expression"> <! -- Content: Template --> </XSL: Variable>

5. <XSL: Copy> and <XSL: copy-of> Elements
Both copy the current node and Its namespace, but the latter also copies the subnode and the current node attributes. Syntax:

<XSL: copy-of select = "expression"/>
<XSL: Copy use-Attribute-sets = "name-list"> <! -- Content: Template --> </XSL: Copy>

Use-Attribute-sets are optional.

6. <XSL: Comment> Elements
Generate a comment node in the result tree. Syntax:

<XSL: Comment> <! -- Content: Template --> </XSL: Comment>

7. <XSL: decimal-format> element
Defines some special characters or symbols used in the process of calling the format-number () function to convert a number to a character generator. Syntax:

<XSL: decimal-format name = "name" Decimal-separator = "char" grouping-separator = "char" infinity = "string"
Minus-Sign = "char" Nan = "string" percent = "char" per-Mille = "char" zero-digit = "char" digit = "char" pattern-separator = "char"/>

All items are optional.

8. <XSL: Element> Elements
Generate an element in the result tree. The syntax is as follows:

<XSL: element name = "name" namespace = "Uri" use-Attribute-sets = "namelist"> <! -- Content: Template --> </XSL: Element>

The last two attributes are optional. The values of the first two attributes can be calculated during real-time running.

9. <XSL: fallback> Elements
When the XSL element cannot be recognized by the processor, the backup provided by fallback is called.Program.

<XSL: fallback> <! -- Content: Template --> </XSL: fallback>

10. <XSL: Key> element
This is a top-level element that defines a key for the key function.

<XSL: key name = "name" match = "pattern" use = "expression"/>

11. <XSL: Message> element
Used to output information, such as error information. All other elements can appear in the content.

<XSL: Message terminate = "Yes | no"> <! -- Content: Template --> </XSL: Message>

12. <XSL: namespace-alias> element
It is used to replace a namespace with another one in the output.

<XSL: namespace-alias stylesheet-Prefix = "prefix | # default" result-Prefix = "prefix |" # default "/>

13. <XSL: number> element
It indicates the order of the current node in the source tree, or you can format a number.

<XSL: number count = "expression" level = "single | multiple | any" from = "expression" value = "expression" format = "formatstring"
Lang = "languagecode" letter-value = "alphabetic | traditional" grouping-separator = "character" grouping-size = "Number"/>

14. <XSL: output> element
Used to define the output format,

<XSL: output method = "XML | HTML | text | Name" version = "string" encoding = "string" omit-XML-declaration = "Yes | no"
Standalone = "Yes | no" doctype-Public = "string" doctype-system = "string" CDATA-section-elements = "namelist"
Indent = "Yes | no" media-type = "string"/>

15. <XSL: preserve-space> and <XSL: strip-space> Elements
The two are used to indicate that the space of the element content is still removed. Because it is retained by default, you must specify the retainer only when you remove it.

<XSL: preserve-space elements = "list-of-element-names"/>
<XSL: strip-space elements = "list-of-element-names"/>

* Wildcards are available for list-of-element-names values.

16. <XSL: Processing-instruction> element
It is used to write processing commands to the output, such as specifying CSS files.

<XSL: Processing-instruction name = "process-name"> <! -- Content: Template --> </XSL: Processing-instruction>

17. <XSL: Text> Elements
Used to output string constants.

<XSL: Text disable-output-escaping = "Yes | no"> <! -- Content: # pcdata --> </XSL: Text>

Posted by Hilton at July 23,200 3 am | trackback

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.