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. 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] filtering descendent text, Peter Davis | Thread | [xsl] Special Characters display in, King Wilder |
RE: [xsl] Newbie: using translate, Jarno . Elovirta | Date | RE: [xsl] commandline parameters, Pavitra Jain |
Month |