|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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@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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








