This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


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
arise.
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
select="."/></xsl:template> 

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
fail-safe:

<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
people.

.dan.

:=====================:====================:
: Dan Morrison        : The Web Limited    :
:  http://here.is/dan :  http://web.co.nz  :
:  dman@es.co.nz      :  danm@web.co.nz    :
:  04 384 1472        :  04 495 8250       :
:  025 207 1140       :                    :
:.....................:....................:
: If ignorance is bliss, why aren't more people happy?
:.........................................:


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]