Altova Mailing List Archives
>xsl-list Archive Home
>Recent entries
>Thread Prev - RE: [xsl] filtering descendent text nodes
>Thread Next - RE: [xsl] filtering descendent text nodes
RE: [xsl] filtering descendent text nodes
To:
Date: 3/18/2002 7:02:00 PM
Hi, That was very informative. Thanks. I have a set of tags of which some are whitespace text nodes. I need to filter out nodes which are not whitespace text nodes (to be more contedtual i need to know how many nodes has meaningful data associated and how many are whitespace text nodes). Is there any way of doing this. Please find below an example situation in the context of my query. <Employee> <empid>eid100</empid> <proj-id>pid1</proj-id> </Employee> <Employee> <empid>eid101</empid> <proj-id></proj-id> </Employee> <Employee> <empid>eid102</empid> <proj-id>pid2</proj-id> </Employee> >From the above list how can i filter out employees who doesnt have a project id assigned. If i try the strip-space tag how do i compare for the occurance of null. Thanks Aseef.J --- Michael Kay <michael.h.kay@xxxxxxxxxxxx> wrote: > > i am new to xslt. Given below is the files i am > using. > > > > <?xml version="1.0" ?> > > <custdet> > > <customer> > > <name> > > <firstname>FIRST1</firstname> > > <secondname>NAME1 > > <secondname1>SECONDNAME1</secondname1> > > </secondname> > > </name> > > </customer> > > </custdet> > > > > ------------------- > > I AM TRYING TO FILTER OUT ALL DESCENDENT TEXT > NODES > > VALUES (I.E. FIRST1,NAME1,SECONDNAME1) AND AM > USING > > THE FOLLOWING XSL FOR THAT. > > First point: every node except the root node is a > descendant of something. > The root node is the parent of the <custdet> element > (think of it as > representing the document itself). Certainly every > text node is a descendant > of something. So filtering out all the descendant > text nodes is the same as > filtering out all the text nodes. > > ------------------- > > > > <?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> > > <xsl:template match="*"> > > <xsl:apply-templates/> > > </xsl:template> > > <xsl:template match="text()"> > > <xsl:apply-templates/> > > </xsl:template> > > This last rule is rather peculiar. You are saying, > when a text node is > encountered, apply templates to its children. But > text nodes don't have > children. So your template rule is equivalent to > <xsl:template > match="text()"/> - which is fine if that's what you > want to do, it means > that when a text node is encountered, you output > nothing. > > > <!-- --> > > <xsl:template match="customer//node()"> > > First Name : > > <b><i> > > <font color="red"> > > <xsl:value-of select="." /> > > <br/> > > </font> > > </i></b> > > > > </xsl:template> > > This rule has a higher precedence than the rules > above, so it will be chosen > in preference when processing any node (which may be > an element node or text > node) that is a descendant of the <customer> > element. So your <xsl:template > match="*"/> rule will be used to process the > customer element itself. This > rule calls <xsl:apply-templates/> to process the > children of the customer > element. Apart from whitespace-only text nodes, > there is only one child of > <customer>, the <name> element. So the > customer//node() rules is invoked to > process the <name> element, and also to process the > whitespace-only text > nodes that precede and follow the <name> element. > > For each of these three nodes, the template outputs > "First name:" followed > by the string-value of the node, together with some > HTML markup. For the > whitespace text nodes, the string-value of the node > is whitespace. For the > <name> element, it is the concatenation of all the > text contained within the > <name> element (including whitespace), without any > tags. > > Your example output shows five lines. I think your > XML document must have > contained an extra element after the <name> element, > which you haven't shown > us. Also, I don't think you've shown us the (HTML) > output of the > transformation, you've shown us the way this HTML is > rendered by the > browser. > > The customer//node() template rule doesn't do an > <xsl:apply-templates/>, so > the children of the <name> element are never > processed. > > Michael Kay > Software AG > home: Michael.H.Kay@xxxxxxxxxxxx > work: Michael.Kay@xxxxxxxxxxxxxx > > > <!----> > > </xsl:stylesheet> > > > > > > THE expected result is three lines with "FIRST > NAME:" > > prefix and the corresponding text value attached. > The > > output i am getting is as follows > > > > > > First Name : > > First Name : FIRST1 NAME1 SECONDNAME1 > > First Name : > > First Name : 20one1 > > First Name > > > > Could somebody explain what actually is happening > and > > also some light on the difference between child > nodes > > and descendent nodes. > > > > Thanks > > Aseef.J > > > > __________________________________________________ > > Do You Yahoo!? > > Yahoo! Sports - live college hoops coverage > > http://sports.yahoo.com/ > > > > XSL-List info and archive: > http://www.mulberrytech.com/xsl/xsl-list > > > > > XSL-List info and archive: > http://www.mulberrytech.com/xsl/xsl-list > __________________________________________________ Do You Yahoo!? Yahoo! Sports - live college hoops coverage http://sports.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Disclaimer
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

