javascript - Find the Max Value for an XML Attribute, Across Records -
using jquery & spservices, receive xml similar following:
<?xml version="1.0"?> <soap:envelope xmlns: . . .> <soap:body> <getlistitemsresponse xmlns=" ... "> <getlistitemsresult> <listitems xmlns:s=" ... > <rs:data itemcount="4"> <z:row ows_ctid="5" ows_id="1" ows_ct="gr" /> <z:row ows_ctid="9" ows_id="4" ows_ct="pc" /> <z:row ows_ctid="2" ows_id="5" ows_ct="g" /> <z:row ows_ctid="3" ows_id="7" ows_ct="o55" /> </rs:data> </listitems> </getlistitemsresult> </getlistitemsresponse> </soap:body></soap:envelope> (i lot more, of course; has been pared down simplicity in showing concept.)
you note ordering according ows_id, , both ows_id , ows_ctid have gaps in values.
i want min & max values of ows_ctid; want “2” & “9,” in other words.
using javascript, jquery (and possibly spservices), how can min , max value of specific attribute in xml (ows_ctid, in case)?
you need loop through z:row's , keep variable min , max, updating them when larger value or lesser value found... example, place following inside completefunc function of spservices:
var min = null, max = null; $(xdata.responsexml).spfilternode("z:row").each(function() { var $this = $(this), val = parseint( $this.attr("ows_ctid") ); if (min === null) { min = max = val; } if (val < min) { min = val; } if (val > max) { max = val; } }); alert("min: " + min + " | max: " + max); if field (in case, ows_ctid) other integer, change above not use 'parseint'... if number decimals, change parsefloat instead.
paul.
Comments
Post a Comment