This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Understanding Templates
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] Understanding Templates
- From: "Michael Kay" <mhkay at iclway dot co dot uk>
- Date: Tue, 18 Sep 2001 21:47:11 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
> 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
To be precise, it will match the root node of the document. A pattern
matches some nodes and doesn't match others; match="/" matches only the root
node.
>
> If I have "match='//bar'", and a corresponding "value-of",
> would I get both
> "Beer" and "Soap" because "//" looks for any instance in the
> node of the named element?
The pattern match="//bar" matches exactly the same nodes as match="bar",
that is, a <bar> element anywhere in the document. I'm not sure what you
mean by a "corresponding" value-of.
>
> If my only templates are "match='/'" and "match='bar'", what
> would I get?
Assuming that all your templates do an <xsl:apply-templates/> to process
their children, then the match="bar" will match all the <bar> nodes,
regardless of their position in the tree.
> 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>?
This is precisely what "match='foo/bar'" and "match='eggs/bar'" are designed
to achieve, why would you want to do it any other way?
Mike Kay
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list