[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: filtering descendent text nodes

Subject: Re: filtering descendent text nodes
From: Joerg Pietschmann <joerg.pietschmann@xxxxxx>
Date: Mon, 18 Mar 2002 12:18:53 +0100
define aseef.
Aseef Jamaluddin <j_aseef@xxxxxxxxx> 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.