Using OCLC xISBN service and jQuery to find newer editions

This is a jQuery function that looks for ISBNs in – and for each one queries the OCLC xISBN service http://xisbn.worldcat.org/xisbnadmin/doc/api.htm (the service is limited to 500 requests a day as an non-commercial ad-hoc user).
For each ISBN, the returned data is used to calculate what year the ISBN passed to the service is used, and also which editions are newer than that edition, and which the newest editions are.

The year for each edition is added to the originating span – wrapped in a span with a class to show if it’s a newer or newest edition.
Other data is returned from the xISBN service – e.g. title – which is unused in this example.


function oclcEditions(){
var OCLCxisbn = "http://xisbn.worldcat.org/webservices/xid/isbn/INSERT-ISBN?method=getEditions&format=json&fl=year,title&callback=?";

$('span.oclc-versions').each(function(){
var mySpan = $(this);
var myEdition = $(this).text().trim();
var myURL = OCLCxisbn.replace(/INSERT-ISBN/,myEdition);

$.getJSON(myURL, function(data) {
var myYear = "";
var latestYear = 0;
$.each(data.list, function(i,item){
if(item.isbn == myEdition){
myYear = item.year;
}
if(item.year > latestYear){
latestYear = item.year;
}
});
$.each(data.list, function(i,item){
if(item.year >= latestYear){
mySpan.html(mySpan.html() + ", " +item.year + "");
} else if(item.year > myYear){
mySpan.html(mySpan.html() + ", " +item.year + "");
} else if(item.year == myYear){
mySpan.html(mySpan.html() + ", " +item.year + "");
} else {
mySpan.html(mySpan.html() + ", " +item.year);
}
});

});
});
$('#textcontent').prepend('

Key: Newest edition, newer edition, current edition.

');

}

Leave a reply

You must be logged in to post a comment.