javascript - value is match with xml element then return all there sibling attribute value. -


i try attribute value if attribute value in xml file.

i try  xpath:- var xpath = '//*[local-name() = "dist_region" , ' +                                         ' contains(concat(@value, ","), "' + array_top[i] + ',")]' +                                          '/preceding-sibling::*/@*'; 

but return me top of node .
when entered value match return there above attribute value.
want there sibling attribute value.
ml format:-

<products>   <product_id value="1">     <tab_id value="351">       <tab_name value="test1"/>       <region_timezone value="1"/>       <registrationstatus value="2"/>       <eventstatus value="2"/>       <dist_activity value="4"/>       <dist_activity value="10066"/>       <dist_activity value="10070"/>       <dist_region value="4909"/>       <dist_region value="4902"/>       <dist_region value="4905"/>       <dist_value value="55"/>       <dist_value value="342"/>       <dist_value value="86"/>    </tab_id>  </product_id> <product_id value="2">     <tab_id value="351">       <tab_name value="test1"/>       <region_timezone value="1"/>       <registrationstatus value="2"/>       <eventstatus value="2"/>       <dist_activity value="4"/>       <dist_activity value="10066"/>       <dist_activity value="10070"/>       <dist_region value="4912"/>       <dist_region value="4908"/>       <dist_region value="4901"/>       <dist_value value="55"/>       <dist_value value="342"/>       <dist_value value="86"/>     </tab_id>   </product_id> </products> 

present output is:-

test1,1,2,2,4,10066,10070 

expected output:-

1,351,test1,1,2,2,4,10066,10070,4909,4902,4905,55,342,86 

how can attribute value please solve query.
thanks.

slightly changing xapht do.
replace /preceding-sibling::* /ancestor::product_id/descendant-or-self::*.

explanation what did:

'//*[local-name() = "dist_region" ,  contains(concat(@value, ","), "' + array_top[i] + ',")]' 

you looking dist_region given value in attribute value. example element <dist_region value="4909"/>.
next step element '/preceding-sibling::*/@* attribute values element in document order before current element on same level. leads output see.

what should do:
because of statement expected output:-
seems attributes of product_id current dist_region belongs to. therefore use:

ancestor::product_id/descendant-or-self::*/@* 

because: ancestor::product_id find product_id above form current element. , next step descendant-or-self::*/@* find attribute in child in deep.
that's it.

somme additional commands:
not know why using //*[local-name() = "dist_region" , ...]
//dist_region[...]/ should same.

output:

 1 351 test1 1 2 2 4 10066 10070 4909 4902 4905 55 342 86 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -