Subject: RE: [xsl] JavaScript Patterns From: "Diamond, Jason" <Jason.Diamond@xxxxxxx> Date: Wed, 21 Feb 2001 17:16:04 -0600 |
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: [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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] JavaScript Patterns, ward . ct | Thread | [xsl] Transforming XML to a schema , Adrian Smoothy |
[xsl] JavaScript Patterns, ward . ct | Date | RE: [xsl] XQuery (was Designs for X, Evan Lenz |
Month |