Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: doesn't make sense #2..could you? >Thread Next - Re: doesn't make sense #2..could you? Re: doesn't make sense #2..could you?To: NULL Date: 10/14/2007 12:05:00 PM If you declare your first template to match / and then work down a lot of these problems disappear. If you want morre information serach for "default templates". (I think Anthony meant descendant-or-self not ancestor-or-self in his explanations.) -- Joe Fawcett (MVP - XML) http://joe.fawcett.name "TJ" <TJ@d...> wrote in message news:6D6FF40F-AA85-4FE4-A2D4-38D07425B37F@m...... > Hi, Peter, > Thanks for your great answer. Also thanks, Anthon Jones , for your great > answer. > > It makes sense in B case... > Peter, I have one more question in A case... > > Just want to make sure whehter my understanding is correct. > > So..basically, in A case, root element(/hello-world) wasn't found in the > template..so default rule kicks in and traverse the all child nodes..which > are > (greeting and greeter).. > By match="/hello-world/greeting" statement in A.xsl, it does match > greeting > child element of hello-world, which is root..so it prints by xsl:value-of > select..like <div>..</div>....Then greeter is printed by default template > rule.... > > Is my understanding correct? > > Thanks again, > > .....................................................................TJ > > > "Peter Flynn" wrote: > >> TJ wrote: >> > Hi, >> > >> > I am trying to understand the difference ....xsl...hum.. >> > >> > This is A.xsl >> > <?xml version="1.0"?> >> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >> > version="1.0"> >> > <xsl:template match="/hello-world/greeting"> >> > <div><xsl:value-of select="."/></div> >> > </xsl:template> >> > </xsl:stylesheet> >> > >> > This is B.xsl >> > <?xml version="1.0"?> >> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >> > version="1.0"> >> > <xsl:template match="/hello-world"> >> > <div><xsl:value-of select="greeting/text()"/></div> >> > </xsl:template> >> > </xsl:stylesheet> >> > >> > I tested these two xsl with this xml. >> > >> > This is A.xml >> > <?xml version="1.0"?> >> > <?xml-stylesheet type="text/xsl" href="A.xsl"?> >> > <hello-world> >> > <greeting>Hello, World!</greeting> >> > <greeter>An XSLT Programmer</greeter> >> > </hello-world> >> > >> > This is B.XML >> > <?xml version="1.0"?> >> > <?xml-stylesheet type="text/xsl" href="B.xsl"?> >> > <hello-world> >> > <greeting>Hello, World!</greeting> >> > <greeter>An XSLT Programmer</greeter> >> > </hello-world> >> > >> > It produce different results in IE7. >> > A.XML output >> > Hello, World! >> > An XSLT Programmer >> > >> > B.XML output >> > Hello, World! >> > >> > It looks to me that two xsl should produce >> > same output.....hum... >> > Can anybody explain this? >> >> In XSL, if there is no template matching an element type, it will be >> assumed to equate to an "apply-templates" directive. Here, there is no >> template matching the document root ("/"), so it will proceed to look >> for a template matching the root element type (in your example, >> "hello-world"). >> >> In A.xsl, there is no template matching "hello-world", so using the same >> default rule, it will be assumed to equate to an "apply-templates" >> directive and will walk down the tree to the first subelement, >> "greeting", where it will test and apply the same rule, and find that a >> template for this element type *does* exist, and it says to add the >> string value (".") of any text or elements below this point. (In fact >> this template doesn't need to be quite so specific in its match, just >> "greeting" would have done; the effect of the value-of for "." means >> that if there had been any further nested subelements inside greeting, >> they would have been stripped of their markup and the whole content of >> greeting concatenated and output as a simple string). Having exhausted >> depth, the processor moves sideways to the next sibling element type, >> "greeter". There is no template to match this, so as there are no nested >> subelements, the text content of greeter is added to the output tree. >> >> However, in B.xsl, there *is* a match for the root element. It doesn't >> need to be quite so explicit, just "hello-world" would have done, >> without the slash. In this case, the template says to add the value of >> all the text in the "greeting" subelement to the output tree, which it >> does. This template does not specify any further processing, so as there >> is nothing left to look at, the processing stops here. The greeting >> element and the greeter element, will never *themselves* get processed >> as such, either explicitly (looking for a matching template) NOR >> implicitly (using the default template) because while the current >> context was "hello-world", a template *was* found (whereas in A.xsl it >> was not), and once a template matches, no further >> searching-for-templates occurs *for that element*: only what is >> specifies in the matching template will get done, nothing more. And in >> this case, as the element in question was the root element (of which >> only one can exist), that's all, folks. >> >> ///Peter >> -- >> XML FAQ: http://xml.silmaril.ie/ >> | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
