Wednesday, 7 January 2015

Jquery XML traversing filter date range



I am trying to find multiple nodes in an XML file which have a node attribute ex. like position[validFromDate=2015-01-05] and where the date is within the range of two dates (30 day windows). In addition I need to have a logic operand OR as in "select nodes IF position isPrimaryPosition attribute = true OR position validFromDate (date) is between date1 and date2.



To be very clear: isPrimaryPosition=true OR (date1 > validFromDate < date2)



The relevant part of the XML file looks like this:



<positions>
<position isPrimaryPosition="true" validFromDate="2015-06-20">
<position isPrimaryPosition="false" validFromDate="2015-01-19">
<position isPrimaryPosition="false" validFromDate="2015-06-20">
<position isPrimaryPosition="true" validFromDate="2015-01-19">
<position isPrimaryPosition="false" validFromDate="2015-01-19">
<position isPrimaryPosition="false" validFromDate="2015-06-20">
</positions>


The code I'm working on right now is like this but I can't figure out how to do the selection between the dates an logically OR this to the isPrimaryPosition:



$ansettelse = $(this).find('position[isPrimaryPosition=true],position[validFromDate=2015-01-05]')
$ansettelse.each(function() {
$stillingskategori = $(this).parent().siblings('category').attr('id');
$ansattnummer = $(this).parent().siblings('employeeId').text();
$ansettelsesprosent = $(this).parent().siblings('employmentPercentage').text();
});


I hope to get some help pointing me in the right direction.


No comments:

Post a Comment