A problem with template matching rules about XSLT
Problem: http://expert.9cbs.net/expert/topic/2549/2549396.xml?temp =.5212061
Problem Description:
************** Source file: Test.xml ***************
XML Version = "1.0"?>
book>
books>
*************** Conversion file: Test.xsl **************
DD
xsl: template>
xsl: stylesheet>
Output:
Extreme Programming DD Giancarrio Succi / Michele Marchesi / Zhang Hui (Translated)
Instead, I want DD
If match = / books / book / *, DD DD DD
Why is this, please make a clear
Solution and Xiang's solution
Let us first familiarize with the XSL workflow.
When the XSL parser starts working, I always look for the root node of the document, which is
The XSL parser first finds the root of the document is
The above words look like a bit confused, next, let's take a look at the process of the XSL document output in "Problem Description" to better understand the XSL workflow.
DD
xsl: template>
xsl: stylesheet>
The workflow for the above code parser is like this:
1. Look for
2. Look for
book>
books>
If there is no template for the BOOKS node, the parser will output "death when you deal with the BOOKS node". "
3. Look for
4. Look for
5. Look for
6. Look for
The result of the final output is:
Extreme Programming DD Giancarrio Succi / Michele Marchesi / Zhang Hui (Translated)
Let's take a look at the second question of the problem: if match = / books / book / * is DD DD DD.
Write the changed code:
DD
xsl: template>
xsl: stylesheet>
DD
xsl: template>
DD
xsl: template>
xsl: template>
xsl: stylesheet>
This way the processor will call the provided template when the corresponding node is processed. So the result of the output will be as you can see.
The result of the question is DD. What should we do?
Here are a few solutions:
The first, providing a template for a matching text node, covering the built-in template.
DD xsl: template> xsl: stylesheet> The second, does not provide templates of the matching text node, but provides a template that matches the first-level node. DD xsl: template> xsl: stylesheet> There are still many variations, please think yourself. Exterior: Everyone can see that XSL is displayed by selecting the content of the XML file content. Its work mode is a bit of hands. Of course, it can also show content with the XML file content. Examples, XSL is a You have achieved a good tool for hanging a sheep's head selling dog meat. Below is a XLS code, which realizes the function of hanging the dog's meat. XML Version = "1.0" encoding = "GB2312"?> Title: strong> Price: strong> Author: strong> Don't sell money! xsl: template> Die xsl: template> Extremely metamorphosis tobacco! xsl: template> xsl: stylesheet> This is my first article. I have been a lot of four years in 9cbs. I have learned a lot from here. But I have never sent a post. I saw the questionr in the forum. This is, I have just learned the difficulties in XML, so I wrote this article, I hope to help beginners spend the difficulties. In order to fall into the "dung" for a long time. In addition, I hope that everyone will make valuable comments and suggestions, I have unconditionally accept the insults and destruction of everyone.