[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Understanding Templates

Subject: RE: Understanding Templates
From: "Hewko, Doug" <Doug.Hewko@xxxxxxxxxxxxxxx>
Date: Thu, 20 Sep 2001 10:05:24 -0400
understanding templates
Thanks for the reply. 

I really do not have a single problem to resolve right now. I find that I am
too enthusiastic with XML and need to step back a little to see if I
understand the basics. Maybe then everything will "click" together.

At times it is over-whelming reading books and tutorials, and working
through some of the problems in the list, plus trying to apply some of this
knowledge to my own projects.

> -----Original Message-----
> From: Mike Brown [mailto:mike@xxxxxxxx]
> Sent: September 18, 2001 4:16 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  Understanding Templates
> 
> 
> Hewko, Doug wrote:
> > Hi!
> > 
> > I have a couple of questions about Templates
> > 
> > Say that I have the following XML file:
> > <root>
> > 	<foo>Shoo
> > 		<bar>Beer</bar>
> > 	</foo>
> > 	<eggs>Ham
> > 		<bar>Soap</bar>
> > 	</eggs>
> > </root>
> > 
> > Using "match='/'" will give me the entire XML document
> 
> Not really. Processing begins at the root node (one level above the
> element you named 'root' in your doc). The XSLT processor looks at
> one node at a time and finds the template, perhaps using a built-in
> one, that best matches that node. Processing ends when it is done
> processing the template that matches the root node.
> 
> The template that matches the root node typically contains an
> instruction telling the XSLT processor to go process another set
> of nodes -- xsl:apply-templates, usually.
> 
> Within the template that matches the root node, you "have" just
> the root node as the current node. You don't have the whole doc,
> though you can access it pretty conveniently relative to the
> current node.
> 
> The built-in templates for the root and element nodes contain
> <xsl:apply-templates/>, which causes all child nodes to be
> processed. (children being basically everything except attributes)
> 
> The built-in template for a text node copies the text node to
> the result tree.
> 
> > If I have "match='//bar'",
> 
> Then you have a template that is a good match if the XSLT processor
> happens to need to process an element named 'bar' that is a 
> descendant of the root node.
> 
> > and a corresponding "value-of", would I get both
> > "Beer" and "Soap" because "//" looks for any instance in 
> the node of the
> > named element?
> 
> No. xsl:value-of is an instruction to create a text node in the
> result tree. If you give it a node-set in the select attribute,
> it will use the string-value (as defined by XPath) of the *first*
> node in the set, no more.
> 
> > If my only templates are "match='/'" and "match='bar'", 
> what would I get?
> 
> Try it and see!
> 
> > Aside of using "match='foo/bar'" and "match='eggs/bar'", 
> how could I make
> > sure I get the <bar> under <foo> and not the one under <eggs>?
> 
> You need to concentrate more on what you do with apply-templates
> than what you do with match.
> 
> I think once you understand the processing model, it will 
> become more clear
> how to solve your problem, whatever it is. (you didn't say)
> 
>    - Mike
> ______________________________________________________________
> ______________
>   mike j. brown, fourthought.com  |  xml/xslt: http://skew.org/xml/
>   denver/boulder, colorado, usa   |  personal: 
http://hyperreal.org/~mike/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.