Re: [xsl] filtering descendent text nodes

Subject: Re: [xsl] filtering descendent text nodes
From: Joerg Pietschmann <joerg.pietschmann@xxxxxx>
Date: Mon, 18 Mar 2002 12:18:53 +0100
Aseef Jamaluddin <j_aseef@xxxxxxxxx> wrote:
> i am new to xslt. Given below is the files i am using.

Your post is somewhat inconsistent.

> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="";
>   version="1.0">
> <xsl:template match="/">
> <xsl:apply-templates  />
> </xsl:template>
This and the following template are already provided in
this form by default by the processor, no need to define
them explicitely.

> <xsl:template match="text()">
>  <xsl:apply-templates/>
> </xsl:template>
Note that this essentially is a no-op, no text will be coppied

> <xsl:template match="customer//node()">
>   <xsl:value-of select="." />
> Could somebody explain what actually is happening and
> also some light on the difference between child nodes
> and descendent nodes.

The processor visits nodes in the tree and recursively applies
templates as defined by both the built-in and your first two
templates. Your last template is matched by the three child nodes
of the customer element node, two whitespace only nodes and the
name element node between them. Because there is no apply-templates
there, no template will be recursively applied. The whitespace only
text nodes generate the lines with "First Name :" and no further
text, because xsl:value-of retrieves their whitespace-only content.
In the other lines you get the complete text content of the name
element nodes inserted by the xsl:value-of, which by definition
includes text of any descendants. The whitespace retrieved is
normalized by your browser during display.
If you want only the firstname elements in your output, try
the following transformation:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="";
  <xsl:template match="customer">
   First Name :<b><i><font color="red">
     <xsl:value-of select="name/firstname" />


 XSL-List info and archive:

Current Thread