176 CHAPTER 6 INTRODUCTION TO XSLT WHICH TEMPLATE WILL BE APPLIED? In XSLT 1.0, has a priority attribute that allows you to specify which template to apply if several match a node. A higher priority indicates that the template should apply in preference to others. If the template doesn t specify a priority, it s quite complicated to determine the order in which templates apply. Section 5.5 of the XSLT specification describes the complete process (http://www.w3.org/ TR/xslt#conflict). In essence, the rules state that the XSLT processor should use the most specific of all matching templates. In this example, the identity template matches every node, including the element, but because you have a specific template, that takes precedence. You can use the following identity transformation lines to pass these tags through unchanged: The identity transformation template leaves everything in its original state. It matches every part of the source XML document that doesn t have its own style rule and passes it through unchanged. The identity transformation matches all nodes (node()) and attributes (@*) within the source document. When it finds a match, the rule uses to create an identical copy of the matching item. The tag processes the contents of the matched item without changing them. If this were the only template within an XSLT stylesheet, it would produce a document functionally the same as the source document. You can t use this template when the output document is substantially different from the input document. Normally, you d use it as you ve seen in this example to pass through the unchanged content along with another simple template. Each element or attribute in the source XML document can only be matched by one template, so you need to copy the element to the output document rather than relying on the identity template to do it for you. Because the template is more specific than the identity transformation template, that declaration takes precedence. Let s move on to another example, where I ll use XSLT to repeat content from the source document using a different layout. Creating a Table of Contents This example creates a table of contents showing the nearest planets to us in the solar system. It shows how to generate new content automatically from existing content. Without this approach, you would have to generate the list with server-side logic or by using JavaScript to manipulate the Document Object Model (DOM) and write out the contents.
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.
This entry was posted
on Saturday, September 29th, 2007 at 6:02 pm and is filed under Tomcat.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.