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]

RE: JavaScript Patterns


Hi.

If you change the "alert(nodes.item(n).text);" to
"alert(nodes.item(n).nodeName);" you'll see that the node list does, in
fact, only contains "level" nodes. When you ask for the text value of each
node, it actually concatenates the text value of all the child nodes and
that's why you're seeing the text from the col1 and col2 elements as well.

Personally, I would alter the document so that the level elements don't
contain mixed content. Either move the "1" and "2" text nodes into
attributes on the level element or place them in their own child element of
level.

If you wanted keep the mixed content and the text you were looking for was
always found before the child elements, you could switch the document's
selection language to XPath (since the default language is the old
XSLPatterns syntax) and then select the first text node beneath the level
elements like this:

doc.setProperty("SelectionLanguage", "XPath");
var nodes = doc.selectNodes("//level/text()[1]");

Hope this helps,
Jason.

-----Original Message-----
From: ward.ct@pg.com [mailto:ward.ct@pg.com]
Sent: Wednesday, February 21, 2001 2:48 PM
To: XSL-List@lists.mulberrytech.com
Subject: [xsl] JavaScript Patterns


I had a question on patterns.  Note: I'm strictly using JavaScript.  I'm not
using XSL.

First the XML:
<root>
<level>1
<col1>You</col1>
<col2>GO</col2>
</level>
<level>2
<col1>You</col1>
<col2>Stay</col2>
</level>
<level>2
<col1>You</col1>
<col2>Walk</col2>
</level>
</root>

I have the following JS code:

var nodes = doc.selectNodes("//level");    'Where doc is an XML document
for (var n=0; n<nodes.length; n++)
     alert(nodes.item(n).text;

This works and returns all of the levels I want, but it also includes the
children, col1 & col2.  Is there a way just to return the levels ?


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 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]