xsl-list
[Top] [All Lists]

Re: Apply-templates - how to omit top level element tags?

2005-09-08 01:44:45
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
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>