Need help with Xpath methods in javascript (selectSingleNode, selectNodes)

Posted by Andrija on Stack Overflow See other posts from Stack Overflow or by Andrija
Published on 2010-06-02T09:39:26Z Indexed on 2010/06/02 9:44 UTC
Read the original article Hit count: 380

Filed under:
|

I want to optimize my javascript but I ran into a bit of trouble. I'm using XSLT transformation and the basic idea is to get a part of the XML and subquery it so the calls are faster and less expensive. This is a part of the XML:

<suite>
<table id="spis" runat="client">
    <rows>                      
        <row id="spis_1">               
        <dispatch>'2008', '288627'</dispatch>       
        <data col="urGod">
            <title>2008</title>
            <description>Ur. god.</description>
        </data>
        <data col="rbr">
             <title>288627</title>
             <description>Rbr.</description>
        </data>

...

    </rows>
</table>
</suite>

In the page, this is the javascript that works with this:

// this is my global variable for getting the elements so I just get the most
// I can in one call    

elemCollection = iDom3.Table.all["spis"].XML.DOM.selectNodes("/suite/table/rows/row").context;

//then I have the method that uses this by getting the subresults from elemCollection
//rest of the method isn't interesting, only the selectNodes call

_buildResults = function (){
        var _RowList = elemCollection.selectNodes("/data[@col = 'urGod']/title");
        var tmpResult = [''];
        var substringResult="";
        for (i=0; i<_RowList.length; i++) {
            tmpResult.push(_RowList[i].text,iDom3.Global.Delimiter);
        }
...


//this variant works

elemCollection = iDom3.Table.all["spis"].XML.DOM

_buildResults = function (){
        var _RowList = elemCollection.selectNodes("/suite/table/rows/row/data[@col = 'urGod']/title");
        var tmpResult = [''];
        var substringResult="";
        for (i=0; i<_RowList.length; i++) {
            tmpResult.push(_RowList[i].text,iDom3.Global.Delimiter);
        }

...

The problem is, I can't find a way to use the subresults to get what I need.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about xpath