W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use , cookie and privacy policy. Copyright by Refsnes Data. The stylesheet programming is strictly procedural and deterministic. It is the stylesheet that defines the layout of the resulting HTML file.
To implement the stylesheet logic we have used the XSLT instructions discussed above. A template consists of a head and a body. The head of each template specifies the context in which the template should be activated. This is done by specifying an attribute match with an XPath expression to select the relevant context nodes. The template body describes what to do. This can be procedural XSLT instructions see above.
In addition, we may apply recursion with the instruction xsl:apply-templates , which applies all templates defined in the stylesheet to all nodes in the selected context. The select attribute of xsl:apply-templates defines the context in which the templates are to be executed. In addition, xsl:apply-templates has an optional mode attribute. This introduces an additional selection mechanism for templates: only those templates that have a matching mode attribute in their head are applied.
The result of an xsl:apply-templates instruction can be sorted with an xsl:sort instruction. In addition, the results can be numbered with the xsl:number instruction. If the heads of more than one template match a certain context, the template with the best match is selected for execution:. Templates in the current style sheet are selected over templates from imported style sheets. The more specific a matching expression in the template head is, the better is the match. In addition, it is possible to specify an explicit priority for a template.
Here is an example rule-based stylesheet that produces the same output as the previous procedural style sheet:. This stylesheet contains a separate rule for each element in the source document. The sequence of elements in the XML source triggers the execution of rules in the stylesheet. Rule-based stylesheets are therefore best used when the output document must closely match the structure of the source document.
In our example, there is one exception: To create an extra paragraph with tracks and title it with "Tracks" we used a two-pass approach. In the first pass we convert everything except track elements; in the second pass we convert only track elements. The appropriate templates are selected via mode attributes. XSLT supports variables and parameters. Forgot your password? Search within: Articles Quick Answers Messages.
Tagged as C. Stats S V Saichandra Rate me:. Please Sign up or sign in to vote. This article describes XSLT programming for beginners. Download source - 6. The following figure shows the flow of the XSLT processor. Prerequisites In order to execute the code, we need to have the following:. Copy Code. S V Saichandra. Software Developer Collabera. He Loves coding and his passion has always been towards Microsoft Technologies.
Apart from coding his other hobbies include reading books, painting and hang out with friends is his most favorite past time hobby. Clinton Gallagher Sep Go to top. Layout: fixed fluid. First Prev Next. Version Martin Bluck May Martin Bluck. Is this XSLT 2.
0コメント