RE: [xsl] Apply-templates - how to omit top level element tags?

Subject: RE: [xsl] Apply-templates - how to omit top level element tags?
From: "Mike Schinkel" <mikes@xxxxxxxxx>
Date: Thu, 8 Sep 2005 14:45:40 -0400
Thanks for the reply.


>> Part of your problem is that you are using xsl:value-of rather than
xsl:copy-of, value-of always

As I understand it, copy-of does a literal copy, and does not apply any
templates, right?

-Mike


-----Original Message-----
From: David Carlisle [mailto:davidc@xxxxxxxxx]
Sent: Thursday, September 08, 2005 4:45 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Apply-templates - how to omit top level element tags?

Unfortunately, I still don't grok the difference between:

> Unfortunately, I still don't grok the difference between:
>
> 	*
> 	.
> 	node()


Part of your problem is that you are using xsl:value-of rather than
xsl:copy-of, value-of always gives teh _string value_ of its argument,
so you never see the difference between an element and a text node using
value-of

Consider an input of

<a>www
  <b>zzz</b>
  <!-- yyy -->
  <z/>
</a>

and
<xsl:template match="a">
...
</xsl:template>

then if ... is

<xsl:copy-of select="."/>


You will output a copy of the current node (which is a) a node includes
all children etc so you get

<a>www
  <b>zzz</b>
  <!-- yyy -->
  <z/>
</a>


then if ... is

<xsl:copy-of select="*"/>

then * is short for child::* and selects all child elements so you get

<b>zzz</b><z/>

note, no top level a, no comments and no text nodes, including
indentation white space nodes.


then if ... is

<xsl:copy-of select="node()"/>

then node() is short for child::node() which selects all child nodes
(elements, text, comments and processing instructions) and you get

www
  <b>zzz</b>
  <!-- yyy -->
  <z/>


(no top level <a> element, as you only copied children.

David


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. 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