Re: [xsl] XSLT and unexpected text ouput?

Subject: Re: [xsl] XSLT and unexpected text ouput?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 28 Apr 2004 18:35:11 +0100
  If I understand this right, the behavior of the default template is
  simply to render the text contents of nodes. 

Not directly, it simply recurses on elements and copies text nodes, ie
it is as if you had

<xsl:template match="*">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="text()">
  <xsl:value-of select="."/>
</xsl:template>

in your stylesheet. By actually having templates that match those things
you can change the behaviour, eg if you had

<xsl:template match="*"/>

Then the default behaviour on elements woul dbe to discard them and all
their contents.



  
  	<xsl:template match="/">
  		<xsl:apply-templates select="WHATEVER"/>
  	</xsl:template>
  
  The root node match says specifically apply this template WHATEVER,
  which by implication means to ignore all other nodes off the root which
  do NOT match this template.  Otherwise, if nodes are neither matched nor
  excluded, the default template applies to them.  Is that it?


The terminology here is very confused so I'm not sure what you mean, but
I think that you mean something that is incorrect.

There can only be one root node in a document (it essentially _is_ the
document, it isn't the top level element of the document)

The default template for / is the same as the one above for elements
and applies templates to all its children, there can't be any top level
text if teh input is well formed, and the default template for comments
and pis is to discard, so by default processing moves to the top level
element.


If that has multiple children and you only specify templates for one of
them, you will get the result you described: text from all the other
children will appear at the top level of the output.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread