RE: [xsl] JavaScript Patterns

Subject: RE: [xsl] JavaScript Patterns
From: "Diamond, Jason" <Jason.Diamond@xxxxxxx>
Date: Wed, 21 Feb 2001 17:16:04 -0600

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

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,

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

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

First the XML:

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++)

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:

 XSL-List info and archive:

Current Thread