Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: doesn't make sense....could you?

From: "Anthony Jones" <Ant@------------.--->
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




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent