Re: Can someone please explain:<xsl:template match="*" />

Subject: Re: Can someone please explain:<xsl:template match="*" />
From: Dan Morrison <dman@xxxxxxxx>
Date: Sun, 11 Jun 2000 06:21:43 +1200
alex chang wrote:
> Can someone please explain:
> <xsl:template match="*" />

You're lucky to be looking at such well documented code. :-)

> <!-- The template with match="*" below is a fail-safe.

Which means it's error-handling for a condition which is not expected to
Commenting it out therefore has no effect on a well-formed example, but
makes the code slightly less robust.

>  If at any point we
> get to a node in the XML tree that doesn't match any of our template match
> statements, we replace that node with blank space. -->

Reads pretty clearly to me.

XSL template matching basically goes from the most specific to the
least. There are some subtle rules to it, but in practice you usually
get it right.

match="/top/node" will take precedence over match="node", and for that
matter match="*" (everything not already matched)

All the example you are looking at is saying is that if there is
unexpected content in your source XML
(Say one day you add <AUTHOR>alex</AUTHOR>) the stylesheet will
explicitly ignore it instead of displaying it in plaintext (which is the
default behavior).

This means that your author tag will not appear in the output _until_
you get around to handling it with a 
<xsl:template match="AUTHOR"><i><xsl:value-of

or similar.

Of course if you're confused enough to be using the old Microsoft 'XSL'
parser, this template is odd because the default behaviour of MSXML was
originally to ignore everything anyway. 
Folk who wanted proper easy behaviour had to add the opposite to that

<xsl:template match="*"><xsl:value-of select="."/></xsl:template> 

... to get results.

Easy really.

And please Alex, use subject lines when posting to several thousand busy


: Dan Morrison        : The Web Limited    :
: :  :
:  dman@xxxxxxxx      :  danm@xxxxxxxxx    :
:  04 384 1472        :  04 495 8250       :
:  025 207 1140       :                    :
: If ignorance is bliss, why aren't more people happy?

 XSL-List info and archive:

Current Thread