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

RE: JavaScript Patterns

Subject: RE: JavaScript Patterns
From: "Diamond, Jason" <Jason.Diamond@xxxxxxx>
Date: Wed, 21 Feb 2001 17:16:04 -0600
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@xxxxxx [mailto:ward.ct@xxxxxx]
Sent: Wednesday, February 21, 2001 2:48 PM
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject:  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


Current Thread
  • JavaScript Patterns
    • ward . ct - Wed, 21 Feb 2001 17:48:37 -0500 (EST)
      • <Possible follow-ups>
      • Diamond, Jason - Wed, 21 Feb 2001 18:17:23 -0500 (EST) <=

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.