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]
Other format: [Raw text]

Re: filtering descendent text nodes


Aseef Jamaluddin <j_aseef@yahoo.com> wrote:
> i am new to xslt. Given below is the files i am using.

Your post is somewhat inconsistent.
Well...

> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>   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
through.

> <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="http://www.w3.org/1999/XSL/Transform";
  version="1.0">
  <xsl:template match="customer">
   First Name :<b><i><font color="red">
     <xsl:value-of select="name/firstname" />
   <br/></font></i></b>
  </xsl:template>
</xsl:stylesheet>

HTH
J-Pietschmann

 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]