Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - doesn't make sense....could you? [Thread Next] Re: doesn't make sense....could you?To: NULL Date: 10/13/2007 4:38:00 PM "TJ" <TJ@d...> wrote in message news:3E98B3D9-5850-4ACD-890D-DCBE2F3F17DD@m...... > Hi, > > I am a beginner to learn XSL. > Hope I can understand this clearly. > > This is example xml from MSDN. (hello.xml) > > <?xml version="1.0"?> > <?xml-stylesheet type="text/xsl" href="hello.xsl"?> > <hello-world> > <greeter>An XSLT Programmer</greeter> > <greeting>Hello, World!</greeting> > </hello-world> > > this is hello.xsl that I am just playing around to see how it works.. > > <?xml version="1.0"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > <xsl:template match="/hello-world/greeter"> > <div><xsl:value-of select="."/></div> > </xsl:template> > </xsl:stylesheet> > > As far as I can understand, it should print only "An XSLT Programmer" > because I think current match scope is under /hello-world/greeter. However, > when I run this in IE7, it prints > > An XSLT Programmer > Hello, World! > > I am trying to understand how "Hello,World!" can be printed by this XSL... > Can anybody explain this concept? > The key thing to understand is how XSL starts to look for nodes to transform. Its effectively ancestor-or-self::* from the root. When it finds a match to a template that node is processed by the template, child nodes of that context node won't be processed unless expressly asked to by an apply-templates element. However siblings to the initally selected node and their descendants are still subject to the initial search for nodes. Think of XSL processing as their being an implicit <xsl:apply-templates select="ancestor-or-self::*" /> to find a match to any of the templates in the sheet. Hence when /hello-word/greeter is matched by this 'implicit' apply templates it handles that node but then the outer 'implicit' apply templates continues after that. Try this. Delete all templates from the stylesheet so that it is empty. What do you get? Just the contents of all the text nodes. This is what XSL does if no match is found for a node or any of its descendants. Hence in your case /hello-world/greeter is matched but greeting isn't and gets the default treatment. -- Anthony Jones - MVP ASP/ASP.NET | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
