View | Details | Raw Unified | Return to bug 6536
Collapse All | Expand All

(-)a/C4/Breeding.pm (-3 / +436 lines)
Lines 21-30 use strict; Link Here
21
use warnings;
21
use warnings;
22
22
23
use C4::Biblio;
23
use C4::Biblio;
24
use C4::Koha;
25
use C4::Charset;
24
use C4::Charset;
26
use MARC::File::USMARC;
27
use C4::ImportBatch;
25
use C4::ImportBatch;
26
use C4::Koha;
27
28
use MARC::File::USMARC;
29
use XML::LibXML;
30
use XML::LibXSLT;
31
use ZOOM;
28
32
29
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
33
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
30
34
Lines 36-41 BEGIN { Link Here
36
	@EXPORT = qw(&ImportBreeding &BreedingSearch);
40
	@EXPORT = qw(&ImportBreeding &BreedingSearch);
37
}
41
}
38
42
43
#-------------------------------------------------------------------------------
44
45
use constant MAX_RESULTS => 20;
46
use constant TO_UNIMARC_XSLT => 'MARC21toUNIMARC.xsl';
47
use constant TO_MARC21_XSLT => 'UNIMARCtoMARC21.xsl';
48
49
my ($input,@oConnection,@oResult,@hServer,$zquery, $squery);
50
#zquery in z3950 format; squery general sru, needs server translation
51
my $xsltconv; #stylesheet for marc conversion
52
my $flavour; #system marc flavour
53
54
my $DEBUG=0;	#set to 1 for debug warnings
55
56
#-------------------------------------------------------------------------------
57
39
=head1 NAME
58
=head1 NAME
40
59
41
C4::Breeding : module to add biblios to import_records via
60
C4::Breeding : module to add biblios to import_records via
Lines 154-160 sub ImportBreeding { Link Here
154
    return ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$breedingid);
173
    return ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$breedingid);
155
}
174
}
156
175
157
158
=head2 BreedingSearch
176
=head2 BreedingSearch
159
177
160
($count, @results) = &BreedingSearch($title,$isbn,$random);
178
($count, @results) = &BreedingSearch($title,$isbn,$random);
Lines 216-221 sub BreedingSearch { Link Here
216
    return($count, @results);
234
    return($count, @results);
217
} # sub breedingsearch
235
} # sub breedingsearch
218
236
237
=head2 z3950_search
238
239
($breedingref, $error_ref)= C4::Breeding::z3950_search($input);
240
C<$input> is a CGI object: all search parameters are passed via this object
241
242
C<$breedingref> is an arrayref of search result hashes.
243
C<$error_ref> is an arrayref of error messages per server.
244
245
z3950_search does not call ImportBreeding anymore for performance reasons.
246
247
=cut
248
249
sub z3950_search {
250
# This is a completely new Z3950 clients search using async ZOOM -TG 02/11/06
251
# Did some refactoring, introduced SRU searching -MR 20110608
252
# And incorporated Biblibre XSLT processing for MARC21/UNIMARC conversion
253
  $input= shift; #CGI object passed
254
  my (@errconn, @breeding_loop);
255
256
  init_vars();
257
  build_query();
258
  my $s= create_connections();
259
  load_xslt();
260
  start_async_searches();
261
262
  my $nremaining  = $s;
263
  while($nremaining>0) {
264
    my $k=loop_conn_events(); #returns finished connection number
265
    handle_conn_results(\@breeding_loop, \@errconn, $k) unless $k<0;
266
    --$nremaining;
267
  }
268
  $_->destroy() for @oConnection;
269
270
  return (\@breeding_loop, \@errconn );
271
}
272
273
#-------------------------------------------------------------------------------
274
# Some internal subroutines
275
276
sub init_vars {
277
  @oConnection=();
278
  @oResult=();
279
  @hServer=();
280
  ($zquery,$squery,$xsltconv,$flavour)=('','',undef,'');
281
}
282
283
sub build_query {
284
  my $nterms=0;
285
  my $title         = $input->param('title')||'';
286
  my $author        = $input->param('author')||'';
287
  my $isbn          = $input->param('isbn')||'';
288
  my $lccall        = $input->param('lccall')||'';
289
  my $subject       = $input->param('subject')||'';
290
  my $dewey         = $input->param('dewey')||'';
291
  my $controlnumber = $input->param('controlnumber')||'';
292
  my $stdid         = $input->param('stdid')||'';
293
  my $srchany       = $input->param('srchany')||'';
294
295
  if ($isbn) {
296
        $zquery = "\@or \@attr 1=8 \"$isbn\" \@attr 1=7 \"$isbn\" ";
297
	$squery = "([isbn]=\"$isbn\" or [issn]=\"$isbn\") and ";
298
        $nterms++;
299
  }
300
  if ($title) {
301
        utf8::decode($title);
302
        $zquery .= "\@attr 1=4 \"$title\" ";
303
	$squery .= "[title]=\"$title\" and ";
304
        $nterms++;
305
  }
306
  if ($author) {
307
        utf8::decode($author);
308
        $zquery .= "\@attr 1=1003 \"$author\" ";
309
	$squery .= "[author]=\"$author\" and ";
310
        $nterms++;
311
  }
312
  if ($dewey) {
313
        $zquery .= "\@attr 1=16 \"$dewey\" ";
314
	$squery .= "[dewey]=\"$dewey\" and ";
315
        $nterms++;
316
  }
317
  if ($subject) {
318
        utf8::decode($subject);
319
        $zquery .= "\@attr 1=21 \"$subject\" ";
320
	$squery .= "[subject]=\"$subject\" and ";
321
        $nterms++;
322
  }
323
  if ($lccall) {
324
        $zquery .= "\@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" ";
325
	$squery .= "[lccn]=\"$lccall\" and ";
326
        $nterms++;
327
  }
328
  if ($controlnumber) {
329
        $zquery .= "\@attr 1=12 \"$controlnumber\" ";
330
	$squery .= "[controlnumber]=\"$controlnumber\" and ";
331
        $nterms++;
332
  }
333
  if ($stdid) {
334
        $zquery .= "\@attr 1=1007 \"$stdid\" ";
335
	$squery .= "[stdid]=\"$stdid\" and ";
336
        $nterms++;
337
  }
338
  if ($srchany) {
339
        $zquery .= "\@attr 1=1016 \"$srchany\" ";
340
	$squery .= "[any]=\"$srchany\" and ";
341
        $nterms++;
342
  }
343
  for(1..$nterms-1) {
344
      $zquery = "\@and " . $zquery;
345
  }
346
  $squery=~s/\sand\s$//; #remove last and in sru query
347
  warn "zquery ".$zquery  if $DEBUG;
348
  warn "squery ".$squery  if $DEBUG;
349
}
350
351
sub create_connections {
352
  my $s=0;
353
  my $dbh= C4::Context->dbh;
354
355
  my @id= $input->param('id');
356
  foreach my $servid (@id) {
357
        my $sth = $dbh->prepare("select * from z3950servers where id=?");
358
        $sth->execute($servid);
359
        my $server = $sth->fetchrow_hashref;
360
	next unless $server;
361
        warn "serverinfo ".join(':',my @a=map($_||'',%$server)) if $DEBUG;
362
363
        $server->{sru}= $server->{host}=~/^sru=/ ? 1: 0;
364
	change_sru_host($server) if $server->{sru};
365
366
	#set connection options
367
        my $option1      = new ZOOM::Options();
368
        $option1->option('async' => 1);
369
        $option1->option('elementSetName', 'F');
370
        $option1->option('databaseName', $server->{db}) unless $server->{sru};
371
        $option1->option('user', $server->{userid}) if $server->{userid};
372
        $option1->option('password',$server->{password}) if $server->{password};
373
        $option1->option('preferredRecordSyntax', $server->{syntax});
374
        $option1->option('maximumRecords', MAX_RESULTS) if $server->{sru};
375
	  #MR: doubt if maximum makes difference when going through ZOOM
376
	pass_sru_options($server,$option1) if $server->{sru};
377
378
	#create connection object
379
	my $conn;
380
        $oConnection[$s]= create ZOOM::Connection($option1);
381
382
	#now connect
383
	if($server->{sru}) {
384
          $oConnection[$s]->connect( 'http://'.$server->{host});
385
        }
386
        else {
387
          $oConnection[$s]->connect( $server->{host}, $server->{port} );
388
	}
389
390
        $hServer[$s]= $server;
391
        $s++;
392
  }
393
  return $s;
394
}
395
396
sub change_sru_host { #merge port and database into hostname
397
  my $server= shift;
398
  if($server->{port} ne '80') {
399
    if($server->{host}=~/^([^\/]+)\/(.*)$/ ) {
400
      $server->{host}= $1.':'.$server->{port}.'/'.$2;
401
    }
402
    else {
403
      $server->{host}.= ':'.$server->{port};
404
    }
405
  }
406
  #prevent double slash between host and db when concatenating
407
  $server->{host}=~ s/\/$//g;
408
  $server->{db}=~ s/^\///g;
409
  $server->{host}.= '/'.$server->{db};
410
}
411
412
sub pass_sru_options {
413
  my ($server, $option1)=@_;
414
  my @parts= split /,/,$server->{host};
415
  foreach(my $i=0; $i<@parts; $i++) {
416
    if($i==@parts-1) {
417
      $server->{host}=$parts[$i];
418
    }
419
    else {
420
      if($parts[$i]=~/^([^=]+)=(.*)/) {
421
        $option1->option( $1 => $2);
422
      }
423
    }
424
  }
425
}
426
427
sub load_xslt { #load stylesheet for marc conversion IF needed
428
  $flavour= C4::Context->preference('marcflavour');
429
  my $loaded=0;
430
  foreach (@hServer) { #load stylesheet once, set key for each server
431
    $_->{marc_conv}=0;
432
    if($flavour eq 'MARC21' && $_->{syntax}=~/UNIMARC/) {
433
      $_->{marc_conv}=1;
434
      _load_xslt_stylesheet(TO_MARC21_XSLT) unless $loaded;
435
      $loaded=1;
436
    }
437
    elsif($flavour eq 'UNIMARC' && $_->{syntax}!~/UNIMARC/) {
438
      $_->{marc_conv}=1;
439
      _load_xslt_stylesheet(TO_UNIMARC_XSLT) unless $loaded;
440
      $loaded=1;
441
    }
442
  }
443
}
444
445
sub _load_xslt_stylesheet {
446
  my ($name)= @_;
447
  my $f=full_xslt_path($name);
448
  if($f) {
449
    my $parser = XML::LibXML->new();
450
    my $xslt = XML::LibXSLT->new();
451
    my $style_doc = $parser->parse_file($f);
452
    $xsltconv = $xslt->parse_stylesheet($style_doc);
453
  }
454
  else {
455
    warn "z3950_search: XSLT problem with $name";
456
  }
457
}
458
459
sub full_xslt_path {
460
  my $name=shift;
461
  #absolute path?
462
  if(substr($name,0,1) eq '/') {
463
    return -e $name?$name:undef;
464
  }
465
  #a relative path: look in xslt subfolder of staff templates
466
  my $dir= C4::Context->config('intrahtdocs').'/'.
467
	C4::Context->preference('template');
468
  #try language folder first, otherwise english
469
  my $lang=$input->cookie('KohaOpacLanguage')||'en'; #null->english
470
  my $ff= $dir.'/'.$lang.'/xslt/'.$name;
471
  return $ff if -e $ff;
472
  $ff=$dir.'/en/xslt/'.$name;
473
  return -e $ff? $ff: undef;
474
}
475
476
sub start_async_searches {
477
  my $k=0;
478
  foreach my $conn (@oConnection) {
479
    warn 'Doing search '.($k+1) if $DEBUG;
480
    if($hServer[$k]->{sru}) {
481
      $oResult[$k] = $conn->search(new ZOOM::Query::CQL(tran_query($k)));
482
    }
483
    else {
484
      $oResult[$k]=$conn->search_pqf($zquery);
485
    }
486
    $k++;
487
  }
488
}
489
490
sub loop_conn_events {
491
  my ($event, $k);
492
  while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
493
        $event = $oConnection[ $k - 1 ]->last_event();
494
        warn( "connection ", $k - 1, ": event $event (",
495
            ZOOM::event_str($event), ")\n" )
496
          if $DEBUG;
497
        last if $event == ZOOM::Event::ZEND;
498
  }
499
  return $k-1;
500
}
501
502
sub handle_conn_results {
503
  my ($breedingref, $errorref, $conn)= @_;
504
505
  warn 'Handling results for '.$hServer[$conn]->{name} if $DEBUG;
506
  my ($error, $errmsg, $addinfo, $diagset)= $oConnection[$conn]->error_x();
507
  if ($error) {
508
    if ($error =~ m/^(10000|10007)$/ ) {
509
      push(@$errorref, {'server' => $hServer[$conn]->{host} });
510
    }
511
    warn "$conn ".$hServer[$conn]->{host}.
512
	" error $zquery: $errmsg ($error) $addinfo\n";
513
    return;
514
  }
515
516
  my $numresults = $oResult[$conn]->size();
517
  warn "Number of hits: $numresults" if $DEBUG;
518
  $numresults= MAX_RESULTS if $numresults>MAX_RESULTS;
519
  for(my $i=0; $i<$numresults; $i++) {
520
    my $rec = $oResult[$conn]->record($i);
521
    if($rec) {
522
      handle_one_result($rec, $breedingref, $conn);
523
    }
524
    else {
525
      push(@$breedingref, {
526
	'server' => $hServer[$conn]->{name},
527
	'title' => join(': ',$oConnection[$conn]->error_x()),
528
	'breedingid' => -1,
529
	'biblionumber' => -1
530
      });
531
    }
532
  }
533
  $oResult[$conn]->destroy();
534
}
535
536
sub handle_one_result {
537
  my ($rec, $breedingref, $conn)= @_;
538
  my $marcrecord;
539
540
  if($hServer[$conn]->{sru}) { #SRU
541
    $marcrecord= MARC::Record->new_from_xml($rec->raw(),'UTF-8',
542
	$hServer[$conn]->{syntax});
543
  }
544
  else { #z3950
545
    ($marcrecord)= MarcToUTF8Record($rec->raw(),
546
	marcflavour_from_syntax($conn), $hServer[$conn]->{encoding});
547
  }
548
  $marcrecord->encoding('UTF-8'); #force UTF-8
549
  #convert to system marc flavour and/or additional xslt proc.
550
  $marcrecord= do_xslt_processing($conn, $marcrecord);
551
552
  #call to ImportBreeding replaced by next two calls for optimization
553
  my $batch_id = GetZ3950BatchId($hServer[$conn]->{name});
554
  my $random= $input->param('random') || rand(1000000000);
555
  my $breedingid = AddBiblioToBatch($batch_id, 0, $marcrecord, 'UTF-8',$random);
556
  #call to TransformMarcToKoha replaced by next call; we only need 6 fields
557
  #save results
558
  add_breeding($breedingref, $conn, $marcrecord, $breedingid);
559
}
560
561
sub marcflavour_from_syntax {
562
#passing USMARC to MarcToUTF8Record doesn't work; only knows MARC21/UNIMARC
563
  my $conn= shift;
564
  return 'UNIMARC' if $hServer[$conn]->{syntax}=~/UNIMARC/;
565
  return 'MARC21'; #otherwise
566
}
567
568
sub do_xslt_processing {
569
#convert marc21<->unimarc and/or additional xslt; return MARC record
570
  my ($conn, $marcrecord)= @_;
571
  my ($res, $newmarcrec, $parser, $style_doc, $stylesheet);
572
573
  if($hServer[$conn]->{marc_conv} && defined $xsltconv) {
574
    $parser = XML::LibXML->new();
575
    $res= $parser->parse_string($marcrecord->as_xml());
576
    $res= $xsltconv->transform($res);
577
    $res= $xsltconv->output_string($res);
578
    $newmarcrec= MARC::Record->new_from_xml($res, 'UTF-8');
579
  }
580
581
  if($hServer[$conn]->{add_xslt}) { #server specific xslt proc
582
    $res= $newmarcrec? $newmarcrec->as_xml(): $marcrecord->as_xml();
583
    $parser = XML::LibXML->new() unless $parser;
584
    $res= $parser->parse_string($res);
585
    my $f= full_xslt_path($hServer[$conn]->{add_xslt});
586
    $style_doc = $parser->parse_file($f) if $f;
587
    my $xslt = XML::LibXSLT->new();
588
    $stylesheet = $xslt->parse_stylesheet($style_doc) if $style_doc;
589
    if($stylesheet) {
590
      $res= $stylesheet->transform($res);
591
      $res= $stylesheet->output_string($res);
592
      $newmarcrec= MARC::Record->new_from_xml($res, 'UTF-8');
593
    }
594
    else {
595
      warn "z3950_search: XSLT problem with ".$hServer[$conn]->{add_xslt};
596
    }
597
  }
598
  return $newmarcrec // $marcrecord;
599
}
600
601
sub add_breeding {
602
  my ($breedingref, $conn, $marcrecord, $breedingid)=@_;
603
  my %row_data=();
604
  $row_data{server}       = $hServer[$conn]->{name};
605
  $row_data{breedingid}   = $breedingid;
606
  $row_data{biblionumber} = $input->param('biblionumber')||0;
607
  if($flavour ne 'UNIMARC') { #MARC21 system (not target!)
608
    $row_data{isbn} = isbn_cleanup($marcrecord->subfield('020','a')||'');
609
    $row_data{title}= $marcrecord->subfield('245','a')||'';
610
    $row_data{author}= $marcrecord->subfield('100','a')||'';
611
    $row_data{date}= $marcrecord->subfield('260','c')||'';
612
    $row_data{edition}= $marcrecord->subfield('250','a')||'';
613
    $row_data{lccn}= $marcrecord->subfield('050','a')||'';
614
  }
615
  else { #UNIMARC system (not target!)
616
    $row_data{isbn}= isbn_cleanup($marcrecord->subfield('010','a')||'');
617
    $row_data{title}= $marcrecord->subfield('200','a')||'';
618
    $row_data{author}= $marcrecord->subfield('200','f')||'';
619
    $row_data{date}= $marcrecord->subfield('210','d')||'';
620
    $row_data{edition}= $marcrecord->subfield('205','a')||'';
621
    $row_data{lccn}= '';
622
  }
623
  push( @$breedingref, \%row_data );
624
}
625
626
sub isbn_cleanup {
627
  my $isbn= shift;
628
  $isbn=~ s/ |-|\.//g;
629
  $isbn=~ s/\|/ \| /g;
630
  $isbn=~ s/\(/ \(/g;
631
  return $isbn;
632
}
633
634
sub tran_query { #translate to specific sru fields per server
635
  my ($s)= @_;
636
  #srufields is in format title=field,isbn=field,...
637
  #if a field doesn't exist, try anywhere or remove [field]=
638
  my @parts= split(',', $hServer[$s]->{srufields});
639
  my %trans= map { if(/=/){($`,$')}else{()} } @parts;
640
641
  my $q=$squery; my $any= $trans{any}?$trans{any}.'=':'';
642
  foreach my $key (keys %trans) {
643
    my $f=$trans{$key};
644
    if($f) {$q=~s/\[$key\]/$f/g; } else {$q=~s/\[$key\]=/$any/g; }
645
  }
646
  $q=~s/\[\w+\]=/$any/g; # remove remaining fields (not found in field list)
647
  warn $hServer[$s]->{name}." sru query: $q" if $DEBUG;
648
  return $q;
649
}
650
219
1;
651
1;
652
220
__END__
653
__END__
221
654
(-)a/acqui/z3950_search.pl (-261 / +59 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# This is a completely new Z3950 clients search using async ZOOM -TG 02/11/06
4
# Copyright 2000-2002 Katipo Communications
3
# Copyright 2000-2002 Katipo Communications
5
# Copyright 2010 Catalyst IT
4
# Copyright 2010 Catalyst IT
6
#
5
#
Lines 21-39 Link Here
21
20
22
use warnings;
21
use warnings;
23
use strict;
22
use strict;
23
24
use CGI;
24
use CGI;
25
25
26
use C4::Auth;
26
use C4::Auth;
27
use C4::Koha;
27
use C4::Output;
28
use C4::Output;
28
use C4::Biblio;
29
use C4::Context;
29
use C4::Context;
30
use C4::Breeding;
30
use C4::Breeding;
31
use C4::Koha;
32
use C4::Charset;
33
use C4::Bookseller qw/ GetBookSellerFromId /;
31
use C4::Bookseller qw/ GetBookSellerFromId /;
34
use ZOOM;
35
32
36
my $input        = new CGI;
33
#-------------------------------------------------------------------------------
34
35
my $input= new CGI;
37
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38
    {
37
    {
39
        template_name   => "acqui/z3950_search.tmpl",
38
        template_name   => "acqui/z3950_search.tmpl",
Lines 44-321 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
44
        debug           => 1,
43
        debug           => 1,
45
    }
44
    }
46
);
45
);
46
my $frameworkcode = $input->param('frameworkcode')||'';
47
my $vendor = GetBookSellerFromId($input->param('booksellerid')||0);
48
$template->param(
49
	frameworkcode => $frameworkcode,
50
	frameworkcodeloop => get_framework_list(),
51
	booksellerid => $input->param('booksellerid')||0,
52
	basketno => $input->param('basketno'),
53
	name => $vendor? $vendor->{'name'}: '',
54
);
47
55
48
56
my $op= $input->param('op')||'';
49
my $dbh          = C4::Context->dbh;
57
if($op ne "do_search") {
50
my $error        = $input->param('error');
58
    show_search_form();
51
my $biblionumber = $input->param('biblionumber');
59
}
52
$biblionumber = 0 unless $biblionumber;
60
else {
53
my $frameworkcode = $input->param('frameworkcode');
61
    run_search();
54
my $title         = $input->param('title');
55
my $author        = $input->param('author');
56
my $isbn          = $input->param('isbn');
57
my $issn          = $input->param('issn');
58
my $lccn          = $input->param('lccn');
59
my $lccall          = $input->param('lccall');
60
my $subject= $input->param('subject');
61
my $dewey = $input->param('dewey');
62
my $controlnumber	= $input->param('controlnumber');
63
my $op            = $input->param('op');
64
my $booksellerid = $input->param('booksellerid');
65
my $basketno = $input->param('basketno');
66
my $noconnection;
67
my $numberpending;
68
my $attr = '';
69
my $term;
70
my $host;
71
my $server;
72
my $database;
73
my $port;
74
my $marcdata;
75
my @encoding;
76
my @results;
77
my $count;
78
my $toggle;
79
my $record;
80
my $oldbiblio;
81
my $errmsg;
82
my @serverhost;
83
my @servername;
84
my @breeding_loop = ();
85
my $random        = $input->param('random');
86
unless ($random)
87
{    # this var is not useful anymore just kept to keep rel2_2 compatibility
88
    $random = rand(1000000000);
89
}
62
}
63
output_html_with_http_headers $input, $cookie, $template->output;
90
64
91
my $DEBUG = 0;    # if set to 1, many debug message are send on syslog.
65
#-------------------------------------------------------------------------------
92
66
93
# get framework list
67
sub get_framework_list {
94
my $frameworks = getframeworks;
68
  my $frameworks = getframeworks();
95
my @frameworkcodeloop;
69
  my @frameworkcodeloop;
96
foreach my $thisframeworkcode ( keys %$frameworks ) {
70
  foreach my $thisframeworkcode ( keys %$frameworks ) {
97
    my %row = (
71
    my %row = (
98
        value         => $thisframeworkcode,
72
        value         => $thisframeworkcode,
99
        frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
73
        frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
100
    );
74
    );
101
    if ( $row{'value'} eq $frameworkcode){
75
    if ($row{'value'} eq $frameworkcode) {
102
        $row{'active'} = 'true';
76
        $row{'active'} = 'true';
103
    }
77
    }
104
    push @frameworkcodeloop, \%row;
78
    push @frameworkcodeloop, \%row;
79
  }
80
  return \@frameworkcodeloop;
105
}
81
}
106
82
107
my $vendor = GetBookSellerFromId($booksellerid);
83
#-------------------------------------------------------------------------------
108
$template->param( frameworkcode => $frameworkcode, 
109
                                    frameworkcodeloop => \@frameworkcodeloop,
110
                                    booksellerid => $booksellerid,
111
                                    basketno => $basketno,
112
                                    name => $vendor->{'name'}
113
                                    );
114
                                    
115
84
116
85
sub show_search_form {
117
if ( $op ne "do_search" ) {
86
  my $dbh= C4::Context->dbh;
118
    my $sth = $dbh->prepare("select id,host,name,checked from z3950servers  order by host");
87
  my $sth = $dbh->prepare("select id,host,name,checked from z3950servers order by host");
119
    $sth->execute();
88
  $sth->execute();
120
    my $serverloop = $sth->fetchall_arrayref( {} );
89
  my $serverloop = $sth->fetchall_arrayref( {} );
121
    $template->param(
90
  $template->param(
122
        isbn         => $isbn,
91
        biblionumber => $input->param('biblionumber') || 0,
123
        issn         => $issn,
124
        lccn         => $lccn,
125
        lccall       => $lccall,
126
        title        => $title,
127
        author       => $author,
128
        controlnumber=> $controlnumber,
129
        serverloop   => $serverloop,
92
        serverloop   => $serverloop,
130
        opsearch     => "search",
93
        opsearch     => "search",
131
        biblionumber => $biblionumber,
94
        title        => $input->param('title')||'',
132
    );
95
        isbn         => $input->param('isbn')||'',
133
    output_html_with_http_headers $input, $cookie, $template->output;
96
        lccall       => $input->param('lccall')||'',
134
}
97
        controlnumber=> $input->param('controlnumber')||'',
135
else {
98
        #srchany      => $input->param('srchany')||'',
136
    my @id = $input->param('id');
99
        author       => $input->param('author')||'',
137
    my @oConnection;
100
        subject      => $input->param('subject')||'',
138
    my @oResult;
101
        dewey        => $input->param('dewey')||'',
139
    my $s = 0;
102
        #stdid        => $input->param('stdid')||'',
140
    my $query;
103
  );
141
    my $nterms;
104
  #acqui z3950 doesn't support srchany and stdid but cataloguing does
142
    if ($isbn || $issn) {
143
        $term=$isbn if ($isbn);
144
        $term=$issn if ($issn);
145
        $query .= " \@or \@attr 1=8 \"$term\" \@attr 1=7 \"$term\" ";
146
        $nterms++;
147
    }
148
    if ($title) {
149
        utf8::decode($title);
150
        $query .= " \@attr 1=4 \"$title\" ";
151
        $nterms++;
152
    }
153
    if ($author) {
154
        utf8::decode($author);
155
        $query .= " \@attr 1=1003 \"$author\" ";
156
        $nterms++;
157
    }
158
    if ($dewey) {
159
        $query .= " \@attr 1=16 \"$dewey\" ";
160
        $nterms++;
161
    }
162
    if ($subject) {
163
        utf8::decode($subject);
164
        $query .= " \@attr 1=21 \"$subject\" ";
165
        $nterms++;
166
    }
167
	if ($lccn) {	
168
        $query .= " \@attr 1=9 $lccn ";
169
        $nterms++;
170
    }
171
    if ($lccall) {
172
        $query .= " \@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" ";
173
        $nterms++;
174
    }
175
    if ($controlnumber) {
176
        $query .= " \@attr 1=12 \"$controlnumber\" ";
177
        $nterms++;
178
    }
179
for my $i (1..$nterms-1) {
180
    $query = "\@and " . $query;
181
}
105
}
182
warn "query ".$query  if $DEBUG;
183
184
    foreach my $servid (@id) {
185
        my $sth = $dbh->prepare("select * from z3950servers where id=?");
186
        $sth->execute($servid);
187
        while ( $server = $sth->fetchrow_hashref ) {
188
            warn "serverinfo ".join(':',%$server) if $DEBUG;
189
            my $noconnection = 0;
190
            my $option1      = new ZOOM::Options();
191
            $option1->option( 'async' => 1 );
192
            $option1->option( 'elementSetName', 'F' );
193
            $option1->option( 'databaseName',   $server->{db} );
194
            $option1->option( 'user', $server->{userid} ) if $server->{userid};
195
            $option1->option( 'password', $server->{password} )
196
              if $server->{password};
197
            $option1->option( 'preferredRecordSyntax', $server->{syntax} );
198
            $oConnection[$s] = create ZOOM::Connection($option1)
199
              || $DEBUG
200
              && warn( "" . $oConnection[$s]->errmsg() );
201
            warn( "server data", $server->{name}, $server->{port} ) if $DEBUG;
202
            $oConnection[$s]->connect( $server->{host}, $server->{port} )
203
              || $DEBUG
204
              && warn( "" . $oConnection[$s]->errmsg() );
205
            $serverhost[$s] = $server->{host};
206
            $servername[$s] = $server->{name};
207
            $encoding[$s]   = ($server->{encoding}?$server->{encoding}:"iso-5426");
208
            $s++;
209
        }    ## while fetch
210
    }    # foreach
211
    my $nremaining  = $s;
212
    my $firstresult = 1;
213
214
    for ( my $z = 0 ; $z < $s ; $z++ ) {
215
        warn "doing the search" if $DEBUG;
216
        $oResult[$z] = $oConnection[$z]->search_pqf($query)
217
          || $DEBUG
218
          && warn( "somthing went wrong: " . $oConnection[$s]->errmsg() );
219
220
        # $oResult[$z] = $oConnection[$z]->search_pqf($query);
221
    }
222
106
223
sub displayresults {
107
#-------------------------------------------------------------------------------
224
    my $k;
225
    my $event;
226
    while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
227
        $event = $oConnection[ $k - 1 ]->last_event();
228
        warn( "connection ", $k - 1, ": event $event (",
229
            ZOOM::event_str($event), ")\n" )
230
          if $DEBUG;
231
        last if $event == ZOOM::Event::ZEND;
232
    }
233
234
    if ( $k != 0 ) {
235
        $k--;
236
        warn $serverhost[$k] if $DEBUG;
237
        my ( $error, $errmsg, $addinfo, $diagset ) =
238
          $oConnection[$k]->error_x();
239
        if ($error) {
240
            warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n"
241
              if $DEBUG;
242
243
        }
244
        else {
245
            my $numresults = $oResult[$k]->size();
246
            my $i;
247
            my $result = '';
248
            if ( $numresults > 0 ) {
249
                for (
250
                    $i = 0 ;
251
                    $i < ( ( $numresults < 20 ) ? ($numresults) : (20) ) ;
252
                    $i++
253
                  )
254
                {
255
                    my $rec = $oResult[$k]->record($i);
256
                    if ($rec) {
257
                        my $marcrecord;
258
                        $marcdata   = $rec->raw();
259
260
                        my ($charset_result, $charset_errors);
261
                        ($marcrecord, $charset_result, $charset_errors) = 
262
                          MarcToUTF8Record($marcdata, C4::Context->preference('marcflavour'), $encoding[$k]);
263
####WARNING records coming from Z3950 clients are in various character sets MARC8,UTF8,UNIMARC etc
264
## In HEAD i change everything to UTF-8
265
# In rel2_2 i am not sure what encoding is so no character conversion is done here
266
##Add necessary encoding changes to here -TG
267
                        my $oldbiblio = TransformMarcToKoha( $dbh, $marcrecord, "" );
268
                        $oldbiblio->{isbn}   =~ s/ |-|\.//g if $oldbiblio->{isbn};
269
                        # pad | and ( with spaces to allow line breaks in the HTML
270
                        $oldbiblio->{isbn} =~ s/\|/ \| /g if $oldbiblio->{isbn};
271
                        $oldbiblio->{isbn} =~ s/\(/ \(/g if $oldbiblio->{isbn};
272
108
273
                        $oldbiblio->{issn} =~ s/ |-|\.//g if $oldbiblio->{issn};
109
sub run_search {
274
                        # pad | and ( with spaces to allow line breaks in the HTML
110
  my ($breedingref)= C4::Breeding::z3950_search($input);
275
                        $oldbiblio->{issn} =~ s/\|/ \| /g if $oldbiblio->{issn};
111
    #Code for Z3950 searching moved to C4 module -MR 06/27/11
276
                        $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn};
112
    #second return value is ignored here (not in cataloguing)
277
                          my (
113
  $template->param(
278
                            $notmarcrecord, $alreadyindb, $alreadyinfarm,
114
        breeding_loop => $breedingref,
279
                            $imported,      $breedingid
115
        biblionumber  => $input->param('biblionumber') || 0,
280
                          )
116
  );
281
                          = ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' );
282
                        my %row_data;
283
                        if ( $i % 2 ) {
284
                            $toggle = 1;
285
                        }
286
                        else {
287
                            $toggle = 0;
288
                        }
289
                        $row_data{toggle}       = $toggle;
290
                        $row_data{server}       = $servername[$k];
291
                        $row_data{isbn}         = $oldbiblio->{isbn};
292
                        $row_data{lccn}         = $oldbiblio->{lccn};
293
                        $row_data{title}        = $oldbiblio->{title};
294
                        $row_data{author}       = $oldbiblio->{author};
295
                        $row_data{breedingid}   = $breedingid;
296
                        $row_data{biblionumber} = $biblionumber;
297
                        push( @breeding_loop, \%row_data );
298
		            
299
                    } else {
300
                        push(@breeding_loop,{'toggle'=>($i % 2)?1:0,'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1});
301
                    } # $rec
302
                }    # upto 5 results
303
            }    #$numresults
304
        }
305
    }    # if $k !=0
306
    $numberpending = $nremaining - 1;
307
    $template->param(
308
        breeding_loop => \@breeding_loop,
309
        server        => $servername[$k],
310
        numberpending => $numberpending,
311
    );
312
    output_html_with_http_headers $input, $cookie, $template->output if $numberpending == 0;
313
314
    #  	print  $template->output  if $firstresult !=1;
315
    $firstresult++;
316
}
117
}
317
displayresults();
118
318
while ( --$nremaining > 0 ) {
119
#-------------------------------------------------------------------------------
319
        displayresults();
320
    }
321
}    ## if op=search
(-)a/admin/z3950servers.pl (-23 / +34 lines)
Lines 32-38 sub StringSearch { Link Here
32
	$searchstring=~ s/\'/\\\'/g;
32
	$searchstring=~ s/\'/\\\'/g;
33
	my @data=split(' ',$searchstring);
33
	my @data=split(' ',$searchstring);
34
	my $count=@data;
34
	my $count=@data;
35
	my $sth=$dbh->prepare("Select host,port,db,userid,password,name,id,checked,rank,syntax,encoding from z3950servers where (name like ?) order by rank,name");
35
	my $sth=$dbh->prepare("Select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,srufields,add_xslt from z3950servers where (name like ?) order by rank,name");
36
	$sth->execute("$data[0]\%");
36
	$sth->execute("$data[0]\%");
37
	my @results;
37
	my @results;
38
	while (my $data=$sth->fetchrow_hashref) {
38
	while (my $data=$sth->fetchrow_hashref) {
Lines 74-88 if ($op eq 'add_form') { Link Here
74
	my $data;
74
	my $data;
75
	if ($searchfield) {
75
	if ($searchfield) {
76
		my $dbh = C4::Context->dbh;
76
		my $dbh = C4::Context->dbh;
77
		my $sth=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax,encoding from z3950servers where (name = ?) order by rank,name");
77
		my $sth=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,srufields,add_xslt from z3950servers where (name = ?) order by rank,name");
78
		$sth->execute($searchfield);
78
		$sth->execute($searchfield);
79
		$data=$sth->fetchrow_hashref;
79
		$data=$sth->fetchrow_hashref;
80
		$sth->finish;
80
		$sth->finish;
81
	}
81
	}
82
    $template->param( $_ => $data->{$_} ) 
82
    $template->param( $_ => $data->{$_} ) 
83
        for ( qw( host port db userid password checked rank ) );
83
        for ( qw( host port db userid password checked rank srufields add_xslt) );
84
    $template->param( $_ . $data->{$_} => 1)
84
    $template->param( $_ . $data->{$_} => 1)
85
        for ( qw( syntax encoding ) );
85
        for ( qw( syntax encoding) );
86
													# END $OP eq ADD_FORM
86
													# END $OP eq ADD_FORM
87
################## ADD_VALIDATE ##################################
87
################## ADD_VALIDATE ##################################
88
# called by add_form, used to insert/modify data in DB
88
# called by add_form, used to insert/modify data in DB
Lines 92-98 if ($op eq 'add_form') { Link Here
92
	my $sth=$dbh->prepare("select * from z3950servers where name=?");
92
	my $sth=$dbh->prepare("select * from z3950servers where name=?");
93
	$sth->execute($input->param('searchfield'));
93
	$sth->execute($input->param('searchfield'));
94
	if ($sth->rows) {
94
	if ($sth->rows) {
95
		$sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=?,encoding=? where name=?");
95
		$sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=?,encoding=?,srufields=?,add_xslt=? where name=?");
96
		$sth->execute($input->param('host'),
96
		$sth->execute($input->param('host'),
97
		      $input->param('port'),
97
		      $input->param('port'),
98
		      $input->param('db'),
98
		      $input->param('db'),
Lines 101-127 if ($op eq 'add_form') { Link Here
101
		      $input->param('searchfield'),
101
		      $input->param('searchfield'),
102
		      $input->param('checked'),
102
		      $input->param('checked'),
103
		      $input->param('rank'),
103
		      $input->param('rank'),
104
			  $input->param('syntax'),
104
		      $input->param('syntax'),
105
              $input->param('encoding'),
105
		      $input->param('encoding'),
106
		      $input->param('srufields'),
107
		      $input->param('add_xslt'),
106
		      $input->param('searchfield'),
108
		      $input->param('searchfield'),
107
		      );
109
		      );
108
	} 
110
	} 
109
	else {
111
	else {
110
		$sth=$dbh->prepare(
112
		$sth=$dbh->prepare(
111
		  "INSERT INTO z3950servers " .
113
		  "INSERT INTO z3950servers " .
112
		  "(host,port,db,userid,password,name,checked,rank,syntax,encoding) " .
114
		  "(host,port,db,userid,password,name,checked,rank,syntax,encoding,srufields,add_xslt) " .
113
		  "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );
115
		  "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );
114
        $sth->execute(
116
		$sth->execute(
115
            $input->param( 'host' ),
117
		  $input->param( 'host' ),
116
            $input->param( 'port' ),
118
		  $input->param( 'port' ),
117
            $input->param( 'db' ),
119
		  $input->param( 'db' ),
118
            $input->param( 'userid' ),
120
		  $input->param( 'userid' ),
119
            $input->param( 'password' ),
121
		  $input->param( 'password' ),
120
            $input->param( 'searchfield' ),
122
		  $input->param( 'searchfield' ),
121
            $input->param( 'checked' ),
123
		  $input->param( 'checked' ),
122
            $input->param( 'rank' ),
124
		  $input->param( 'rank' ),
123
            $input->param( 'syntax' ),
125
		  $input->param( 'syntax' ),
124
            $input->param( 'encoding' ) );
126
		  $input->param( 'encoding' ),
127
		  $input->param( 'srufields'),
128
		  $input->param( 'add_xslt'),
129
		);
125
	}
130
	}
126
	$sth->finish;
131
	$sth->finish;
127
													# END $OP eq ADD_VALIDATE
132
													# END $OP eq ADD_VALIDATE
Lines 131-137 if ($op eq 'add_form') { Link Here
131
	$template->param(delete_confirm => 1);
136
	$template->param(delete_confirm => 1);
132
	my $dbh = C4::Context->dbh;
137
	my $dbh = C4::Context->dbh;
133
138
134
	my $sth2=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax,encoding from z3950servers where (name = ?) order by rank,name");
139
	my $sth2=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,srufields,add_xslt from z3950servers where (name = ?) order by rank,name");
135
	$sth2->execute($searchfield);
140
	$sth2->execute($searchfield);
136
	my $data=$sth2->fetchrow_hashref;
141
	my $data=$sth2->fetchrow_hashref;
137
	$sth2->finish;
142
	$sth2->finish;
Lines 144-150 if ($op eq 'add_form') { Link Here
144
                         checked => $data->{'checked'},
149
                         checked => $data->{'checked'},
145
                         rank => $data->{'rank'},
150
                         rank => $data->{'rank'},
146
                         syntax => $data->{'syntax'},
151
                         syntax => $data->{'syntax'},
147
                         encoding => $data->{'encoding'}            );
152
                         encoding => $data->{'encoding'},
153
			 srufields => $data->{srufields},
154
			 add_xslt => $data->{add_xslt},
155
	);
148
156
149
													# END $OP eq DELETE_CONFIRM
157
													# END $OP eq DELETE_CONFIRM
150
################## DELETE_CONFIRMED ##################################
158
################## DELETE_CONFIRMED ##################################
Lines 174-180 if ($op eq 'add_form') { Link Here
174
			checked => $results->[$i]{'checked'},
182
			checked => $results->[$i]{'checked'},
175
			rank => $results->[$i]{'rank'},
183
			rank => $results->[$i]{'rank'},
176
			syntax => $results->[$i]{'syntax'},
184
			syntax => $results->[$i]{'syntax'},
177
      encoding => $results->[$i]{'encoding'});
185
			encoding => $results->[$i]{'encoding'},
186
			srufields => $results->[$i]{srufields},
187
			add_xslt => $results->[$i]{add_xslt},
188
		);
178
		push @loop, \%row;
189
		push @loop, \%row;
179
190
180
	}
191
	}
(-)a/cataloguing/z3950_search.pl (-255 / +42 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# This is a completely new Z3950 clients search using async ZOOM -TG 02/11/06
4
# Copyright 2000-2002 Katipo Communications
3
# Copyright 2000-2002 Katipo Communications
5
#
4
#
6
# This file is part of Koha.
5
# This file is part of Koha.
Lines 19-76 Link Here
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
19
21
use strict;
20
use strict;
22
#use warnings; FIXME - Bug 2505
21
use warnings;
22
23
use CGI;
23
use CGI;
24
24
25
use C4::Auth;
25
use C4::Auth;
26
use C4::Output;
26
use C4::Output;
27
use C4::Biblio;
28
use C4::Context;
27
use C4::Context;
29
use C4::Breeding;
28
use C4::Breeding;
30
use C4::Koha;
31
use C4::Charset;
32
use ZOOM;
33
34
my $input        = new CGI;
35
my $dbh          = C4::Context->dbh;
36
my $error         = $input->param('error');
37
my $biblionumber  = $input->param('biblionumber') || 0;
38
my $frameworkcode = $input->param('frameworkcode');
39
my $title         = $input->param('title');
40
my $author        = $input->param('author');
41
my $isbn          = $input->param('isbn');
42
my $issn          = $input->param('issn');
43
my $lccn          = $input->param('lccn');
44
my $lccall        = $input->param('lccall');
45
my $subject       = $input->param('subject');
46
my $dewey         = $input->param('dewey');
47
my $controlnumber	= $input->param('controlnumber');
48
my $stdid			= $input->param('stdid');
49
my $srchany			= $input->param('srchany');
50
my $random        = $input->param('random') || rand(1000000000); # this var is not useful anymore just kept for rel2_2 compatibility
51
my $op            = $input->param('op');
52
my $numberpending;
53
my $attr = '';
54
my $term;
55
my $host;
56
my $server;
57
my $database;
58
my $port;
59
my $marcdata;
60
my @encoding;
61
my @results;
62
my $count;
63
my $record;
64
my $oldbiblio;
65
my $errmsg;
66
my @serverloop = ();
67
my @serverhost;
68
my @servername;
69
my @breeding_loop = ();
70
29
71
my $DEBUG = 0;    # if set to 1, many debug message are send on syslog.
30
#-------------------------------------------------------------------------------
72
31
73
my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
32
my $input= new CGI;
33
my ($template, $loggedinuser, $cookie ) = get_template_and_user({
74
        template_name   => "cataloguing/z3950_search.tmpl",
34
        template_name   => "cataloguing/z3950_search.tmpl",
75
        query           => $input,
35
        query           => $input,
76
        type            => "intranet",
36
        type            => "intranet",
Lines 78-299 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ Link Here
78
        flagsrequired   => { catalogue => 1 },
38
        flagsrequired   => { catalogue => 1 },
79
        debug           => 1,
39
        debug           => 1,
80
});
40
});
41
$template->param( frameworkcode => $input->param('frameworkcode')||'' );
81
42
82
$template->param( frameworkcode => $frameworkcode, );
43
my $op= $input->param('op')||'';
83
44
if($op ne "do_search") {
84
if ( $op ne "do_search" ) {
45
    show_search_form();
85
    my $sth = $dbh->prepare("select id,host,name,checked from z3950servers  order by host");
86
    $sth->execute();
87
    my $serverloop = $sth->fetchall_arrayref( {} );
88
    $template->param(
89
        isbn         => $isbn,
90
        issn         => $issn,
91
        lccn         => $lccn,
92
        lccall       => $lccall,
93
        title        => $title,
94
        author       => $author,
95
        controlnumber=> $controlnumber,
96
        stdid			=> $stdid,
97
        srchany		=> $srchany,
98
        serverloop   => $serverloop,
99
        opsearch     => "search",
100
        biblionumber => $biblionumber,
101
    );
102
    output_html_with_http_headers $input, $cookie, $template->output;
103
}
46
}
104
else {
47
else {
105
    my @id = $input->param('id');
48
    run_search();
106
107
    if ( not defined @id ) {
108
        # empty server list -> report and exit
109
        $template->param( emptyserverlist => 1 );
110
        output_html_with_http_headers $input, $cookie, $template->output;
111
        exit;
112
    }
113
114
    my @oConnection;
115
    my @oResult;
116
    my @errconn;
117
    my $s = 0;
118
    my $query;
119
    my $nterms;
120
    if ($isbn || $issn) {
121
        $term=$isbn if ($isbn);
122
        $term=$issn if ($issn);
123
        $query .= " \@or \@attr 1=8 \"$term\" \@attr 1=7 \"$term\" ";
124
        $nterms++;
125
    }
126
    if ($title) {
127
        utf8::decode($title);
128
        $query .= " \@attr 1=4 \"$title\" ";
129
        $nterms++;
130
    }
131
    if ($author) {
132
        utf8::decode($author);
133
        $query .= " \@attr 1=1003 \"$author\" ";
134
        $nterms++;
135
    }
136
    if ($dewey) {
137
        $query .= " \@attr 1=16 \"$dewey\" ";
138
        $nterms++;
139
    }
140
    if ($subject) {
141
        utf8::decode($subject);
142
        $query .= " \@attr 1=21 \"$subject\" ";
143
        $nterms++;
144
    }
145
	if ($lccn) {	
146
        $query .= " \@attr 1=9 $lccn ";
147
        $nterms++;
148
    }
149
    if ($lccall) {
150
        $query .= " \@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" ";
151
        $nterms++;
152
    }
153
    if ($controlnumber) {
154
        $query .= " \@attr 1=12 \"$controlnumber\" ";
155
        $nterms++;
156
    }
157
    if ($stdid) {
158
        $query .= " \@attr 1=1007 \"$stdid\" ";
159
        $nterms++;
160
    }
161
    if ($srchany) {
162
        $query .= " \@attr 1=1016 \"$srchany\" ";
163
        $nterms++;
164
    }
165
for my $i (1..$nterms-1) {
166
    $query = "\@and " . $query;
167
}
49
}
168
warn "query ".$query  if $DEBUG;
50
output_html_with_http_headers $input, $cookie, $template->output;
169
170
    foreach my $servid (@id) {
171
        my $sth = $dbh->prepare("select * from z3950servers where id=?");
172
        $sth->execute($servid);
173
        while ( $server = $sth->fetchrow_hashref ) {
174
            warn "serverinfo ".join(':',%$server) if $DEBUG;
175
            my $option1      = new ZOOM::Options();
176
            $option1->option('async' => 1);
177
            $option1->option('elementSetName', 'F');
178
            $option1->option('databaseName', $server->{db});
179
            $option1->option('user',         $server->{userid}  ) if $server->{userid};
180
            $option1->option('password',     $server->{password}) if $server->{password};
181
            $option1->option('preferredRecordSyntax', $server->{syntax});
182
            $oConnection[$s] = create ZOOM::Connection($option1)
183
              || $DEBUG
184
              && warn( "" . $oConnection[$s]->errmsg() );
185
            warn( "server data", $server->{name}, $server->{port} ) if $DEBUG;
186
            $oConnection[$s]->connect( $server->{host}, $server->{port} )
187
              || $DEBUG
188
              && warn( "" . $oConnection[$s]->errmsg() );
189
            $serverhost[$s] = $server->{host};
190
            $servername[$s] = $server->{name};
191
            $encoding[$s]   = ($server->{encoding}?$server->{encoding}:"iso-5426");
192
            $s++;
193
        }    ## while fetch
194
    }    # foreach
195
    my $nremaining  = $s;
196
    my $firstresult = 1;
197
51
198
    for ( my $z = 0 ; $z < $s ; $z++ ) {
52
#-------------------------------------------------------------------------------
199
        warn "doing the search" if $DEBUG;
200
        $oResult[$z] = $oConnection[$z]->search_pqf($query)
201
          || $DEBUG
202
          && warn( "somthing went wrong: " . $oConnection[$s]->errmsg() );
203
53
204
        # $oResult[$z] = $oConnection[$z]->search_pqf($query);
54
sub show_search_form {
205
    }
55
  my $dbh= C4::Context->dbh;
206
56
  my $sth= $dbh->prepare("select id,host,name,checked from z3950servers order by host");
207
  AGAIN:
57
  $sth->execute();
208
    my $k;
58
  my $serverloop = $sth->fetchall_arrayref( {} );
209
    my $event;
59
  $template->param(
210
    while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
60
        biblionumber => $input->param('biblionumber') || 0,
211
        $event = $oConnection[ $k - 1 ]->last_event();
61
        serverloop   => $serverloop,
212
        warn( "connection ", $k - 1, ": event $event (",
62
        opsearch     => "search",
213
            ZOOM::event_str($event), ")\n" )
63
        title        => $input->param('title')||'',
214
          if $DEBUG;
64
        isbn         => $input->param('isbn')||'',
215
        last if $event == ZOOM::Event::ZEND;
65
        lccall       => $input->param('lccall')||'',
216
    }
66
        controlnumber=> $input->param('controlnumber')||'',
217
67
        srchany      => $input->param('srchany')||'',
218
    if ( $k != 0 ) {
68
        author       => $input->param('author')||'',
219
        $k--;
69
        subject      => $input->param('subject')||'',
220
        warn $serverhost[$k] if $DEBUG;
70
        dewey        => $input->param('dewey')||'',
221
        my ( $error, $errmsg, $addinfo, $diagset ) =
71
        stdid        => $input->param('stdid')||'',
222
          $oConnection[$k]->error_x();
72
  );
223
        if ($error) {
73
}
224
            if ($error =~ m/^(10000|10007)$/ ) {
225
                push(@errconn, {'server' => $serverhost[$k]});
226
            }
227
            $DEBUG and warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n";
228
        }
229
        else {
230
            my $numresults = $oResult[$k]->size();
231
            my $i;
232
            my $result = '';
233
            if ( $numresults > 0 ) {
234
                for ($i = 0; $i < (($numresults < 20) ? $numresults : 20); $i++) {
235
                    my $rec = $oResult[$k]->record($i);
236
                    if ($rec) {
237
                        my $marcrecord;
238
                        $marcdata   = $rec->raw();
239
240
                        my ($charset_result, $charset_errors);
241
                        ($marcrecord, $charset_result, $charset_errors) = 
242
                          MarcToUTF8Record($marcdata, C4::Context->preference('marcflavour'), $encoding[$k]);
243
####WARNING records coming from Z3950 clients are in various character sets MARC8,UTF8,UNIMARC etc
244
## In HEAD i change everything to UTF-8
245
# In rel2_2 i am not sure what encoding is so no character conversion is done here
246
##Add necessary encoding changes to here -TG
247
                        my $oldbiblio = TransformMarcToKoha( $dbh, $marcrecord, "" );
248
                        $oldbiblio->{isbn}   =~ s/ |-|\.//g if $oldbiblio->{isbn};
249
                        # pad | and ( with spaces to allow line breaks in the HTML
250
                        $oldbiblio->{isbn} =~ s/\|/ \| /g if $oldbiblio->{isbn};
251
                        $oldbiblio->{isbn} =~ s/\(/ \(/g if $oldbiblio->{isbn};
252
74
253
                        $oldbiblio->{issn} =~ s/ |-|\.//g if $oldbiblio->{issn};
75
#-------------------------------------------------------------------------------
254
                        # pad | and ( with spaces to allow line breaks in the HTML
255
                        $oldbiblio->{issn} =~ s/\|/ \| /g if $oldbiblio->{issn};
256
                        $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn};
257
                          my (
258
                            $notmarcrecord, $alreadyindb, $alreadyinfarm,
259
                            $imported,      $breedingid
260
                          )
261
                          = ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' );
262
                        my %row_data;
263
                        $row_data{server}       = $servername[$k];
264
                        $row_data{isbn}         = $oldbiblio->{isbn};
265
                        $row_data{lccn}         = $oldbiblio->{lccn};
266
                        $row_data{title}        = $oldbiblio->{title};
267
                        $row_data{author}       = $oldbiblio->{author};
268
                        $row_data{date}         = $oldbiblio->{copyrightdate};
269
                        $row_data{edition}      = $oldbiblio->{editionstatement};
270
                        $row_data{breedingid}   = $breedingid;
271
                        $row_data{biblionumber} = $biblionumber;
272
                        push( @breeding_loop, \%row_data );
273
		            
274
                    } else {
275
                        push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1});
276
                    } # $rec
277
                }
278
            }    #$numresults
279
        }
280
    }    # if $k !=0
281
    $numberpending = $nremaining - 1;
282
    $template->param(
283
        breeding_loop => \@breeding_loop,
284
        server        => $servername[$k],
285
        numberpending => $numberpending,
286
        biblionumber  => $biblionumber,
287
        errconn       => \@errconn
288
    );
289
    
290
    output_html_with_http_headers $input, $cookie, $template->output if $numberpending == 0;
291
76
292
    #  	print  $template->output  if $firstresult !=1;
77
sub run_search {
293
    $firstresult++;
78
  my ($breedingref, $error_ref)= C4::Breeding::z3950_search($input);
79
  $template->param(
80
        breeding_loop => $breedingref,
81
        biblionumber  => $input->param('biblionumber') || 0,
82
        errconn       => $error_ref,
83
  );
84
}
294
85
295
  MAYBE_AGAIN:
86
#-------------------------------------------------------------------------------
296
    if ( --$nremaining > 0 ) {
297
        goto AGAIN;
298
    }
299
}    ## if op=search
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt (+2 lines)
Lines 226-231 Link Here
226
[% END %]
226
[% END %]
227
</select>
227
</select>
228
</li>
228
</li>
229
	<li><label for="srufields">SRU Fields: </label><input type="text" size="80" name="srufields" id="srufields" value="[% srufields %]"/></li>
230
	<li><label for="add_xslt">Additional XSLT: </label><input type="text" size="40" name="add_xslt" id="add_xslt" value="[% add_xslt %]"/></li>
229
</ol>
231
</ol>
230
        </fieldset>
232
        </fieldset>
231
		
233
		
(-)a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21toUNIMARC.xsl (+1187 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
Copyright 2011 BibLibre.
4
This file is part of Koha.
5
Koha is free software; you can redistribute it and/or modify it under the
6
terms of the GNU General Public License as published by the Free Software
7
Foundation; either version 2 of the License, or (at your option) any later
8
version.
9
Koha is distributed in the hope that it will be useful, but WITHOUT ANY
10
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11
A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License along
13
with Koha; if not, write to the Free Software Foundation, Inc.,
14
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15
-->
16
<xsl:stylesheet xmlns:marc="http://www.loc.gov/MARC21/slim" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
17
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
18
	<xsl:template match="/">
19
		<collection>
20
            <xsl:for-each select="marc:record">
21
			<record
22
				xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23
				xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/ standards/marcxml/schema/MARC21slim.xsd"
24
				xmlns="http://www.loc.gov/MARC21/slim">
25
				<xsl:variable name="leader" select="leader" />
26
				<leader>
27
					<!-- A calculer, mais comment ? -->
28
					<xsl:variable name="len">00000</xsl:variable>
29
					<xsl:variable name="stat">
30
						<xsl:choose>
31
							<xsl:when test="substring(leader,6,1) = 'a'">p</xsl:when>
32
							<xsl:otherwise><xsl:value-of select="substring(leader,6,1)" /></xsl:otherwise>
33
						</xsl:choose>
34
					</xsl:variable>
35
					<xsl:variable name="type">
36
						<xsl:choose>
37
							<xsl:when test="substring(leader,7,1) = 'o'">m</xsl:when>
38
							<xsl:when test="substring(leader,7,1) = 'r'">n</xsl:when>
39
							<xsl:otherwise><xsl:value-of select="substring(leader,7,1)" /></xsl:otherwise>
40
						</xsl:choose>
41
					</xsl:variable>
42
					<xsl:variable name="biblvl">
43
						<xsl:choose>
44
							<xsl:when test="substring(leader,8,1) = 'b'">m</xsl:when>
45
							<xsl:when test="substring(leader,8,1) = 'd'">m</xsl:when>
46
							<xsl:otherwise><xsl:value-of select="substring(leader,8,1)" /></xsl:otherwise>
47
						</xsl:choose>
48
					</xsl:variable>
49
					<!-- A calculer, mais comment ? -->
50
					<xsl:variable name="baod">00000</xsl:variable>
51
					<xsl:variable name="enclvl">
52
						<xsl:choose>
53
							<xsl:when test="substring(leader,18,1) = '8'">2</xsl:when>
54
							<xsl:when test="substring(leader,17,1) = '5'">3</xsl:when>
55
							<xsl:when test="substring(leader,18,1) = '7'">3</xsl:when>
56
							<xsl:otherwise><xsl:value-of select="substring(leader,18,1)" /></xsl:otherwise>
57
						</xsl:choose>
58
					</xsl:variable>
59
					<xsl:variable name="dcf">
60
						<xsl:choose>
61
							<xsl:when test="substring(leader,19,1) = ' '">n</xsl:when>
62
							<xsl:otherwise><xsl:value-of select="' '" /></xsl:otherwise>
63
						</xsl:choose>
64
					</xsl:variable>
65
					<xsl:value-of select="concat($len,$stat,$type,$biblvl,'  22',$baod,$enclvl,$dcf,' 45  ')" />
66
				</leader>
67
				<xsl:for-each select="marc:controlfield[@tag='001']">
68
					<controlfield tag="001"><xsl:value-of select="text()" /></controlfield>
69
				</xsl:for-each>
70
				<xsl:for-each select="marc:controlfield[@tag='005']">
71
					<controlfield tag="005"><xsl:value-of select="text()" /></controlfield>
72
				</xsl:for-each>
73
				<xsl:for-each select="marc:controlfield[@tag='008']">
74
					<!-- FIXME: Dummy indicators -->
75
					<datafield tag="100">
76
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
77
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
78
						<subfield code="a">
79
						<xsl:variable name="deof">
80
							<xsl:choose>
81
								<xsl:when test="substring(text(),1,2) &lt; 70">
82
									<xsl:value-of select="concat('20',substring(text(),1,6))" />
83
								</xsl:when>
84
								<xsl:otherwise>
85
									<xsl:value-of select="concat('19',substring(text(),1,6))" />
86
								</xsl:otherwise>
87
							</xsl:choose>
88
						</xsl:variable>
89
						<xsl:variable name="topd" select="substring(text(),7,1)" />
90
						<xsl:variable name="d1" select="substring(text(),8,4)" />
91
						<xsl:variable name="d2" select="substring(text(),12,4)" />
92
						<xsl:variable name="il">
93
							<xsl:choose>
94
								<xsl:when test="substring(text(),23,1) = 'a'">b||</xsl:when>
95
								<xsl:when test="substring(text(),23,1) = 'b'">c||</xsl:when>
96
								<xsl:when test="substring(text(),23,1) = 'j'">a||</xsl:when>
97
								<xsl:when test="substring(text(),23,1) = 'c'">d||</xsl:when>
98
								<xsl:when test="substring(text(),23,1) = 'd'">e||</xsl:when>
99
								<xsl:when test="substring(text(),23,1) = 'e'">k||</xsl:when>
100
								<xsl:when test="substring(text(),23,1) = 'g'">m||</xsl:when>
101
								<xsl:when test="substring(text(),23,1) = '|'">|||</xsl:when>
102
								<xsl:when test="substring(text(),23,1) = ' '">u||</xsl:when>
103
								<xsl:otherwise>u||</xsl:otherwise>
104
							</xsl:choose>
105
						</xsl:variable>
106
						<xsl:variable name="gpc">
107
							<xsl:choose>
108
								<xsl:when test="substring(text(),29,1) = 'f'">a</xsl:when>
109
								<xsl:when test="substring(text(),29,1) = 's'">b</xsl:when>
110
								<xsl:when test="substring(text(),29,1) = 'l'">d</xsl:when>
111
								<xsl:when test="substring(text(),29,1) = 'c'">e</xsl:when>
112
								<xsl:when test="substring(text(),29,1) = 'i'">f</xsl:when>
113
								<xsl:when test="substring(text(),29,1) = 'z'">g</xsl:when>
114
								<xsl:when test="substring(text(),29,1) = 'o'">h</xsl:when>
115
								<xsl:when test="substring(text(),29,1) = 'u'">u</xsl:when>
116
								<xsl:when test="substring(text(),29,1) = ' '">y</xsl:when>
117
								<xsl:when test="substring(text(),29,1) = 'z'">z</xsl:when>
118
								<xsl:when test="substring(text(),29,1) = '|'">|</xsl:when>
119
								<xsl:otherwise>y</xsl:otherwise>
120
							</xsl:choose>
121
						</xsl:variable>
122
						<xsl:variable name="mrc">
123
							<xsl:choose>
124
								<xsl:when test="substring(text(),39,1) = ' '">0</xsl:when>
125
								<xsl:otherwise>1</xsl:otherwise>
126
							</xsl:choose>
127
						</xsl:variable>
128
						<xsl:variable name="loc">
129
							<xsl:choose>
130
								<xsl:when test="datafield[@tag='040']/subfield[@code='b']"><xsl:value-of select="marc:datafield[@tag='040']/subfield[@code='b']" /></xsl:when>
131
								<xsl:otherwise><xsl:value-of select="'   '" /></xsl:otherwise>
132
							</xsl:choose>
133
						</xsl:variable>
134
						<xsl:variable name="tc">
135
							<xsl:choose>
136
								<xsl:when test="substring(text(),39,1) = 'o'">b</xsl:when>
137
								<xsl:otherwise>y</xsl:otherwise>
138
							</xsl:choose>
139
						</xsl:variable>
140
						<!-- Demander à nicomo pour les 2 variables suivantes -->
141
						<xsl:variable name="cs"><xsl:value-of select="'    '" /></xsl:variable>
142
						<xsl:variable name="acs"><xsl:value-of select="'    '" /></xsl:variable>
143
						<xsl:variable name="aot" select="substring(text(),34,1)" />
144
						<xsl:value-of select="concat($deof,$topd,$d1,$d2,$il,$gpc,$mrc,$loc,$tc,$cs,$acs,$aot)" />
145
						</subfield>
146
					</datafield>
147
					<datafield tag="105">
148
						<!-- Difficile de faire un bel algo pour les deux variables suivantes -->
149
						<subfield code="a">
150
						<xsl:variable name="ic"><xsl:value-of select="'    '" /></xsl:variable>
151
						<xsl:variable name="focc"><xsl:value-of select="'    '" /></xsl:variable>
152
						<xsl:variable name="cc"><xsl:value-of select="substring(text(),30,1)" /></xsl:variable>
153
						<xsl:variable name="fi"><xsl:value-of select="substring(text(),31,1)" /></xsl:variable>
154
						<xsl:variable name="ii"><xsl:value-of select="substring(text(),32,1)" /></xsl:variable>
155
						<xsl:variable name="lc">
156
							<xsl:choose>
157
								<xsl:when test="substring(text(),34,1) = '1'">a</xsl:when>
158
								<xsl:otherwise>|</xsl:otherwise>
159
							</xsl:choose>
160
						</xsl:variable>
161
						<xsl:variable name="bc">
162
							<xsl:choose>
163
								<xsl:when test="substring(text(),35,1) = ' '">y</xsl:when>
164
								<xsl:otherwise><xsl:value-of select="substring(text(),35,1)" /></xsl:otherwise>
165
							</xsl:choose>
166
						</xsl:variable>
167
						<xsl:value-of select="concat($ic,$focc,$cc,$fi,$ii,$lc,$bc)" />
168
						</subfield>
169
					</datafield>
170
					<datafield tag="106">
171
					    <subfield code="a">
172
						<xsl:choose>
173
							<xsl:when test="substring(text(),24,1) = ' '">y</xsl:when>
174
							<xsl:otherwise><xsl:value-of select="substring(text(),24,1)" /></xsl:otherwise>
175
						</xsl:choose>
176
					    </subfield>
177
					</datafield>
178
					<datafield tag="110">
179
					    <subfield code="a">
180
						<xsl:variable name="tos">
181
							<xsl:choose>
182
								<xsl:when test="substring(text(),22,1) = 'p'">a</xsl:when>
183
								<xsl:when test="substring(text(),22,1) = 'm'">b</xsl:when>
184
								<xsl:when test="substring(text(),22,1) = 'n'">c</xsl:when>
185
								<xsl:when test="substring(text(),22,1) = ' '">z</xsl:when>
186
								<xsl:when test="substring(text(),22,1) = '|'">|</xsl:when>
187
								<xsl:otherwise>z</xsl:otherwise>
188
							</xsl:choose>
189
						</xsl:variable>
190
						<xsl:variable name="foi">
191
							<xsl:choose>
192
								<xsl:when test="substring(text(),19,1) = 'd'">a</xsl:when>
193
								<xsl:when test="substring(text(),19,1) = 'c'">b</xsl:when>
194
								<xsl:when test="substring(text(),19,1) = 'w'">c</xsl:when>
195
								<xsl:when test="substring(text(),19,1) = 'e'">d</xsl:when>
196
								<xsl:when test="substring(text(),19,1) = 's'">e</xsl:when>
197
								<xsl:when test="substring(text(),19,1) = 'm'">f</xsl:when>
198
								<xsl:when test="substring(text(),19,1) = 'b'">g</xsl:when>
199
								<xsl:when test="substring(text(),19,1) = 'q'">h</xsl:when>
200
								<xsl:when test="substring(text(),19,1) = 't'">i</xsl:when>
201
								<xsl:when test="substring(text(),19,1) = 'f'">j</xsl:when>
202
								<xsl:when test="substring(text(),19,1) = 'a'">k</xsl:when>
203
								<xsl:when test="substring(text(),19,1) = 'g'">l</xsl:when>
204
								<xsl:when test="substring(text(),19,1) = 'h'">m</xsl:when>
205
								<xsl:when test="substring(text(),19,1) = 'i'">n</xsl:when>
206
								<xsl:when test="substring(text(),19,1) = 'j'">o</xsl:when>
207
								<xsl:when test="substring(text(),19,1) = 'u'">u</xsl:when>
208
								<xsl:when test="substring(text(),19,1) = ' '">y</xsl:when>
209
								<xsl:when test="substring(text(),19,1) = 'z'">z</xsl:when>
210
								<xsl:when test="substring(text(),19,1) = '|'">|</xsl:when>
211
								<xsl:when test="substring(text(),19,1) = 'n'">|</xsl:when>
212
								<xsl:otherwise>y</xsl:otherwise>
213
							</xsl:choose>
214
						</xsl:variable>
215
						<xsl:variable name="r">
216
							<xsl:choose>
217
								<xsl:when test="substring(text(),20,1) = 'r'">a</xsl:when>
218
								<xsl:when test="substring(text(),20,1) = 'n'">b</xsl:when>
219
								<xsl:when test="substring(text(),20,1) = 'u'">u</xsl:when>
220
								<xsl:when test="substring(text(),20,1) = 'x'">y</xsl:when>
221
								<xsl:when test="substring(text(),20,1) = '|'">|</xsl:when>
222
								<xsl:when test="substring(text(),20,1) = ' '">|</xsl:when>
223
								<xsl:otherwise>u</xsl:otherwise>
224
							</xsl:choose>
225
						</xsl:variable>
226
						<xsl:variable name="tomc">
227
							<xsl:choose>
228
								<xsl:when test="substring(text(),25,1) = 'b'">a</xsl:when>
229
								<xsl:when test="substring(text(),25,1) = 'c'">b</xsl:when>
230
								<xsl:when test="substring(text(),25,1) = 'i'">c</xsl:when>
231
								<xsl:when test="substring(text(),25,1) = 'a'">d</xsl:when>
232
								<xsl:when test="substring(text(),25,1) = 'd'">e</xsl:when>
233
								<xsl:when test="substring(text(),25,1) = 'e'">f</xsl:when>
234
								<xsl:when test="substring(text(),25,1) = 'r'">g</xsl:when>
235
								<xsl:when test="substring(text(),25,1) = 'y'">h</xsl:when>
236
								<xsl:when test="substring(text(),25,1) = 's'">i</xsl:when>
237
								<xsl:when test="substring(text(),25,1) = 'p'">j</xsl:when>
238
								<xsl:when test="substring(text(),25,1) = 'o'">k</xsl:when>
239
								<xsl:when test="substring(text(),25,1) = 'l'">l</xsl:when>
240
								<xsl:when test="substring(text(),25,1) = 'w'">m</xsl:when>
241
								<xsl:when test="substring(text(),25,1) = 'g'">n</xsl:when>
242
								<xsl:when test="substring(text(),25,1) = 'v'">o</xsl:when>
243
								<xsl:when test="substring(text(),25,1) = 'h'">p</xsl:when>
244
								<xsl:when test="substring(text(),25,1) = 'n'">r</xsl:when>
245
								<xsl:when test="substring(text(),25,1) = ' '">z</xsl:when>
246
								<xsl:when test="substring(text(),25,1) = '|'">|</xsl:when>
247
								<xsl:otherwise>z</xsl:otherwise>
248
							</xsl:choose>
249
						</xsl:variable>
250
						<xsl:variable name="nocc"><xsl:value-of select="substring(text(),26,3)" /></xsl:variable>
251
						<xsl:variable name="ci"><xsl:value-of select="substring(text(),30,1)" /></xsl:variable>
252
						<xsl:variable name="tpa">|</xsl:variable>
253
						<xsl:variable name="iac">|</xsl:variable>
254
						<xsl:variable name="cia">|</xsl:variable>
255
						<xsl:value-of select="concat($tos,$foi,$r,$tomc,$nocc,$ci,$tpa,$iac,$cia)" />
256
					    </subfield>
257
					</datafield>
258
				</xsl:for-each>
259
				<xsl:for-each select="marc:datafield[@tag='020']">
260
					<datafield tag="010">
261
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
262
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
263
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
264
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
265
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
266
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
267
					</datafield>
268
				</xsl:for-each>
269
				<xsl:for-each select="marc:datafield[@tag='022']">
270
					<datafield tag="011">
271
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
272
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
273
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
274
					<!--<xsl:for-each select="marc:subfield[@code='?']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
275
					<!--<xsl:for-each select="marc:subfield[@code='?']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
276
						<xsl:for-each select="marc:subfield[@code='y']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
277
					<!--<xsl:for-each select="marc:subfield[@code='z']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
278
					</datafield>
279
				</xsl:for-each>
280
			<!--<xsl:for-each select="marc:datafield[@tag='024']">
281
					<datafield tag="012">
282
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
283
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
284
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>
285
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>
286
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>
287
					</datafield>
288
				</xsl:for-each>-->
289
				<xsl:for-each select="marc:datafield[@tag='015']">
290
					<datafield tag="020">
291
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
292
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
293
						<xsl:for-each select="marc:subfield[@code='2']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
294
						<xsl:for-each select="marc:subfield[@code='a']">
295
							<subfield code="b"><xsl:value-of select="text()" /></subfield>
296
							<subfield code="z"><xsl:value-of select="text()" /></subfield>
297
						</xsl:for-each>
298
					</datafield>
299
				</xsl:for-each>
300
				<xsl:for-each select="marc:datafield[@tag='017']">
301
					<datafield tag="021">
302
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
303
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
304
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
305
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
306
					</datafield>
307
				</xsl:for-each>
308
				<xsl:for-each select="marc:datafield[@tag='086']">
309
					<datafield tag="22">
310
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
311
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
312
						<xsl:for-each select="marc:subfield[@code='2']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
313
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
314
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
315
					</datafield>
316
				</xsl:for-each>
317
				<xsl:for-each select="marc:datafield[@tag='030']">
318
					<datafield tag="040">
319
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
320
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
321
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
322
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
323
					</datafield>
324
				</xsl:for-each>
325
				<xsl:for-each select="marc:datafield[@tag='028']">
326
					<datafield tag="071">
327
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
328
						<xsl:attribute name="ind2">
329
							<xsl:choose>
330
								<xsl:when test="@ind2 = 0">0</xsl:when>
331
								<xsl:otherwise>1</xsl:otherwise>
332
							</xsl:choose>
333
						</xsl:attribute>
334
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
335
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
336
					</datafield>
337
				</xsl:for-each>
338
				<xsl:for-each select="marc:datafield[@tag='041']">
339
					<datafield tag="101">
340
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
341
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
342
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
343
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
344
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
345
						<xsl:for-each select="marc:subfield[@code='e']"><subfield code="h"><xsl:value-of select="text()" /></subfield></xsl:for-each>
346
						<xsl:for-each select="marc:subfield[@code='f']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
347
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="i"><xsl:value-of select="text()" /></subfield></xsl:for-each>
348
						<xsl:for-each select="marc:subfield[@code='h']"><subfield code="c"><xsl:value-of select="text()" /></subfield></xsl:for-each>
349
					</datafield>
350
				</xsl:for-each>
351
				<xsl:for-each select="marc:datafield[@tag='044']">
352
					<datafield tag="102">
353
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
354
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
355
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
356
					<!--<xsl:for-each select="marc:subfield[@code='b']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
357
					</datafield>
358
				</xsl:for-each>
359
				<xsl:for-each select="marc:datafield[@tag='245']">
360
					<datafield tag="200">
361
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
362
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
363
						<xsl:for-each select="marc:subfield[@code='a']">
364
							<subfield code="a"><xsl:value-of select="text()" /></subfield>
365
							<xsl:if test="contains(text(),' = ')">
366
								<subfield code="d"><xsl:value-of select="concat('=',substring-after(text(),' =' ))" /></subfield>
367
							</xsl:if>
368
						</xsl:for-each>
369
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
370
						<xsl:for-each select="marc:subfield[@code='c']">
371
							<xsl:choose>
372
								<xsl:when test="contains(text(),' / ')">
373
									<subfield code="f"><xsl:value-of select="substring-before(text(),' / ')" /></subfield>
374
									<subfield code="g"><xsl:value-of select="substring-after(text(),' / ')" /></subfield>
375
								</xsl:when>
376
								<xsl:otherwise>
377
									<subfield code="f"><xsl:value-of select="text()" /></subfield>
378
								</xsl:otherwise>
379
							</xsl:choose>
380
						</xsl:for-each>
381
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="h"><xsl:value-of select="text()" /></subfield></xsl:for-each>
382
						<xsl:for-each select="marc:subfield[@code='p']"><subfield code="i"><xsl:value-of select="text()" /></subfield></xsl:for-each>
383
					</datafield>
384
					<!-- FIXME -->
385
					<!--
386
					<datafield tag="204">
387
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
388
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
389
						<xsl:for-each select="marc:subfield[@code='h']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
390
					</datafield>
391
					-->
392
				</xsl:for-each>
393
				<xsl:for-each select="marc:datafield[@tag='250']">
394
					<datafield tag="205">
395
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
396
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
397
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
398
					</datafield>
399
				</xsl:for-each>
400
				<xsl:for-each select="marc:datafield[@tag='254']">
401
					<datafield tag="208">
402
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
403
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
404
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
405
					</datafield>
406
				</xsl:for-each>
407
				<xsl:for-each select="marc:datafield[@tag='260']">
408
					<datafield tag="210">
409
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
410
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
411
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
412
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="c"><xsl:value-of select="text()" /></subfield></xsl:for-each>
413
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
414
						<xsl:for-each select="marc:subfield[@code='e']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
415
						<xsl:for-each select="marc:subfield[@code='f']"><subfield code="g"><xsl:value-of select="text()" /></subfield></xsl:for-each>
416
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="h"><xsl:value-of select="text()" /></subfield></xsl:for-each>
417
					</datafield>
418
				</xsl:for-each>
419
				<xsl:for-each select="marc:datafield[@tag='263']">
420
					<datafield tag="211">
421
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
422
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
423
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
424
					</datafield>
425
				</xsl:for-each>
426
				<xsl:for-each select="marc:datafield[@tag='300']">
427
					<datafield tag="215">
428
						<xsl:choose>
429
							<xsl:when test="@ind = 1"><xsl:attribute name="ind1">0</xsl:attribute></xsl:when>
430
							<xsl:otherwise><xsl:attribute name="ind1">1</xsl:attribute></xsl:otherwise>
431
						</xsl:choose>
432
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
433
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
434
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="c"><xsl:value-of select="text()" /></subfield></xsl:for-each>
435
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
436
						<xsl:for-each select="marc:subfield[@code='e']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
437
					</datafield>
438
				</xsl:for-each>
439
				<xsl:for-each select="marc:datafield[@tag='490']">
440
					<datafield tag="225">
441
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
442
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
443
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
444
						<xsl:for-each select="marc:subfield[@code='v']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
445
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
446
					</datafield>
447
				</xsl:for-each>
448
				<xsl:for-each select="marc:datafield[@tag='256']">
449
					<datafield tag="230">
450
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
451
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
452
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
453
					</datafield>
454
				</xsl:for-each>
455
				<xsl:for-each select="marc:datafield[@tag='500']">
456
					<datafield tag="300">
457
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
458
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
459
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
460
					</datafield>
461
				</xsl:for-each>
462
				<xsl:for-each select="marc:datafield[@tag='525']">
463
					<datafield tag="300">
464
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
465
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
466
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
467
					</datafield>
468
				</xsl:for-each>
469
				<xsl:for-each select="marc:datafield[@tag='555']">
470
					<datafield tag="300">
471
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
472
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
473
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
474
					</datafield>
475
				</xsl:for-each>
476
				<xsl:for-each select="marc:datafield[@tag='504']">
477
					<datafield tag="320">
478
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
479
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
480
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
481
					</datafield>
482
				</xsl:for-each>
483
				<xsl:for-each select="marc:datafield[@tag='505']">
484
					<datafield tag="327">
485
					    <!-- FIXME: Dummy indicators -->
486
						<!--<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>-->
487
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
488
						<!--<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>-->
489
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
490
						<subfield code="a">bla</subfield>
491
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
492
					</datafield>
493
				</xsl:for-each>
494
				<xsl:for-each select="marc:datafield[@tag='502']">
495
					<datafield tag="328">
496
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
497
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
498
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
499
					</datafield>
500
				</xsl:for-each>
501
				<xsl:for-each select="marc:datafield[@tag='520']">
502
					<datafield tag="330">
503
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
504
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
505
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
506
					</datafield>
507
				</xsl:for-each>
508
				<xsl:for-each select="marc:datafield[@tag='524']">
509
					<datafield tag="332">
510
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
511
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
512
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
513
					</datafield>
514
				</xsl:for-each>
515
				<xsl:for-each select="marc:datafield[@tag='521']">
516
					<datafield tag="333">
517
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
518
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
519
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
520
					</datafield>
521
				</xsl:for-each>
522
				<xsl:for-each select="marc:datafield[@tag='500']">
523
					<datafield tag="336">
524
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
525
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
526
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
527
					</datafield>
528
				</xsl:for-each>
529
				<xsl:for-each select="marc:datafield[@tag='538']">
530
					<datafield tag="337">
531
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
532
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
533
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
534
					</datafield>
535
				</xsl:for-each>
536
				<xsl:for-each select="marc:datafield[@tag='037']">
537
					<datafield tag="345">
538
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
539
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
540
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
541
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
542
						<xsl:for-each select="marc:subfield[@code='f']"><subfield code="c"><xsl:value-of select="text()" /></subfield></xsl:for-each>
543
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
544
					</datafield>
545
				</xsl:for-each>
546
				<xsl:for-each select="marc:datafield[@tag='760']">
547
					<datafield tag="410">
548
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
549
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
550
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
551
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
552
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
553
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
554
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
555
					</datafield>
556
				</xsl:for-each>
557
				<xsl:for-each select="marc:datafield[@tag='762']">
558
					<datafield tag="411">
559
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
560
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
561
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
562
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
563
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
564
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
565
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
566
					</datafield>
567
				</xsl:for-each>
568
				<xsl:for-each select="marc:datafield[@tag='770']">
569
					<datafield tag="421">
570
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
571
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
572
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
573
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
574
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
575
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
576
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
577
					</datafield>
578
				</xsl:for-each>
579
				<xsl:for-each select="marc:datafield[@tag='772']">
580
					<datafield tag="422">
581
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
582
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
583
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
584
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
585
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
586
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
587
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
588
					</datafield>
589
				</xsl:for-each>
590
				<xsl:for-each select="marc:datafield[@tag='777']">
591
					<datafield tag="423">
592
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
593
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
594
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
595
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
596
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
597
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
598
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
599
					</datafield>
600
				</xsl:for-each>
601
				<xsl:for-each select="marc:datafield[@tag='780']">
602
					<datafield tag="430">
603
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
604
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
605
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
606
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
607
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
608
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
609
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
610
					</datafield>
611
				</xsl:for-each>
612
				<xsl:for-each select="marc:datafield[@tag='785']">
613
					<datafield tag="440">
614
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
615
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
616
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
617
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
618
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
619
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
620
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
621
					</datafield>
622
				</xsl:for-each>
623
				<xsl:for-each select="marc:datafield[@tag='775']">
624
					<datafield tag="451">
625
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
626
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
627
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
628
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
629
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
630
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
631
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
632
					</datafield>
633
				</xsl:for-each>
634
				<xsl:for-each select="marc:datafield[@tag='776']">
635
					<datafield tag="452">
636
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
637
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
638
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
639
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
640
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
641
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
642
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
643
					</datafield>
644
				</xsl:for-each>
645
				<xsl:for-each select="marc:datafield[@tag='767']">
646
					<datafield tag="453">
647
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
648
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
649
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
650
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
651
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
652
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
653
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
654
					</datafield>
655
				</xsl:for-each>
656
				<xsl:for-each select="marc:datafield[@tag='765']">
657
					<datafield tag="454">
658
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
659
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
660
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
661
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
662
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
663
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
664
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
665
					</datafield>
666
				</xsl:for-each>
667
				<xsl:for-each select="marc:datafield[@tag='787']">
668
					<datafield>
669
						<xsl:choose>
670
							<xsl:when test="contains(subfield[@code='i'],'Reproduction of:')"><xsl:attribute name="tag" select="455" /></xsl:when>
671
							<xsl:when test="contains(subfield[@code='i'],'Reproduced as:')"><xsl:attribute name="tag" select="456" /></xsl:when>
672
							<xsl:when test="contains(subfield[@code='i'],'Item reviewed:')"><xsl:attribute name="tag" select="470" /></xsl:when>
673
							<xsl:otherwise>
674
								<xsl:attribute name="tag" select="488" />
675
							</xsl:otherwise>
676
						</xsl:choose>
677
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
678
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
679
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
680
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
681
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
682
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
683
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
684
					</datafield>
685
				</xsl:for-each>
686
				<xsl:for-each select="marc:datafield[@tag='774']">
687
					<datafield>
688
						<xsl:choose>
689
							<xsl:when test="subfield[@code='i']">
690
								<xsl:attribute name="tag" select="462" />
691
							</xsl:when>
692
							<xsl:otherwise>
693
								<xsl:attribute name="tag" select="461" />
694
							</xsl:otherwise>
695
						</xsl:choose>
696
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
697
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
698
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
699
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
700
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
701
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
702
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
703
					</datafield>
704
				</xsl:for-each>
705
				<xsl:for-each select="marc:datafield[@tag='773']">
706
					<datafield tag="463">
707
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
708
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
709
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
710
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
711
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
712
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
713
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
714
					</datafield>
715
				</xsl:for-each>
716
				<xsl:for-each select="marc:datafield[@tag='774']">
717
					<datafield tag="464">
718
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
719
						<xsl:attribute name="ind2"><xsl:value-of select="@ind1" /></xsl:attribute>
720
						<xsl:for-each select="marc:subfield[@code='w']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>
721
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
722
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
723
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
724
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
725
					</datafield>
726
				</xsl:for-each>
727
				<xsl:for-each select="marc:datafield[@tag='730']">
728
					<datafield tag="500">
729
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
730
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
731
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
732
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="n"><xsl:value-of select="text()" /></subfield></xsl:for-each>
733
						<xsl:for-each select="marc:subfield[@code='f']"><subfield code="k"><xsl:value-of select="text()" /></subfield></xsl:for-each>
734
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="n"><xsl:value-of select="text()" /></subfield></xsl:for-each>
735
						<xsl:for-each select="marc:subfield[@code='k']"><subfield code="j"><xsl:value-of select="text()" /></subfield></xsl:for-each>
736
						<xsl:for-each select="marc:subfield[@code='l']"><subfield code="m"><xsl:value-of select="text()" /></subfield></xsl:for-each>
737
						<xsl:for-each select="marc:subfield[@code='m']"><subfield code="r"><xsl:value-of select="text()" /></subfield></xsl:for-each>
738
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="h"><xsl:value-of select="text()" /></subfield></xsl:for-each>
739
						<xsl:for-each select="marc:subfield[@code='o']"><subfield code="w"><xsl:value-of select="text()" /></subfield></xsl:for-each>
740
						<xsl:for-each select="marc:subfield[@code='p']"><subfield code="i"><xsl:value-of select="text()" /></subfield></xsl:for-each>
741
						<xsl:for-each select="marc:subfield[@code='r']"><subfield code="u"><xsl:value-of select="text()" /></subfield></xsl:for-each>
742
						<xsl:for-each select="marc:subfield[@code='s']"><subfield code="q"><xsl:value-of select="text()" /></subfield></xsl:for-each>
743
					</datafield>
744
				</xsl:for-each>
745
				<xsl:for-each select="marc:datafield[@tag='243']">
746
					<datafield tag="501">
747
						<xsl:attribute name="ind1">1</xsl:attribute>
748
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
749
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
750
						<xsl:for-each select="marc:subfield[@code='k']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
751
						<xsl:for-each select="marc:subfield[@code='f']"><subfield code="k"><xsl:value-of select="text()" /></subfield></xsl:for-each>
752
						<xsl:for-each select="marc:subfield[@code='l']"><subfield code="m"><xsl:value-of select="text()" /></subfield></xsl:for-each>
753
					</datafield>
754
				</xsl:for-each>
755
				<xsl:for-each select="marc:datafield[@tag='247']">
756
					<datafield tag="520">
757
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
758
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
759
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
760
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
761
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="h"><xsl:value-of select="text()" /></subfield></xsl:for-each>
762
						<xsl:for-each select="marc:subfield[@code='p']"><subfield code="i"><xsl:value-of select="text()" /></subfield></xsl:for-each>
763
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="n"><xsl:value-of select="text()" /></subfield></xsl:for-each>
764
						<xsl:for-each select="marc:subfield[@code='f']"><subfield code="j"><xsl:value-of select="text()" /></subfield></xsl:for-each>
765
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
766
					</datafield>
767
				</xsl:for-each>
768
				<xsl:for-each select="marc:datafield[@tag='222']">
769
					<datafield tag="530">
770
						<xsl:attribute name="ind1">0</xsl:attribute>
771
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
772
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
773
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
774
					</datafield>
775
				</xsl:for-each>
776
				<xsl:for-each select="marc:datafield[@tag='210']">
777
					<datafield tag="531">
778
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
779
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
780
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
781
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
782
					</datafield>
783
				</xsl:for-each>
784
				<xsl:for-each select="marc:datafield[@tag='246']">
785
					<datafield tag="532">
786
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
787
						<xsl:attribute name="ind2">0</xsl:attribute>
788
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
789
					</datafield>
790
				</xsl:for-each>
791
				<xsl:for-each select="marc:datafield[@tag='242']">
792
					<datafield tag="541">
793
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
794
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
795
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
796
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
797
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="h"><xsl:value-of select="text()" /></subfield></xsl:for-each>
798
						<xsl:for-each select="marc:subfield[@code='p']"><subfield code="i"><xsl:value-of select="text()" /></subfield></xsl:for-each>
799
						<xsl:for-each select="marc:subfield[@code='y']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
800
					</datafield>
801
				</xsl:for-each>
802
				<xsl:for-each select="marc:datafield[@tag='773']">
803
					<datafield tag="545">
804
						<xsl:attribute name="ind1">
805
							<xsl:choose>
806
								<xsl:when test="@ind1 = 0">1</xsl:when>
807
								<xsl:otherwise>0</xsl:otherwise>
808
							</xsl:choose>
809
						</xsl:attribute>
810
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
811
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
812
					</datafield>
813
				</xsl:for-each>
814
				<xsl:for-each select="marc:datafield[@tag='610']">
815
					<datafield tag="601">
816
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
817
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
818
						<xsl:for-each select="marc:subfield[@code='a']">
819
							<subfield code="a"><xsl:value-of select="text()" /></subfield>
820
							<subfield code="c"><xsl:value-of select="substring-before(substring-after(text(),'('),')')" /></subfield>
821
						</xsl:for-each>
822
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
823
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
824
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="f"><xsl:value-of select="text()" /></subfield></xsl:for-each>
825
						<xsl:for-each select="marc:subfield[@code='e']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
826
					<!--<xsl:for-each select="marc:subfield[@code='f']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
827
					<!--<xsl:for-each select="marc:subfield[@code='g']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
828
						<xsl:for-each select="marc:subfield[@code='k']"><subfield code="j"><xsl:value-of select="text()" /></subfield></xsl:for-each>
829
					<!--<xsl:for-each select="marc:subfield[@code='l']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
830
					<!--<xsl:for-each select="marc:subfield[@code='m']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
831
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
832
					<!--<xsl:for-each select="marc:subfield[@code='o']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
833
					<!--<xsl:for-each select="marc:subfield[@code='p']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
834
					<!--<xsl:for-each select="marc:subfield[@code='r']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
835
					<!--<xsl:for-each select="marc:subfield[@code='s']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
836
					<!--<xsl:for-each select="marc:subfield[@code='t']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
837
					<!--<xsl:for-each select="marc:subfield[@code='u']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
838
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
839
						<xsl:for-each select="marc:subfield[@code='y']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
840
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
841
					<!--<xsl:for-each select="marc:subfield[@code='?']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
842
					</datafield>
843
				</xsl:for-each>
844
				<xsl:for-each select="marc:datafield[@tag='611']">
845
					<datafield tag="601">
846
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
847
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
848
						<xsl:for-each select="marc:subfield[@code='a']">
849
							<subfield code="a"><xsl:value-of select="text()" /></subfield>
850
							<subfield code="c"><xsl:value-of select="substring-before(substring-after(text(),'('),')')" /></subfield>
851
						</xsl:for-each>
852
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
853
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="f"><xsl:value-of select="text()" /></subfield></xsl:for-each>
854
						<xsl:for-each select="marc:subfield[@code='e']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
855
					<!--<xsl:for-each select="marc:subfield[@code='f']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
856
					<!--<xsl:for-each select="marc:subfield[@code='g']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
857
						<xsl:for-each select="marc:subfield[@code='k']"><subfield code="j"><xsl:value-of select="text()" /></subfield></xsl:for-each>
858
					<!--<xsl:for-each select="marc:subfield[@code='l']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
859
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
860
					<!--<xsl:for-each select="marc:subfield[@code='p']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
861
					<!--<xsl:for-each select="marc:subfield[@code='s']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
862
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
863
					<!--<xsl:for-each select="marc:subfield[@code='u']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
864
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
865
						<xsl:for-each select="marc:subfield[@code='y']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
866
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
867
					<!--<xsl:for-each select="marc:subfield[@code='?']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
868
					</datafield>
869
				</xsl:for-each>
870
				<xsl:for-each select="marc:datafield[@tag='630']">
871
					<datafield tag="605">
872
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
873
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
874
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
875
					<!--<xsl:for-each select="marc:subfield[@code='d']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
876
						<xsl:for-each select="marc:subfield[@code='f']"><subfield code="k"><xsl:value-of select="text()" /></subfield></xsl:for-each>
877
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="n"><xsl:value-of select="text()" /></subfield></xsl:for-each>
878
						<xsl:for-each select="marc:subfield[@code='k']"><subfield code="j"><xsl:value-of select="text()" /></subfield></xsl:for-each>
879
						<xsl:for-each select="marc:subfield[@code='l']"><subfield code="m"><xsl:value-of select="text()" /></subfield></xsl:for-each>
880
						<xsl:for-each select="marc:subfield[@code='m']"><subfield code="r"><xsl:value-of select="text()" /></subfield></xsl:for-each>
881
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="h"><xsl:value-of select="text()" /></subfield></xsl:for-each>
882
						<xsl:for-each select="marc:subfield[@code='o']"><subfield code="w"><xsl:value-of select="text()" /></subfield></xsl:for-each>
883
						<xsl:for-each select="marc:subfield[@code='p']"><subfield code="i"><xsl:value-of select="text()" /></subfield></xsl:for-each>
884
						<xsl:for-each select="marc:subfield[@code='r']"><subfield code="u"><xsl:value-of select="text()" /></subfield></xsl:for-each>
885
						<xsl:for-each select="marc:subfield[@code='s']"><subfield code="q"><xsl:value-of select="text()" /></subfield></xsl:for-each>
886
					<!--<xsl:for-each select="marc:subfield[@code='t']"><subfield code="?"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
887
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
888
						<xsl:for-each select="marc:subfield[@code='y']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
889
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
890
					<!--<xsl:for-each select="marc:subfield[@code='?']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
891
					</datafield>
892
				</xsl:for-each>
893
				<xsl:for-each select="marc:datafield[@tag='600']">
894
					<datafield tag="600">
895
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
896
						<xsl:attribute name="ind2">
897
							<xsl:choose>
898
								<xsl:when test="@ind1 = 0">0</xsl:when>
899
								<xsl:otherwise>1</xsl:otherwise>
900
							</xsl:choose>
901
						</xsl:attribute>
902
						<xsl:for-each select="marc:subfield[@code='a']">
903
							<subfield code="a"><xsl:value-of select="substring-before(text(),', ')" /></subfield>
904
							<subfield code="b"><xsl:value-of select="substring-after(text(),', ')" /></subfield>
905
						</xsl:for-each>
906
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="c"><xsl:value-of select="text()" /></subfield></xsl:for-each>
907
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
908
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="f"><xsl:value-of select="text()" /></subfield></xsl:for-each>
909
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
910
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
911
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
912
						<xsl:for-each select="marc:subfield[@code='y']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
913
						<xsl:for-each select="marc:subfield[@code='2']"><subfield code="2"><xsl:value-of select="text()" /></subfield></xsl:for-each>
914
					</datafield>
915
					<datafield tag="602">
916
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
917
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
918
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
919
						<xsl:for-each select="marc:subfield[@code='t']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
920
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
921
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
922
						<xsl:for-each select="marc:subfield[@code='y']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
923
						<xsl:for-each select="marc:subfield[@code='2']"><subfield code="2"><xsl:value-of select="text()" /></subfield></xsl:for-each>
924
					</datafield>
925
				</xsl:for-each>
926
				<xsl:for-each select="marc:datafield[@tag='630']">
927
					<datafield tag="605">
928
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
929
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
930
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
931
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="h"><xsl:value-of select="text()" /></subfield></xsl:for-each>
932
						<xsl:for-each select="marc:subfield[@code='p']"><subfield code="i"><xsl:value-of select="text()" /></subfield></xsl:for-each>
933
						<xsl:for-each select="marc:subfield[@code='f']"><subfield code="k"><xsl:value-of select="text()" /></subfield></xsl:for-each>
934
						<xsl:for-each select="marc:subfield[@code='k']"><subfield code="l"><xsl:value-of select="text()" /></subfield></xsl:for-each>
935
						<xsl:for-each select="marc:subfield[@code='l']"><subfield code="m"><xsl:value-of select="text()" /></subfield></xsl:for-each>
936
						<xsl:for-each select="marc:subfield[@code='g']"><subfield code="n"><xsl:value-of select="text()" /></subfield></xsl:for-each>
937
						<xsl:for-each select="marc:subfield[@code='s']"><subfield code="q"><xsl:value-of select="text()" /></subfield></xsl:for-each>
938
						<xsl:for-each select="marc:subfield[@code='r']"><subfield code="r"><xsl:value-of select="text()" /></subfield></xsl:for-each>
939
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="s"><xsl:value-of select="text()" /></subfield></xsl:for-each>
940
						<xsl:for-each select="marc:subfield[@code='o']"><subfield code="t"><xsl:value-of select="text()" /></subfield></xsl:for-each>
941
						<xsl:for-each select="marc:subfield[@code='r']"><subfield code="u"><xsl:value-of select="text()" /></subfield></xsl:for-each>
942
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
943
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
944
						<xsl:for-each select="marc:subfield[@code='y']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
945
						<xsl:for-each select="marc:subfield[@code='2']"><subfield code="2"><xsl:value-of select="text()" /></subfield></xsl:for-each>
946
					</datafield>
947
				</xsl:for-each>
948
				<xsl:for-each select="marc:datafield[@tag='650']">
949
					<datafield tag="606">
950
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
951
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
952
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
953
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
954
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
955
						<xsl:for-each select="marc:subfield[@code='y']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
956
						<xsl:for-each select="marc:subfield[@code='2']"><subfield code="2"><xsl:value-of select="text()" /></subfield></xsl:for-each>
957
					</datafield>
958
				</xsl:for-each>
959
				<xsl:for-each select="marc:datafield[@tag='651']">
960
					<datafield tag="607">
961
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
962
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
963
						<xsl:for-each select="marc:subfield[@code='a']">
964
							<subfield code="a"><xsl:value-of select="substring-before(text(),', ')" /></subfield>
965
							<subfield code="b"><xsl:value-of select="substring-after(text(),', ')" /></subfield>
966
						</xsl:for-each>
967
						<xsl:for-each select="marc:subfield[@code='x']"><subfield code="x"><xsl:value-of select="text()" /></subfield></xsl:for-each>
968
						<xsl:for-each select="marc:subfield[@code='z']"><subfield code="y"><xsl:value-of select="text()" /></subfield></xsl:for-each>
969
						<xsl:for-each select="marc:subfield[@code='y']"><subfield code="z"><xsl:value-of select="text()" /></subfield></xsl:for-each>
970
						<xsl:for-each select="marc:subfield[@code='2']"><subfield code="2"><xsl:value-of select="text()" /></subfield></xsl:for-each>
971
					</datafield>
972
				</xsl:for-each>
973
				<xsl:for-each select="marc:datafield[@tag='653']">
974
					<datafield tag="610">
975
						<xsl:attribute name="ind1">
976
							<xsl:choose>
977
								<xsl:when test="@ind1 = ' '">0</xsl:when>
978
								<xsl:otherwise><xsl:value-of select="@ind1" /></xsl:otherwise>
979
							</xsl:choose>
980
						</xsl:attribute>
981
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
982
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
983
					</datafield>
984
				</xsl:for-each>
985
				<xsl:for-each select="marc:datafield[@tag='752']">
986
					<datafield tag="620">
987
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
988
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
989
						<xsl:for-each select="marc:subfield"><subfield code="@code"><xsl:value-of select="text()" /></subfield></xsl:for-each>
990
					</datafield>
991
				</xsl:for-each>
992
				<xsl:for-each select="marc:datafield[@tag='753']">
993
					<datafield tag="626">
994
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
995
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
996
						<xsl:for-each select="marc:subfield"><subfield code="@code"><xsl:value-of select="text()" /></subfield></xsl:for-each>
997
					</datafield>
998
				</xsl:for-each>
999
				<xsl:for-each select="marc:datafield[@tag='043']">
1000
					<datafield tag="660">
1001
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1002
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
1003
						<xsl:for-each select="marc:subfield"><subfield code="@code"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1004
					</datafield>
1005
				</xsl:for-each>
1006
				<xsl:for-each select="marc:datafield[@tag='045']">
1007
					<datafield tag="661">
1008
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1009
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
1010
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1011
					</datafield>
1012
				</xsl:for-each>
1013
				<xsl:for-each select="marc:datafield[@tag='886']">
1014
					<datafield tag="670">
1015
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1016
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
1017
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1018
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="c"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1019
						<xsl:for-each select="marc:subfield[@code='2']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1020
					</datafield>
1021
				</xsl:for-each>
1022
				<xsl:for-each select="marc:datafield[@tag='080']">
1023
					<datafield tag="675">
1024
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1025
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
1026
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1027
					</datafield>
1028
				</xsl:for-each>
1029
				<xsl:for-each select="marc:datafield[@tag='082']">
1030
					<datafield tag="676">
1031
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1032
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
1033
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1034
						<xsl:for-each select="marc:subfield[@code='2']"><subfield code="v"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1035
					</datafield>
1036
				</xsl:for-each>
1037
				<xsl:for-each select="marc:datafield[@tag='050']">
1038
					<datafield tag="680">
1039
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1040
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
1041
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1042
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1043
					</datafield>
1044
				</xsl:for-each>
1045
				<xsl:for-each select="marc:datafield[@tag='084']">
1046
					<datafield tag="686">
1047
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1048
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
1049
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1050
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1051
						<xsl:for-each select="marc:subfield[@code='2']"><subfield code="2"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1052
					</datafield>
1053
				</xsl:for-each>
1054
				<xsl:for-each select="marc:datafield[@tag='100']">
1055
					<datafield tag="700">
1056
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1057
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
1058
						<xsl:for-each select="marc:subfield[@code='a']">
1059
							<subfield code="a"><xsl:value-of select="substring-before(text(),', ')" /></subfield>
1060
							<subfield code="b"><xsl:value-of select="substring-after(text(),', ')" /></subfield>
1061
						</xsl:for-each>
1062
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1063
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="c"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1064
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="f"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1065
						<xsl:for-each select="marc:subfield[@code='e']"><subfield code="4"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1066
						<xsl:for-each select="marc:subfield[@code='q']"><subfield code="g"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1067
						<xsl:for-each select="marc:subfield[@code='u']"><subfield code="p"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1068
					<!--<xsl:for-each select="marc:subfield[@code='?']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
1069
						<xsl:for-each select="marc:subfield[@code='4']"><subfield code="4"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1070
					</datafield>
1071
				</xsl:for-each>
1072
				<xsl:for-each select="marc:datafield[@tag='700']">
1073
					<datafield tag="701">
1074
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1075
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
1076
						<xsl:for-each select="marc:subfield[@code='a']">
1077
							<subfield code="a"><xsl:value-of select="substring-before(text(),', ')" /></subfield>
1078
							<subfield code="b"><xsl:value-of select="substring-after(text(),', ')" /></subfield>
1079
						</xsl:for-each>
1080
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1081
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="c"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1082
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="f"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1083
						<xsl:for-each select="marc:subfield[@code='e']"><subfield code="4"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1084
						<xsl:for-each select="marc:subfield[@code='q']"><subfield code="g"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1085
						<xsl:for-each select="marc:subfield[@code='u']"><subfield code="p"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1086
					<!--<xsl:for-each select="marc:subfield[@code='?']"><subfield code="3"><xsl:value-of select="text()" /></subfield></xsl:for-each>-->
1087
						<xsl:for-each select="marc:subfield[@code='4']"><subfield code="4"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1088
					</datafield>
1089
				</xsl:for-each>
1090
				<xsl:for-each select="marc:datafield[@tag='110']">
1091
					<datafield tag="710">
1092
						<xsl:attribute name="ind1">0</xsl:attribute>
1093
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
1094
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1095
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1096
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1097
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1098
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="f"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1099
						<xsl:for-each select="marc:subfield[@code='u']"><subfield code="p"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1100
						<xsl:for-each select="marc:subfield[@code='4']"><subfield code="4"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1101
					</datafield>
1102
				</xsl:for-each>
1103
				<xsl:for-each select="marc:datafield[@tag='111']">
1104
					<datafield tag="710">
1105
						<xsl:attribute name="ind1">1</xsl:attribute>
1106
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
1107
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1108
						<xsl:for-each select="marc:subfield[@code='e']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1109
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1110
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1111
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="f"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1112
						<xsl:for-each select="marc:subfield[@code='u']"><subfield code="p"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1113
						<xsl:for-each select="marc:subfield[@code='4']"><subfield code="4"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1114
					</datafield>
1115
				</xsl:for-each>
1116
				<xsl:for-each select="marc:datafield[@tag='710']">
1117
					<datafield tag="711">
1118
						<xsl:attribute name="ind1">0</xsl:attribute>
1119
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
1120
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1121
						<xsl:for-each select="marc:subfield[@code='b']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1122
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1123
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1124
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="f"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1125
						<xsl:for-each select="marc:subfield[@code='u']"><subfield code="p"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1126
						<xsl:for-each select="marc:subfield[@code='4']"><subfield code="4"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1127
					</datafield>
1128
				</xsl:for-each>
1129
				<xsl:for-each select="marc:datafield[@tag='711']">
1130
					<datafield tag="711">
1131
						<xsl:attribute name="ind1">1</xsl:attribute>
1132
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
1133
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1134
						<xsl:for-each select="marc:subfield[@code='e']"><subfield code="b"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1135
						<xsl:for-each select="marc:subfield[@code='n']"><subfield code="d"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1136
						<xsl:for-each select="marc:subfield[@code='c']"><subfield code="e"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1137
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="f"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1138
						<xsl:for-each select="marc:subfield[@code='u']"><subfield code="p"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1139
						<xsl:for-each select="marc:subfield[@code='4']"><subfield code="4"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1140
					</datafield>
1141
				</xsl:for-each>
1142
				<xsl:for-each select="marc:datafield[@tag='100']">
1143
					<datafield tag="720">
1144
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1145
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
1146
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1147
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="f"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1148
						<xsl:for-each select="marc:subfield[@code='4']"><subfield code="4"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1149
					</datafield>
1150
				</xsl:for-each>
1151
				<xsl:for-each select="marc:datafield[@tag='700']">
1152
					<datafield tag="721">
1153
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1154
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
1155
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1156
						<xsl:for-each select="marc:subfield[@code='d']"><subfield code="f"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1157
						<xsl:for-each select="marc:subfield[@code='4']"><subfield code="4"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1158
					</datafield>
1159
				</xsl:for-each>
1160
				<xsl:for-each select="marc:controlfield[@tag='008']">
1161
					<datafield tag="802">
1162
						<xsl:attribute name="ind1"><xsl:value-of select="' '" /></xsl:attribute>
1163
						<xsl:attribute name="ind2"><xsl:value-of select="' '" /></xsl:attribute>
1164
						<subfield code="a">
1165
							<xsl:choose>
1166
								<xsl:when test="substring(text(),21,1) = '0'">00</xsl:when>
1167
								<xsl:when test="substring(text(),21,1) = '1'">01</xsl:when>
1168
								<xsl:when test="substring(text(),21,1) = '4'">04</xsl:when>
1169
								<xsl:when test="substring(text(),21,1) = '#'">uu</xsl:when>
1170
								<xsl:when test="substring(text(),21,1) = 'z'">zz</xsl:when>
1171
								<xsl:otherwise>zz</xsl:otherwise>
1172
							</xsl:choose>
1173
						</subfield>
1174
					</datafield>
1175
				</xsl:for-each>
1176
				<xsl:for-each select="marc:datafield[@tag='590']">
1177
					<datafield tag="900">
1178
						<xsl:attribute name="ind1"><xsl:value-of select="@ind1" /></xsl:attribute>
1179
						<xsl:attribute name="ind2"><xsl:value-of select="@ind2" /></xsl:attribute>
1180
						<xsl:for-each select="marc:subfield[@code='a']"><subfield code="a"><xsl:value-of select="text()" /></subfield></xsl:for-each>
1181
					</datafield>
1182
				</xsl:for-each>
1183
			</record>
1184
		</xsl:for-each>
1185
		</collection>
1186
	</xsl:template>
1187
</xsl:stylesheet>
(-)a/koha-tmpl/intranet-tmpl/prog/en/xslt/UNIMARCtoMARC21.xsl (-1 / +523 lines)
Line 0 Link Here
0
- 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
Copyright 2011 Rijksmuseum.
4
This file is part of Koha.
5
Koha is free software; you can redistribute it and/or modify it under the
6
terms of the GNU General Public License as published by the Free Software
7
Foundation; either version 2 of the License, or (at your option) any later
8
version.
9
Koha is distributed in the hope that it will be useful, but WITHOUT ANY
10
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11
A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License along
13
with Koha; if not, write to the Free Software Foundation, Inc.,
14
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15
-->
16
<!--
17
NOTE: This stylesheet converts UNIMARC to MARC21.
18
IMPORTANT: Please note that MARC21 and UNIMARC are different in restrictions
19
for tags and subfields to be repeatable. In this stylesheet this difference
20
implies the careful use of if and value-of on one side and for-each and copy-of
21
on the other side!!
22
FIXME: Currently, it only converts the most important MARC fields. Add more!
23
-->
24
<xsl:stylesheet xmlns:marc="http://www.loc.gov/MARC21/slim" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
25
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
26
  <xsl:template match="/">
27
    <collection>
28
    <xsl:apply-templates/>
29
    </collection>
30
  </xsl:template>
31
32
  <xsl:template match="marc:record">
33
   <record>
34
    <xsl:call-template name="leader"/>
35
    <xsl:call-template name="copy_control">
36
      <xsl:with-param name="tagno">001</xsl:with-param>
37
    </xsl:call-template>
38
    <xsl:call-template name="control005"/>
39
    <xsl:call-template name="control008"/>
40
41
    <xsl:call-template name="isbn_issn"/>
42
    <xsl:call-template name="author"/>
43
    <xsl:call-template name="author_corp"/>
44
    <xsl:call-template name="title"/>
45
    <xsl:call-template name="edition"/>
46
    <xsl:call-template name="publication"/>
47
    <xsl:call-template name="physicaldesc"/>
48
    <xsl:call-template name="note_general"/>
49
    <xsl:call-template name="subject_person"/>
50
    <xsl:call-template name="subject_topic"/>
51
    <xsl:call-template name="subject_geo"/>
52
    <xsl:call-template name="subject_uncontrolled"/>
53
    <xsl:call-template name="pers_name"/>
54
    <xsl:call-template name="corp_name"/>
55
   </record>
56
  </xsl:template>
57
58
  <!-- Named templates -->
59
60
  <xsl:template name="leader">
61
    <xsl:variable name="leader" select="marc:leader"/>
62
    <leader>
63
    <xsl:text>00000na</xsl:text>
64
    <xsl:choose>
65
      <xsl:when test="contains('cms',substring($leader,8,1))">
66
        <xsl:value-of select="substring($leader,8,1)"/>
67
      </xsl:when>
68
      <xsl:otherwise><xsl:text>m</xsl:text></xsl:otherwise>
69
    </xsl:choose>
70
    <xsl:text> a2200000u</xsl:text>
71
    <xsl:choose>
72
      <xsl:when test="contains('i ',substring($leader,19,1))">
73
        <xsl:text>i</xsl:text>
74
      </xsl:when>
75
      <xsl:when test="substring($leader,19,1)='n'">
76
        <xsl:text> </xsl:text>
77
      </xsl:when>
78
      <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
79
    </xsl:choose>
80
    <xsl:text> 4500</xsl:text>
81
    </leader>
82
  </xsl:template>
83
84
  <xsl:template name="control005">
85
    <xsl:choose>
86
      <xsl:when test="marc:controlfield[@tag='005']">
87
        <xsl:copy-of select="marc:controlfield[@tag='005']"/>
88
      </xsl:when>
89
      <xsl:otherwise>
90
        <xsl:if test="marc:datafield[@tag='801']/marc:subfield[@code='c']">
91
        <controlfield tag="005">
92
          <xsl:value-of select="marc:datafield[@tag='801']/marc:subfield[@code='c']"/>
93
        </controlfield>
94
        </xsl:if>
95
      </xsl:otherwise>
96
    </xsl:choose>
97
  </xsl:template>
98
99
  <xsl:template name="control008">
100
    <!-- FIXME:  Some conversions here are simplified:
101
	Processing of pubdate type
102
	Material dependent pos 18-34
103
    -->
104
    <controlfield tag="008">
105
      <xsl:value-of select="substring(marc:datafield[@tag='100']/marc:subfield[@code='a'],3,6)"/>
106
      <xsl:choose>
107
        <xsl:when test="substring(marc:leader,8,1)='s'">
108
        </xsl:when>
109
        <xsl:otherwise>
110
          <xsl:text>s</xsl:text>
111
          <xsl:value-of select="substring(marc:datafield[@tag='100']/marc:subfield[@code='a'],10,4)"/>
112
          <xsl:text>    </xsl:text>
113
        </xsl:otherwise>
114
	  <xsl:value-of select="translate(substring(marc:datafield[@tag='100']/marc:subfield[@code='a'],9,1),'abc','cdu')"/>
115
          <xsl:value-of select="substring(marc:datafield[@tag='100']/marc:subfield[@code='a'],10,8)"/>
116
      </xsl:choose>
117
      <!-- pos 15-17 place publication; 102a is two char code -->
118
      <xsl:choose>
119
      <xsl:when test="marc:datafield[@tag='102']/marc:subfield[@code='a']">
120
        <xsl:value-of select="substring(concat(marc:datafield[@tag='102']/marc:subfield[@code='a'],'   '),1,3)"/>
121
      </xsl:when>
122
      <xsl:otherwise>
123
        <xsl:text>xx </xsl:text>
124
      </xsl:otherwise>
125
      </xsl:choose>
126
      <!-- FIXME: pos 18-34 depending on material type -->
127
      <xsl:text>|||||||||||||||||</xsl:text>
128
      <!-- pos 35-37 language -->
129
      <xsl:value-of select="substring(concat(marc:datafield[@tag='101']/marc:subfield[@code='a'],'   '),1,3)"/>
130
      <!-- pos 38,39 modified, cataloging source -->
131
      <xsl:text> d</xsl:text>
132
    </controlfield>
133
  </xsl:template>
134
135
  <xsl:template name="isbn_issn">
136
    <xsl:if test="marc:datafield[@tag='010']">
137
      <datafield tag="020" ind1=" " ind2=" ">
138
        <subfield code="a">
139
	  <xsl:value-of select="marc:datafield[@tag='010']/marc:subfield[@code='a']"/>
140
	</subfield>
141
        <xsl:if test="marc:datafield[@tag='010']/marc:subfield[@code='b']">
142
          <subfield code="b">
143
	  <xsl:value-of select="marc:datafield[@tag='010']/marc:subfield[@code='b']"/>
144
	  </subfield>
145
	</xsl:if>
146
        <xsl:if test="marc:datafield[@tag='010']/marc:subfield[@code='d']">
147
          <subfield code="c">
148
	  <xsl:value-of select="marc:datafield[@tag='010']/marc:subfield[@code='d']"/>
149
	  </subfield>
150
	</xsl:if>
151
        <xsl:copy-of select="marc:datafield[@tag='010']/marc:subfield[@code='z']"/>
152
      </datafield>
153
    </xsl:if>
154
    <xsl:if test="marc:datafield[@tag='011']">
155
      <datafield tag="022" ind1=" " ind2=" ">
156
        <subfield code="a">
157
	  <xsl:value-of select="marc:datafield[@tag='011']/marc:subfield[@code='a']"/>
158
	</subfield>
159
        <xsl:copy-of select="marc:datafield[@tag='011']/marc:subfield[@code='z']"/>
160
      </datafield>
161
    </xsl:if>
162
  </xsl:template>
163
164
  <xsl:template name="author">
165
    <xsl:if test="marc:datafield[@tag='700']">
166
    <datafield tag="100">
167
      <!-- 100c only is R -->
168
      <xsl:call-template name="copy_indicators"><xsl:with-param name="tagno">700</xsl:with-param></xsl:call-template>
169
      <subfield code="a">
170
	<xsl:value-of select="marc:datafield[@tag='700']/marc:subfield[@code='a']"/>
171
	<xsl:if test="marc:datafield[@tag='700']/marc:subfield[@code='b']">
172
	  <xsl:text>, </xsl:text>
173
	  <xsl:value-of select="marc:datafield[@tag='700']/marc:subfield[@code='b']"/>
174
	</xsl:if>
175
      </subfield>
176
      <xsl:if test="marc:datafield[@tag='700']/marc:subfield[@code='d']">
177
          <subfield code='b'>
178
          <xsl:value-of select="marc:datafield[@tag='700']/marc:subfield[@code='d']"/>
179
          </subfield>
180
      </xsl:if>
181
      <xsl:copy-of select="marc:datafield[@tag='700']/marc:subfield[@code='c']"/>
182
      <xsl:if test="marc:datafield[@tag='700']/marc:subfield[@code='f']">
183
          <subfield code='d'>
184
          <xsl:value-of select="marc:datafield[@tag='700']/marc:subfield[@code='f']"/>
185
          </subfield>
186
      </xsl:if>
187
      <xsl:if test="marc:datafield[@tag='700']/marc:subfield[@code='g']">
188
          <subfield code='q'>
189
          <xsl:value-of select="marc:datafield[@tag='700']/marc:subfield[@code='g']"/>
190
          </subfield>
191
      </xsl:if>
192
    </datafield>
193
    </xsl:if>
194
  </xsl:template>
195
196
  <xsl:template name="author_corp">
197
    <xsl:if test="marc:datafield[@tag='710']">
198
      <datafield>
199
      <xsl:variable name="type" select="marc:datafield[@tag='710']/@ind1"/>
200
      <xsl:choose>
201
	<xsl:when test="$type=1">
202
	  <xsl:attribute name="tag">111</xsl:attribute>
203
	</xsl:when>
204
	<xsl:otherwise>
205
	  <xsl:attribute name="tag">110</xsl:attribute>
206
	</xsl:otherwise>
207
      </xsl:choose>
208
      <xsl:attribute name="ind1">
209
        <xsl:value-of select="marc:datafield[@tag='710']/@ind2"/>
210
      </xsl:attribute>
211
      <xsl:attribute name="ind2"><xsl:text> </xsl:text></xsl:attribute>
212
213
      <subfield code="a">
214
	<xsl:value-of select="marc:datafield[@tag='710']/marc:subfield[@code='a']"/>
215
	<xsl:for-each select="marc:datafield[@tag='710']/marc:subfield[@code='c']">
216
	  <xsl:text>, </xsl:text>
217
	  <xsl:value-of select="."/>
218
	</xsl:for-each>
219
      </subfield>
220
      <xsl:copy-of select="marc:datafield[@tag='710']/marc:subfield[@code='b']"/>
221
      <xsl:if test="marc:datafield[@tag='710']/marc:subfield[@code='e']">
222
          <subfield code='c'>
223
          <xsl:value-of select="marc:datafield[@tag='710']/marc:subfield[@code='e']"/>
224
          </subfield>
225
      </xsl:if>
226
      <xsl:if test="marc:datafield[@tag='710']/marc:subfield[@code='f']">
227
          <subfield code='d'>
228
          <xsl:value-of select="marc:datafield[@tag='710']/marc:subfield[@code='f']"/>
229
          </subfield>
230
      </xsl:if>
231
      <xsl:if test="marc:datafield[@tag='710']/marc:subfield[@code='d']">
232
          <subfield code='n'>
233
          <xsl:value-of select="marc:datafield[@tag='710']/marc:subfield[@code='d']"/>
234
          </subfield>
235
      </xsl:if>
236
      <xsl:if test="marc:datafield[@tag='710']/marc:subfield[@code='p']">
237
          <subfield code='u'>
238
          <xsl:value-of select="marc:datafield[@tag='710']/marc:subfield[@code='p']"/>
239
          </subfield>
240
      </xsl:if>
241
      <xsl:copy-of select="marc:datafield[@tag='710']/marc:subfield[@code='4']"/>
242
      </datafield>
243
    </xsl:if>
244
  </xsl:template>
245
246
  <xsl:template name="title">
247
    <datafield tag="245">
248
      <!-- 245abc are NR, 245np are R -->
249
      <xsl:call-template name="copy_indicators"><xsl:with-param name="tagno">200</xsl:with-param></xsl:call-template>
250
      <subfield code="a">
251
	<xsl:value-of select="marc:datafield[@tag='200']/marc:subfield[@code='a']"/>
252
      </subfield>
253
254
      <xsl:variable name="tagd" select="marc:datafield[@tag='200']/marc:subfield[@code='d']"/>
255
      <xsl:variable name="tage" select="marc:datafield[@tag='200']/marc:subfield[@code='e']"/>
256
      <xsl:if test="$tagd!='' or $tage!=''">
257
        <subfield code="b">
258
	<xsl:value-of select="$tagd"/>
259
	<xsl:for-each select="marc:datafield[@tag='200']/marc:subfield[@code='e']">
260
	  <xsl:text> : </xsl:text>
261
	  <xsl:value-of select="."/>
262
	</xsl:for-each>
263
        </subfield>
264
      </xsl:if>
265
266
      <xsl:variable name="tagf" select="marc:datafield[@tag='200']/marc:subfield[@code='f']"/>
267
      <xsl:variable name="tagg" select="marc:datafield[@tag='200']/marc:subfield[@code='g']"/>
268
      <xsl:if test="$tagf!='' or $tagg!=''">
269
        <subfield code="c">
270
	<xsl:value-of select="$tagf"/>
271
	<xsl:for-each select="marc:datafield[@tag='200']/marc:subfield[@code='g']">
272
	  <xsl:text> ; </xsl:text>
273
	  <xsl:value-of select="."/>
274
	</xsl:for-each>
275
        </subfield>
276
      </xsl:if>
277
278
      <xsl:for-each select="marc:datafield[@tag='200']/marc:subfield[@code='h']">
279
        <subfield code="n"><xsl:value-of select="."/></subfield>
280
      </xsl:for-each>
281
      <xsl:for-each select="marc:datafield[@tag='200']/marc:subfield[@code='i']">
282
        <subfield code="p"><xsl:value-of select="."/></subfield>
283
      </xsl:for-each>
284
    </datafield>
285
  </xsl:template>
286
287
  <xsl:template name="edition">
288
    <xsl:if test="marc:datafield[@tag='205']">
289
      <datafield tag="250" ind1=" " ind2=" ">
290
        <!-- 250 a is NR -->
291
        <xsl:copy-of select="marc:datafield[@tag='205'][1]/marc:subfield[@code='a'][1]"/>
292
        <xsl:if test="marc:datafield[@tag='205']/marc:subfield[@code='f']">
293
          <subfield code='b'>
294
          <xsl:value-of select="marc:datafield[@tag='205']/marc:subfield[@code='f']"/>
295
          </subfield>
296
        </xsl:if>
297
      </datafield>
298
    </xsl:if>
299
  </xsl:template>
300
301
  <xsl:template name="publication">
302
    <xsl:if test="marc:datafield[@tag='210']">
303
      <datafield tag="260" ind1=" " ind2=" ">
304
	<!-- 260 abc are repeatable: use for loops -->
305
        <xsl:copy-of select="marc:datafield[@tag='210']/marc:subfield[@code='a']"/>
306
        <xsl:for-each select="marc:datafield[@tag='210']/marc:subfield[@code='c']">
307
          <subfield code='b'>
308
          <xsl:value-of select="."/>
309
          </subfield>
310
        </xsl:for-each>
311
        <xsl:for-each select="marc:datafield[@tag='210']/marc:subfield[@code='d']">
312
          <subfield code='c'>
313
          <xsl:value-of select="."/>
314
          </subfield>
315
        </xsl:for-each>
316
317
        <!-- 260 efg are not-repeatable: take the first element only -->
318
        <xsl:copy-of select="marc:datafield[@tag='210']/marc:subfield[@code='e'][1]"/>
319
        <xsl:if test="marc:datafield[@tag='210']/marc:subfield[@code='g']">
320
          <subfield code='f'>
321
          <xsl:value-of select="marc:datafield[@tag='210']/marc:subfield[@code='g']"/>
322
          </subfield>
323
        </xsl:if>
324
        <xsl:if test="marc:datafield[@tag='210']/marc:subfield[@code='h']">
325
          <subfield code='g'>
326
          <xsl:value-of select="marc:datafield[@tag='210']/marc:subfield[@code='h']"/>
327
          </subfield>
328
        </xsl:if>
329
      </datafield>
330
    </xsl:if>
331
  </xsl:template>
332
333
  <xsl:template name="physicaldesc">
334
    <xsl:for-each select="marc:datafield[@tag='215']">
335
      <!-- 300ac are R, 300be are NR -->
336
      <datafield tag="300" ind1=" " ind2=" ">
337
        <xsl:copy-of select="marc:subfield[@code='a']"/>
338
        <xsl:if test="marc:subfield[@code='c']">
339
          <subfield code='b'>
340
          <xsl:value-of select="marc:subfield[@code='c']"/>
341
          </subfield>
342
        </xsl:if>
343
        <xsl:for-each select="marc:subfield[@code='d']">
344
          <subfield code='c'>
345
          <xsl:value-of select="."/>
346
          </subfield>
347
        </xsl:for-each>
348
        <xsl:copy-of select="marc:subfield[@code='e'][1]"/>
349
      </datafield>
350
    </xsl:for-each>
351
  </xsl:template>
352
353
  <xsl:template name="note_general">
354
    <xsl:for-each select="marc:datafield[@tag='300']">
355
      <!-- 500a is R -->
356
      <datafield tag="500" ind1=" " ind2=" ">
357
        <xsl:copy-of select="marc:subfield[@code='a']"/>
358
      </datafield>
359
    </xsl:for-each>
360
  </xsl:template>
361
362
  <xsl:template name="subject_person">
363
    <xsl:for-each select="marc:datafield[@tag='600']">
364
      <!-- only MARC21 600c is R -->
365
      <datafield tag="600">
366
      <xsl:attribute name="ind1"><xsl:value-of select="@ind1"/></xsl:attribute>
367
      <xsl:attribute name="ind2"><xsl:value-of select="@ind2"/></xsl:attribute>
368
        <xsl:copy-of select="marc:subfield[@code='a'][1]"/>
369
        <xsl:if test="marc:subfield[@code='d']">
370
          <subfield code='b'>
371
          <xsl:value-of select="marc:subfield[@code='d']"/>
372
          </subfield>
373
        </xsl:if>
374
        <xsl:copy-of select="marc:subfield[@code='c']"/>
375
        <xsl:if test="marc:subfield[@code='f']">
376
          <subfield code='d'>
377
          <xsl:value-of select="marc:subfield[@code='f']"/>
378
          </subfield>
379
        </xsl:if>
380
        <xsl:if test="marc:subfield[@code='b']">
381
          <subfield code='q'>
382
          <xsl:value-of select="marc:subfield[@code='b']"/>
383
          </subfield>
384
        </xsl:if>
385
      </datafield>
386
    </xsl:for-each>
387
  </xsl:template>
388
389
  <xsl:template name="subject_topic">
390
    <xsl:for-each select="marc:datafield[@tag='606']">
391
      <!-- 650a is NR -->
392
      <datafield tag="650" ind1=" " ind2="4">
393
        <xsl:copy-of select="marc:subfield[@code='a'][1]"/>
394
      </datafield>
395
    </xsl:for-each>
396
  </xsl:template>
397
398
  <xsl:template name="subject_geo">
399
    <xsl:for-each select="marc:datafield[@tag='607']">
400
      <!-- 651a is NR -->
401
      <datafield tag="651" ind1=" " ind2="4">
402
        <xsl:copy-of select="marc:subfield[@code='a'][1]"/>
403
      </datafield>
404
    </xsl:for-each>
405
  </xsl:template>
406
407
  <xsl:template name="subject_uncontrolled">
408
    <xsl:for-each select="marc:datafield[@tag='610']">
409
      <!-- 653a is R -->
410
      <datafield tag="653">
411
        <xsl:attribute name="ind1"><xsl:value-of select="@ind1"/></xsl:attribute>
412
        <xsl:attribute name="ind2"><xsl:value-of select="@ind2"/></xsl:attribute>
413
        <xsl:copy-of select="marc:subfield[@code='a']"/>
414
      </datafield>
415
    </xsl:for-each>
416
  </xsl:template>
417
418
  <xsl:template name="pers_name">
419
    <xsl:for-each select="marc:datafield[@tag='701' or @tag='702']">
420
    <datafield tag="700">
421
      <!-- 700c only is R -->
422
        <xsl:attribute name="ind1"><xsl:value-of select="@ind1"/></xsl:attribute>
423
        <xsl:attribute name="ind2"><xsl:value-of select="@ind2"/></xsl:attribute>
424
      <subfield code="a">
425
	<xsl:value-of select="marc:subfield[@code='a']"/>
426
	<xsl:if test="marc:subfield[@code='b']">
427
	  <xsl:text>, </xsl:text>
428
	  <xsl:value-of select="marc:subfield[@code='b']"/>
429
	</xsl:if>
430
      </subfield>
431
      <xsl:if test="marc:subfield[@code='d']">
432
          <subfield code='b'>
433
          <xsl:value-of select="marc:subfield[@code='d']"/>
434
          </subfield>
435
      </xsl:if>
436
      <xsl:copy-of select="marc:subfield[@code='c']"/>
437
      <xsl:if test="marc:subfield[@code='f']">
438
          <subfield code='d'>
439
          <xsl:value-of select="marc:subfield[@code='f']"/>
440
          </subfield>
441
      </xsl:if>
442
      <xsl:if test="marc:subfield[@code='g']">
443
          <subfield code='q'>
444
          <xsl:value-of select="marc:subfield[@code='g']"/>
445
          </subfield>
446
      </xsl:if>
447
    </datafield>
448
    </xsl:for-each>
449
  </xsl:template>
450
451
  <xsl:template name="corp_name">
452
    <xsl:for-each select="marc:datafield[@tag='711' or @tag='712']">
453
      <datafield>
454
      <xsl:variable name="type" select="@ind1"/>
455
      <xsl:choose>
456
	<xsl:when test="$type=1">
457
	  <xsl:attribute name="tag">711</xsl:attribute>
458
	</xsl:when>
459
	<xsl:otherwise>
460
	  <xsl:attribute name="tag">710</xsl:attribute>
461
	</xsl:otherwise>
462
      </xsl:choose>
463
      <xsl:attribute name="ind1">
464
        <xsl:value-of select="@ind2"/>
465
      </xsl:attribute>
466
      <xsl:attribute name="ind2"><xsl:text> </xsl:text></xsl:attribute>
467
468
      <subfield code="a">
469
	<xsl:value-of select="marc:subfield[@code='a']"/>
470
	<xsl:for-each select="marc:subfield[@code='c']">
471
	  <xsl:text>, </xsl:text>
472
	  <xsl:value-of select="."/>
473
	</xsl:for-each>
474
      </subfield>
475
      <xsl:copy-of select="marc:subfield[@code='b']"/>
476
      <xsl:if test="marc:subfield[@code='e']">
477
          <subfield code='c'>
478
          <xsl:value-of select="marc:subfield[@code='e']"/>
479
          </subfield>
480
      </xsl:if>
481
      <xsl:if test="marc:subfield[@code='f']">
482
          <subfield code='d'>
483
          <xsl:value-of select="marc:subfield[@code='f']"/>
484
          </subfield>
485
      </xsl:if>
486
      <xsl:if test="marc:subfield[@code='d']">
487
          <subfield code='n'>
488
          <xsl:value-of select="marc:subfield[@code='d']"/>
489
          </subfield>
490
      </xsl:if>
491
      <xsl:if test="marc:subfield[@code='p']">
492
          <subfield code='u'>
493
          <xsl:value-of select="marc:subfield[@code='p']"/>
494
          </subfield>
495
      </xsl:if>
496
      <xsl:copy-of select="marc:subfield[@code='4']"/>
497
      </datafield>
498
    </xsl:for-each>
499
  </xsl:template>
500
501
  <!-- And some utility functions -->
502
503
  <xsl:template name="copy_control">
504
    <xsl:param name="tagno"/>
505
    <xsl:if test="marc:controlfield[@tag=$tagno]">
506
      <controlfield>
507
       <xsl:attribute name="tag"><xsl:value-of select="$tagno"/></xsl:attribute>
508
       <xsl:value-of select="marc:controlfield[@tag=$tagno]" />
509
      </controlfield>
510
    </xsl:if>
511
  </xsl:template>
512
513
  <xsl:template name="copy_indicators">
514
    <xsl:param name="tagno"/>
515
        <xsl:attribute name="ind1">
516
          <xsl:value-of select="marc:datafield[@tag=$tagno]/@ind1"/>
517
        </xsl:attribute>
518
        <xsl:attribute name="ind2">
519
          <xsl:value-of select="marc:datafield[@tag=$tagno]/@ind2"/>
520
        </xsl:attribute>
521
  </xsl:template>
522
523
</xsl:stylesheet>

Return to bug 6536