diff --git a/bin/slubsipbuilder.pl b/bin/slubsipbuilder.pl
deleted file mode 100755
index 4ed53429d4d4cbf2fc567a72497529c7cd124193..0000000000000000000000000000000000000000
--- a/bin/slubsipbuilder.pl
+++ /dev/null
@@ -1,690 +0,0 @@
-#!/usr/bin/env perl
-#===============================================================================
-#
-#         FILE: slubsipbuilder.pl
-#
-#        USAGE: ./slubsipbuilder.pl
-#
-#  DESCRIPTION: A CLI tool to create a valid SIP for SLUBArchiv
-#
-# REQUIREMENTS: ---
-#         BUGS: ---
-#        NOTES: related to official document
-#               "SIP Spezifikation (v1.5)"
-#       AUTHOR: Andreas Romeyke (romeyke@slub-dresden.de)
-# ORGANIZATION: SLUB
-#      VERSION: 1.1
-#      CREATED: 2019-07-23
-#===============================================================================
-
-
-use strict;
-use warnings;
-use Carp;
-use 5.28.0;
-package SLUB::LZA::SIPBuilder;
-    use DateTime::Format::ISO8601;
-    use File::Copy qw(cp);
-    use File::Find;
-    use Path::Tiny;
-    use LWP::UserAgent; # to get MARC data
-    use MARC::Record;
-    use XML::LibXML;
-    use XML::LibXSLT;
-    use XML::XPath;
-    use Carp;
-	use Encode;
-	
-    my $marc_mods_url = 'http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3-6.xsl';
-    my $marc_utils_url = 'http://www.loc.gov/standards/marcxml/xslt/MARC21slimUtils.xsl';
-    my $swb_url = 'https://sru.bsz-bw.de/swb';
-    my $searchkey = "pica.swn";
-    my $recordschema = "marcxmlvbos";
-    our $VERSION = '1.2';
-    our $with_debug=0;
-
-
-    # write data to file (UTF-8)
-    sub write_file($$) {
-		if(! defined $_[0]) { croak "filename not defined!"; }
-		if(! defined $_[1]) { croak "value not defined!"; }
-		if($_[0] eq "" || $_[1] eq ""){
-			die "invalid parameters.";
-		}
-		my $filename = $_[0];
-        my $value = $_[1];
-        open(my $fh, '>:encoding(UTF-8)', $filename) || (croak "Can't open '$filename', $!");
-        print $fh $value;
-        close($fh) || (croak "could not close file '$filename', $!");
-        return 1;
-    }
-
-    # this will patch the mods-xml as a workaround for bugs in LOCs xslt files
-    sub patch_mods($) {
-		if(! defined $_[0]) { croak "modsobject not defined!"; }
-		if($_[0] eq ""){ die "invalid parameters."; }
-        my $modsobj = shift; # mods expected as XML Parser object
-        # TODO: Bugfix for /mets:mets/mets:dmdSec[1]/mets:mdWrap[1]/mets:xmlData[1]/mods:modsCollection[1]/mods:mods[1]/mods:relatedItem[2]/mods:internetMediaType[1]
-        my $xslt_patch_string = <<'PATCH';
-<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-    xmlns:xs="http://www.w3.org/2001/XMLSchema"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xmlns:mods="http://www.loc.gov/mods/v3"
-    xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd"
-    exclude-result-prefixes="xs"
-    version="1.0">
-    <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
-    <xsl:strip-space elements="*"/>
-    <xsl:template match="//mods:mods/mods:relatedItem[mods:internetMediaType]">
-        <xsl:comment>patched wrong //mods:mods/mods:relatedItem[mods:internetMediaType]</xsl:comment>
-    </xsl:template>
-    <xsl:template match="@* | node()">
-        <xsl:copy>
-            <xsl:apply-templates select="@* | node()"/>
-        </xsl:copy>
-    </xsl:template>
-</xsl:stylesheet>
-PATCH
-        my $xslt = XML::LibXSLT->new();
-        my $xslt_patch = XML::LibXML->load_xml(string => $xslt_patch_string, no_cdata => 1);
-        my $stylesheet = $xslt->parse_stylesheet($xslt_patch);
-        my $result = $stylesheet->transform($modsobj);
-        return $result;
-    }
-
-    sub patch_marc_response($) {
-		if(! defined $_[0]) { croak "marcobject not defined!"; }
-		if($_[0] eq ""){ die "invalid parameters."; }
-        my $marcobj = shift; # marcobj expected as XML Parser object
-        my $xslt_patch_string = <<'PATCH2';
-<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.loc.gov/MARC21/slim" xmlns:srw="http://www.loc.gov/zing/srw/"
-    exclude-result-prefixes="srw" version="1.0">
-    <xsl:template match="/record">
-        <xsl:element name="collection">
-            <xsl:element name="record" namespace="http://www.loc.gov/MARC21/slim">
-                <xsl:apply-templates select="@*"/>
-                <xsl:apply-templates select="node()"/>
-            </xsl:element>
-        </xsl:element>
-    </xsl:template>
-    <xsl:template match="*">
-        <xsl:element name="{local-name()}" namespace="http://www.loc.gov/MARC21/slim">
-            <xsl:apply-templates select="node() | @*"/>
-        </xsl:element>
-    </xsl:template>
-    <xsl:template match="@*">
-        <xsl:attribute name="{local-name()}">
-            <xsl:value-of select="."/>
-        </xsl:attribute>
-    </xsl:template>
-</xsl:stylesheet>
-PATCH2
-        my $xslt = XML::LibXSLT->new();
-        my $xslt_patch = XML::LibXML->load_xml(string => $xslt_patch_string, no_cdata => 1);
-        my $stylesheet = $xslt->parse_stylesheet($xslt_patch);
-        my $result = $stylesheet->transform($marcobj);
-        return $result;
-    }
-
-    # check MARC21 utility xsl
-    sub check_marc21_utility {
-		if(! defined $_[0]) { croak "xsl directory not defined!"; }
-		if(! defined $_[1]) { croak "user agent not defined!"; }
-		if($_[0] eq "" || $_[1] eq ""){
-			die "invalid parameters.";
-		}
-        my $xsl_dir = shift;
-        my $ua = shift;
-        my $marc_utils_basename = path($marc_utils_url)->basename;
-        my $marc_utils_path = path($xsl_dir)->child($marc_utils_basename);
-        if (!$marc_utils_path->is_file) {
-            say "Downloading MARC21 utility xsl '$marc_utils_url'";
-            my $result = $ua->get($marc_utils_url);
-            if ($result->is_error) {
-                croak "Failed to download '$marc_utils_url', " . $result->error_as_HTML;
-            }
-            say "Saving MARC21 utility xsl to file '$marc_utils_path'";
-            my $xsl = $result->decoded_content;
-            write_file($marc_utils_path, $xsl);
-        }
-        return $marc_utils_path;
-    }
-
-    # check MARC21->MODS xsl
-    sub check_marc21_mods_xsl {
-		if(! defined $_[0]) { croak "xsl directory not defined!"; }
-		if(! defined $_[1]) { croak "user agent not defined!"; }
-		if($_[0] eq "" || $_[1] eq ""){
-			die "invalid parameters.";
-		}
-        my $xsl_dir = shift;
-        my $ua = shift;
-        my $marc_mods_basename = path($marc_mods_url)->basename;
-        my $marc_mods_path = path($xsl_dir)->child($marc_mods_basename)->stringify;
-        my $marc_mods_patched_basename = path($marc_mods_url)->basename(".xsl") . ".patched.xsl";
-        my $marc_mods_patched_path = path($xsl_dir)->child($marc_mods_patched_basename);
-        if (! $marc_mods_patched_path->is_file) {
-            say "Downloading MARC21->MODS xsl '$marc_mods_url'";
-            my $result = $ua->get($marc_mods_url);
-            if ($result->is_error) {
-                croak "Failed to download '$marc_mods_url', " . $result->error_as_HTML;
-            }
-            say "Modifying MARC21->MODS xsl for offline use";
-            my $xsl = $result->decoded_content;
-            write_file($marc_mods_path, $xsl);
-            my $xsl_modified = $xsl;
-            my $marc_utils_path = check_marc21_utility( $xsl_dir, $ua);
-            $xsl_modified =~ s#$marc_utils_url#$marc_utils_path#g;
-            say "Saving MARC21->MODS xsl to file '$marc_mods_path'";
-            write_file($marc_mods_patched_path, $xsl_modified);
-        }
-        return $marc_mods_patched_path;
-    }
-
-    sub check_xsl_directory {
-        # check xsl directory
-        my $xsl_dir = path(__FILE__)->parent->realpath->parent->child("xsl");
-        if (! $xsl_dir->is_dir) {
-            say "Rebuilding XSL directory '$xsl_dir'";
-            $xsl_dir->mkpath() || confess("could not mkdir '$xsl_dir', $!");
-        }
-        return $xsl_dir;
-    }
-
-    # specification SRU/SRW BSZ: https://wiki.k10plus.de/pages/viewpage.action?pageId=132874251
-    sub get_mods_from($$$$) {
-		if(! defined $_[0]) { croak "url not defined!"; }
-		if(! defined $_[1]) { croak "ppn not defined!"; }
-		if(! defined $_[2]) { croak "key not defined!"; }
-		if(! defined $_[3]) { croak "schema not defined!"; }
-		if($_[0] eq "" || $_[1] eq "" || $_[2] eq "" || $_[3] eq ""){
-			die "invalid parameters.";
-		}
-        # $mods = ($url, $ppn, $searchkey, $recordschema)
-        my $url = shift;
-        my $ppn = shift; # example: "457035137"  for "Der Fichtelberg"
-        my $key = shift;
-        my $schema = shift;
-
-        #### where to find XSLT
-		
-        my $ua = LWP::UserAgent->new;
-        $ua->agent("MyApp/0.1 ");
-        $ua->timeout(3600); #1h
-
-        my $xsl_dir = check_xsl_directory();
-        check_marc21_utility($xsl_dir, $ua);
-        check_marc21_mods_xsl($xsl_dir, $ua);
-
-        my $srubase = $url;      # host
-        my $srusearchkey = $key; # SRU search key
-        my $sruvalue = $ppn;
-        my $srumaxrecords = 1;
-        my $srustartrecord = 1;
-        my $sruschema = $schema;
-        my $sru = "${srubase}?version=1.1&query=${srusearchkey}%3D${sruvalue}&operation=searchRetrieve&maximumRecords=${srumaxrecords}&startRecord=${srustartrecord}&recordSchema=${sruschema}";
-        if ($with_debug) {say "catalog-URL='$sru'";}
-        my $response = $ua->get($sru); # ask SWB for given PPN
-        if ($response->is_success) {
-            # parse ZiNG repsonse, extract MARC-data
-            my $xp = XML::XPath->new($response->decoded_content);
-            my $parser = XML::LibXML->new();
-            if ($with_debug) {
-                say "write DEBUG_${ppn}_response.xml";
-                write_file("DEBUG_${ppn}_response.xml", $response->decoded_content);
-            }
-            my $recordData = $xp->findnodes_as_string('/*[local-name()="searchRetrieveResponse"]/*[local-name()="records"]/*[local-name()="record"]/*[local-name()="recordData"]/*');
-            if (!$recordData) { croak("ERROR: Did not get any <recordData/> for PPN '$ppn' using '$sru'");}
-            my $marcblob = $parser->parse_string($recordData);
-
-
-            my $marcblob_patched = patch_marc_response($marcblob);
-            if ($with_debug) {
-                say "write DEBUG_${ppn}_marc_unpatched.xml";
-                write_file("DEBUG_${ppn}_marc_unpatched.xml", $marcblob);
-                say "write DEBUG_${ppn}_marc.xml";
-                write_file("DEBUG_${ppn}_marc.xml", $marcblob_patched);
-            }
-
-            my $marc_mods_patched_path = check_marc21_mods_xsl($xsl_dir, $ua);
-            my $xslt = XML::LibXSLT->new();
-            my $marcmods = XML::LibXML->load_xml(location => $marc_mods_patched_path, no_cdata => 1);
-            my $stylesheet = $xslt->parse_stylesheet($marcmods);
-            my $marc = $parser->parse_string($marcblob_patched);
-            my $result = $stylesheet->transform($marc);
-            if ($with_debug) {
-                say "write DEBUG_${ppn}_unpatched_mods.xml";
-                write_file("DEBUG_${ppn}_unpatched_mods.xml", $stylesheet->output_string($result));
-            }
-            $result = patch_mods($result);
-            my $result_string = $stylesheet->output_string($result);
-            return $result_string;
-        }
-        else {
-            carp("Problem asking catalogue at $url using $ppn");
-        }
-        return;
-    }
-	
-	sub create_filecopyhash {
-		if(! defined $_[0]) { croak "directory not defined!"; }
-		if(! defined $_[1]) { croak "content not defined!"; }
-		if($_[0] eq "" || $_[1] eq ""){
-			die "invalid parameters.";
-		}
-		my $directory = shift;
-		my $content = shift;
-		my %filecopyhash;
-		my $wanted=sub {
-			if (-d $_) {
-				# dir, do nothing
-				();
-			} else {
-				my $file=$File::Find::name;
-				# system unabhängige pfade
-				if ($file !~ m#^[-A-Za-z0-9_\.:\\/]+$#) {
-					confess("file '$file' does not match regex '^[-A-Za-z0-9_\.:\\/]+\$'");
-				}
-				my $source = $file;
-				$filecopyhash{$source}->{'source'}=$file;
-				$file=~s#^$directory/?##;
-				$filecopyhash{$source}{'relative'}="data/$file";
-				$filecopyhash{$source}{'target'}="$content/$file";
-				my $fh;
-				open($fh, "<", $source) or confess ("Can't open '$source', $!");
-				binmode($fh);
-				my $ctx = Digest::MD5->new;
-				$ctx->addfile(*$fh);
-				close ($fh);
-				my $md5 = $ctx->hexdigest;
-				$filecopyhash{$source}{'md5sum'}=$md5;
-			}
-		};
-		finddepth($wanted, $directory);
-		return \%filecopyhash;
-	}
-
-    sub prepare_dmd_section_with_ppn($) {
-		if(! defined $_[0]) { croak "ppn not defined!"; }
-        my $ppn = shift;
-        my $mods = SLUB::LZA::SIPBuilder::get_mods_from($swb_url, $ppn, $searchkey, $recordschema);
-        if ($with_debug) {
-            SLUB::LZA::SIPBuilder::write_file("DEBUG_${ppn}_mods.xml", $mods);
-        }
-        # remove the <xml /> from beginning of the answer
-        $mods=~ s#<\?xml version="1.0" encoding="UTF-8"\?>#<!-- removed xml header from mods part -->#;
-        my $dmd =<<"DMD";
-<mets:dmdSec ID="DMDLOG_0000">
-  <!-- bibliographic metadata -->
-  <mets:mdWrap MDTYPE="MODS">
-    <mets:xmlData>
-      $mods
-    </mets:xmlData>
-  </mets:mdWrap>
-</mets:dmdSec>
-DMD
-        return $dmd;
-    }
-
-    sub prepare_dmd_section_with_noppn($) {
-		if(! defined $_[0]) { croak "noppn not defined!"; }
-        my $noppn = shift;
-        my $mods =<<"MODS";
-<mods version="3.6"
-    xmlns="http://www.loc.gov/mods/v3"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd">
-    <identifier>$noppn</identifier>
-</mods>
-MODS
-        my $dmd =<<"DMD";
-<mets:dmdSec ID="DMDLOG_0000">
-  <!-- bibliographic metadata -->
-  <mets:mdWrap MDTYPE="MODS">
-    <mets:xmlData>
-      $mods
-    </mets:xmlData>
-  </mets:mdWrap>
-</mets:dmdSec>
-DMD
-        return $dmd;
-    }
-
-    sub prepare_amd_section($$$$$$) {
-		if(! defined $_[0]) { croak "export to archive date not defined!"; }
-		if(! defined $_[1]) { croak "external workflow not defined!"; }
-		if(! defined $_[2]) { croak "external id not defined!"; }
-		if(! defined $_[3]) { croak "external conservation flag not defined!"; }
-		if(! defined $_[4]) { croak "external isil not defined!"; }
-		if(! defined $_[5]) { croak "external value description not defined!"; }
-		if($_[0] eq "" || $_[1] eq "" || $_[2] eq "" || $_[3] eq "" || $_[5] eq ""){
-			die "invalid parameters.";
-		}
-        my $export_to_archive_date = shift;
-        my $external_workflow = shift;
-        my $external_id = shift;
-        my $external_conservation_flag = shift;
-        my $external_isil = shift;
-        my $external_value_descr = decode_utf8(shift);
-		my $amd;
-		
-		if ($external_isil eq '') {
-			$amd =<<"AMD";
-<mets:amdSec ID="AMD">
-        <!-- SIP metadata for automated processing by submission application -->
-        <mets:techMD ID="ARCHIVE">
-            <mets:mdWrap MDTYPE="OTHER" MIMETYPE="text/xml" OTHERMDTYPE="ARCHIVE">
-                <mets:xmlData>
-                    <archive:record version="v2019.2" xmlns:archive="http://slub-dresden.de/slubarchiv">
-                        <archive:exportToArchiveDate>$export_to_archive_date</archive:exportToArchiveDate>
-                        <archive:externalId>$external_id</archive:externalId>
-                        <archive:externalWorkflow>$external_workflow</archive:externalWorkflow>
-                        <archive:hasConservationReason>$external_conservation_flag</archive:hasConservationReason>
-                        <archive:archivalValueDescription>$external_value_descr</archive:archivalValueDescription>
-                    </archive:record>
-                </mets:xmlData>
-            </mets:mdWrap>
-        </mets:techMD>
-    </mets:amdSec>
-AMD
-		} else {
-			$amd =<<"AMD";
-<mets:amdSec ID="AMD">
-        <!-- SIP metadata for automated processing by submission application -->
-        <mets:techMD ID="ARCHIVE">
-            <mets:mdWrap MDTYPE="OTHER" MIMETYPE="text/xml" OTHERMDTYPE="ARCHIVE">
-                <mets:xmlData>
-                    <archive:record version="v2019.2" xmlns:archive="http://slub-dresden.de/slubarchiv">
-                        <archive:exportToArchiveDate>$export_to_archive_date</archive:exportToArchiveDate>
-                        <archive:externalId>$external_id</archive:externalId>
-                        <archive:externalWorkflow>$external_workflow</archive:externalWorkflow>
-                        <archive:hasConservationReason>$external_conservation_flag</archive:hasConservationReason>
-                        <archive:externalIsilId>$external_isil</archive:externalIsilId>
-                        <archive:archivalValueDescription>$external_value_descr</archive:archivalValueDescription>
-                    </archive:record>
-                </mets:xmlData>
-            </mets:mdWrap>
-        </mets:techMD>
-    </mets:amdSec>
-AMD
-		}
-        return $amd;
-    }
-
-    sub prepare_files_sections($) {
-		if(! defined $_[0]) { croak "filecopyhash not defined!"; }
-        my $filecopyhash = shift;
-        my @fsec;
-        my $i=0;
-        foreach my $fkey (sort keys (%{$filecopyhash})) {
-            push @fsec, sprintf("<mets:file ID=\"FILE_%015u_LZA\" CHECKSUMTYPE=\"MD5\" CHECKSUM=\"%s\">", $i, $filecopyhash->{$fkey}->{"md5sum"});
-            push @fsec, sprintf("<mets:FLocat xmlns:xlink=\"http://www.w3.org/1999/xlink\" LOCTYPE=\"URL\" xlink:href=\"file://%s\"/>", $filecopyhash->{$fkey}->{"relative"});
-            push @fsec, "</mets:file>";
-            $i++;
-        }
-        my $files = join("\n", @fsec);
-        my $filesec=<<"FILESEC";
-<mets:fileSec>
-  <mets:fileGrp USE="LZA">
-  $files
-  </mets:fileGrp>
-</mets:fileSec>
-FILESEC
-        return $filesec;
-    }
-
-    sub prepare_struct_map($) {
-		if(! defined $_[0]) { croak "filecopyhash not defined!"; }
-        my $filecopyhash = shift;
-        my @ssec;
-        my $i=0;
-        foreach my $fkey (sort keys (%{$filecopyhash})) {
-            push @ssec, sprintf("<mets:div ID=\"PHYS_%015u_LZA\" TYPE=\"fileorderSequence\">", $i);
-            push @ssec, sprintf("<mets:fptr FILEID=\"FILE_%015u_LZA\" />", $i);
-            push @ssec, "</mets:div>";
-            $i++;
-        }
-        my $structs = join("\n", @ssec);
-        my $structmap =<<"STRUCTMAP";
-<mets:structMap TYPE="PHYSICAL">
-  <mets:div ID="PHYS_0000" TYPE="ieDir">
-  $structs
-  </mets:div>
-</mets:structMap>
-STRUCTMAP
-        return $structmap;
-    }
-
-	sub check_directory($$) {
-		if(! defined $_[0]) { croak "fullname not defined!"; }
-		if(! defined $_[1]) { croak "entry not defined!"; }
-		if($_[0] eq "" || $_[1] eq ""){
-			die "invalid parameters.";
-		}
-		my $fullname = shift;
-		my $entry = shift;
-		my $dir_err = '';
-		# Die Gesamtlänge der relativen Pfade darf jeweils 255 Zeichen nicht übersteigen. 
-		if (length($fullname) > 255){ 
-			return $dir_err = "path to file: $fullname is too long, expected maximum 255 characters"; 
-		}
-		# Als Dateinamen und Verzeichnisnamen sind für die zu archivierenden Dateien die Zeichen A-Za-z0-9_.- sowie / für Verzeichnistrenner erlaubt.
-		if ($entry !~ m#^[A-Za-z0-9_.-]+$#){ 
-			return $dir_err = "you need to specify a valid file or directory (name: $entry) to (^[A-Za-z0-9_.-]+\$)"; 
-		}
-		# Relative Pfade mit Bestandteilen der Form "../" sind nicht erlaubt.
-		if ($fullname =~ /\.\.\//){ 
-			return $dir_err = "relativ path($fullname) in form '../' is not allowed"; 
-		}
-		return $dir_err;
-	}
-	
-	sub validate_directory($) {
-		if(! defined $_[0]) { croak "directory not defined!"; }
-		if(! -d $_[0]){
-			die "Could not find directory";
-		}
-		my $directory = shift;
-		my @dirs = ($directory);
-		my $dir_err = '';
-		while (@dirs && ($dir_err eq '')) {
-			my $thisdir = shift @dirs;
-			if (!($thisdir)) {
-				# dir, do nothing
-				return $dir_err='';
-			}
-			opendir (my $dh, $thisdir) or die "Could not find $thisdir";
-			while (my $entry = readdir $dh && ($dir_err eq '')) {
-				next if $entry eq '.';
-				next if $entry eq '..';
-				
-				my $fullname = "$thisdir/$entry";
-
-				$dir_err = check_directory($fullname, $entry);
-
-				if (-d $fullname) {
-					push @dirs, $fullname;
-				}
-			}
-			closedir $dh;
-		}
-		return $dir_err;
-	}
-
-    # end package
-
-package main;
-#===============================================================================
-
-BEGIN{
-    $INC{'SLUB/LZA/SIPBuilder.pm'} = 1; # needed because inlined module
-}
-return 1 if caller; # avoids main code running if module stuff is needed
-use SLUB::LZA::SIPBuilder;
-use Getopt::Long;
-use Path::Tiny;
-use Digest::MD5;
-use constant buffer => 100 * 1024 * 1024; # use 100MB as Buffer
-use File::Find;
-use File::Copy qw(cp);
-use Pod::Usage;
-
-my $directory;
-my $ppn;
-my $noppn;
-my $output;
-my $external_id;
-my $external_workflow;
-my $external_isil="";
-my $external_value_descr;
-my $external_conservation_flag;
-
-my $help;
-my $man;
-
-GetOptions(
-    "IE_directory=s"                => \$directory,                     	# required
-    "ppn=s"                         => \$ppn,                           	# semi-optional (choice 1 of 2)
-    "noppn=s"                       => \$noppn,                         	# semi-optional (choice 2 of 2)
-    "SIP_output_path=s"             => \$output,                        	# required
-    "external_id=s"                 => \$external_id,                   	# required
-    "external_workflow=s"           => \$external_workflow,             	# required
-    "external_ISIL=s"               => \$external_isil,                 	# optional, default: no ISIL
-    "external_value_descr=s"        => \$external_value_descr,          	# required
-    "external_conservation_flag"    => \$external_conservation_flag,    	# optional, default: no special conservation
-    "debug"                         => \$SLUB::LZA::SIPBuilder::with_debug, # optional
-    "help|?"                        => \$help,                          	# optional
-    "man"                           => \$man,                           	# optional
-) or pod2usage(2);
-
-
-if ($help)                                  { pod2usage(1); }
-if ($man)                                   { pod2usage(-exitval => 0, -verbose => 2); }
-my $dir_err = SLUB::LZA::SIPBuilder::validate_directory($directory);
-if (!defined $directory)                    { confess("you need to specify an IE directory, which needs to be archived"); }
-if ((defined $directory) && ($dir_err ne '')) { confess($dir_err); }
-if ((defined $ppn) && (defined $noppn))     { confess("you can only specify either -ppn or -noppn"); }
-if ((!defined $ppn) && (!defined $noppn))   { confess("you need to specify a PPN with -ppn or use --noppn"); }
-if (!defined $output)                       { confess("you need to specify an output path, where the SIP will be stored"); }
-if (!defined $external_id)					{ confess("you need to specify external ID"); }
-if ((defined $external_id) && ($external_id !~ m#^[a-z0-9_-]+$#)) { confess("you need to specify a valid external ID (^[a-z0-9_-]+\$)"); }
-if (!defined $external_workflow)			{ confess("you need to specify external workflow"); }
-if ((defined $external_workflow) && ($external_workflow !~ m#^[a-z0-9_-]+$#)) { confess("you need to specify a valid external workflow (^[a-z0-9_-]+\$)"); }
-if (!$external_value_descr)                 { confess("you need to specify an external value description (reason for archiving)"); }
-if (!defined $external_conservation_flag)   { $external_conservation_flag="false"; } else { $external_conservation_flag="true"; }
-if (! -d $directory)                        { confess("you need to specify an IE directory, which needs to be archived, $!"); }
-$directory = path($directory)->realpath->stringify;
-path($output)->mkpath;
-$output = path($output)->realpath->stringify;
-
-#===============================================================================
-
-sub main {
-    # get date
-    my $export_to_archive_date = DateTime->now(time_zone=>'local')->iso8601();
-    my $file_date = $export_to_archive_date;
-    $file_date =~ s/T/_/g; # replace 'T' with '_'
-    $file_date =~ s/:/-/g; # replace ':' with '-'
-    # prepare dirs
-    my $sip_root_dir = (defined $ppn)? "PPN-${ppn}_${file_date}" : "ID-${noppn}_${file_date}";
-    my $content = path($output)->child($sip_root_dir)->child("data")->stringify;
-    path($content)->mkpath;
-    my $filecopyhash = SLUB::LZA::SIPBuilder::create_filecopyhash($directory, $content);
-
-    # prepare dmd-sec
-    my $dmd = (defined $ppn)? SLUB::LZA::SIPBuilder::prepare_dmd_section_with_ppn( $ppn ) : SLUB::LZA::SIPBuilder::prepare_dmd_section_with_noppn( $noppn );
-    # prepare amd-sec
-    my $amd = SLUB::LZA::SIPBuilder::prepare_amd_section(
-        $export_to_archive_date,
-        $external_workflow,
-        $external_id,
-        $external_conservation_flag,
-        $external_isil,
-        $external_value_descr
-    );
-    # create fileSec
-    my $filesec = SLUB::LZA::SIPBuilder::prepare_files_sections($filecopyhash);
-    # prepare structmap
-    my $structmap = SLUB::LZA::SIPBuilder::prepare_struct_map($filecopyhash);
-    # create sip.xml
-    my $sip =<<"METS";
-<?xml version="1.0" encoding="utf-8"?>
-<mets:mets xmlns:mets="http://www.loc.gov/METS/"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/version111/mets.xsd">
-    $dmd
-    $amd
-    $filesec
-    $structmap
-</mets:mets>
-METS
-
-    # write stuff out
-	SLUB::LZA::SIPBuilder::write_file( path($output)->child($sip_root_dir)->child("sip.xml")->stringify, $sip );
-	# copy source to target
-	foreach my $source (sort keys (%{$filecopyhash})) {
-		my $target = path($filecopyhash->{$source}->{"target"})->stringify; # CHECK ON WINDOWS
-		my $basename = path($target)->parent->stringify;
-		if (! -d $basename) {
-			path($basename)->mkpath;
-		}
-		cp($source, $target, buffer) || confess ("could not copy from '$source' to '$target', $!");
-	}
-	say "SIP '$sip_root_dir' build successfully in '$output'";
-    
-    return;
-}
-
-
-#===============================================================================
-
-main();
-
-#===============================================================================
-
-
-__END__
-
-=pod
-
-=head1 NAME
-
-preingest tool "SIP builder" script to create SIPs for SLUBArchive
-
-=head1 SYNOPSIS
-
-slubsipbuilder.pl  [options]
-
- Options:
-        -help                           brief help message
-        -man                            full documentation
-
-        -IE_directory=<IE dir>          existing IE directory (absolute path!)
-        -ppn=<ppn>|-noppn=<noppn>       SWB-PPN or any identifier (uses minimalistic MODS)
-        -SIP_output_path=<target dir>   where to put the SIP dir (absolute path!)
-        -external_id=<id>               mandatory, should be uniqe ID
-        -external_workflow=<workflow>   mandatory, should be uniqe workflow name
-        -external_ISIL=<isil>           optional, ISIL number of library
-        -external_value_descr=<text>    mandatory, the reason why to archive
-        -external_conservation_flag     optional, if set no other "original" still exists
-
-slubsipbuilder.pl --IE_directory=/export_dir_kitodo/10008 --ppn=457035137 --SIP_output_path=/tmp/mysip --external_id=10008 --external_workflow=kitodo --external_ISIL=DE-14 --external_value_descr="Gesetzlicher Auftrag"
-
-=head1 OPTIONS
-
-=over 8
-
-=item B<-help>
-
-Print a brief help message and exits.
-
-=back
-
-=head1 DESCRIPTION
-
-B<This program> will process the given IE directory, add bibliographic metadata from catalogue with given PICA number and check and create a SIP directory ready for SLUBarchiv
-
-=cut
diff --git a/bin/slubsipbuilderbagit.pl b/bin/slubsipbuilderbagit.pl
new file mode 100755
index 0000000000000000000000000000000000000000..654964e9cb0a76dc9f0d38869f58e53fb5388e7c
--- /dev/null
+++ b/bin/slubsipbuilderbagit.pl
@@ -0,0 +1,8334 @@
+#!/usr/bin/env perl
+#===============================================================================
+#         FILE: slubsipbuilderbagit.pl
+#
+#        USAGE: perl -I lib/ bin/slubsipbuilderbagit.pl --save_option=copy
+#               --IE_directory=./export_dir_kitodo/bagit/test2
+#               --SIP_output_path=/tmp --ppn=457035137 --SIP_version=v2020.1
+#               --external_id=10008 --external_workflow=kitodo
+#               --external_ISIL=DE-14 --external_value_descr="Gesetzlicher Auftrag"
+#               --rights_version=1.0
+#               --rights_xml=export_dir_kitodo/bagit/rights/Fallbeispiel-02.xml
+#
+#  DESCRIPTION: A CLI tool to create a valid SIP for SLUBArchiv
+#
+# REQUIREMENTS: perl install version 5.28 or higher, as all necessary modules required
+#                install Archive::BagIt::Base
+#               (If fails than you need extra "sudo apt install libperl-dev libperl5.28")
+#
+#         BUGS: ---
+#        NOTES: related to official document "SLUBArchiv_Produzenten_SIP_Spezifikation_v2.0.pdf"
+#                --save_option=copy is RECOMMENDED than <replace> or <move>,
+#               because IE can be corrupted if process fails. Manual restoration needed!!!
+#               --add_meta_file="key: values" must be in double quotes to be able to write
+#               whitespaces for values
+#       AUTHOR: Andreas Romeyke (romeyke@slub-dresden.de)
+#               Serhiy Bolkun (Serhiy.Bolkun@slub-dresden.de),
+#
+# ORGANIZATION: SLUB
+#      VERSION: 2.0
+#      CREATED: 2020-04-27
+#===============================================================================
+
+
+use strict;
+use warnings;
+
+package SLUB::LZA::SIPBuilderBagIt;
+    use feature 'say';
+    use Archive::BagIt::Base;
+    use Carp;
+    use Data::Printer;
+    use Encode;
+    use File::Find;
+    use File::Copy::Recursive qw( dircopy );
+    use LWP::UserAgent;          # to get MARC data
+    use MARC::Record;
+    use Path::Tiny;
+    use Term::ANSIColor;         # colored print
+    use Try::Tiny;
+    use XML::LibXML;
+    use XML::XPath;
+    use XML::LibXSLT;
+
+    our $VERBOSE = 0;              # print ausgaben schalter 0 => on, 1 und größer = off
+
+    # old SLUB_SIP_Builder functions
+    my $marc_mods_url  = 'http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3-6.xsl';
+    my $marc_utils_url = 'http://www.loc.gov/standards/marcxml/xslt/MARC21slimUtils.xsl';
+    my $swb_url        = 'https://sru.bsz-bw.de/swb';
+    my $searchkey      = 'pica.swn';
+    my $recordschema   = 'marcxmlvbos';
+    our $with_debug    = 0;
+
+    sub prepare_mods_section_with_noppn($){
+        if(! defined $_[0]) { croak "noppn is not defined!"; }
+        if($_[0] eq "") { croak "noppn is empty string!"; }
+
+        my $noppn = shift;
+        my $mods =<<"MODS";
+<mods version="3.6"
+    xmlns="http://www.loc.gov/mods/v3"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd">
+    <identifier>$noppn</identifier>
+</mods>
+MODS
+        return $mods;
+    }
+
+    sub prepare_mods_section_with_ppn($){
+        if(! defined $_[0]){ croak "ppn not defined!"; }
+
+        my $ppn  = shift;
+        my $mods = SLUB::LZA::SIPBuilderBagIt::get_mods_from($swb_url, $ppn, $searchkey, $recordschema);
+
+        if($with_debug){
+            SLUB::LZA::SIPBuilderBagIt::write_file("DEBUG_${ppn}_mods.xml", $mods);
+        }
+        # remove the <xml /> from beginning of the answer
+        $mods=~ s#<\?xml version="1.0" encoding="UTF-8"\?>#<!-- removed xml header from mods part -->#;
+
+        return $mods;
+    }
+
+    sub get_mods_from($$$$){
+        # specification SRU/SRW BSZ: https://wiki.k10plus.de/pages/viewpage.action?pageId=132874251
+        if(! defined $_[0]) { croak "url not defined!"; }
+        if(! defined $_[1]) { croak "ppn not defined!"; }
+        if(! defined $_[2]) { croak "key not defined!"; }
+        if(! defined $_[3]) { croak "schema not defined!"; }
+        if($_[0] eq "" || $_[1] eq "" || $_[2] eq "" || $_[3] eq ""){
+            die "invalid parameters.";
+        }
+        #$mods      = ($url, $ppn, $searchkey, $recordschema)
+        my $url    = shift;
+        my $ppn    = shift; # example: "457035137"  for "Der Fichtelberg"
+        my $key    = shift;
+        my $schema = shift;
+
+        #### where to find XSLT
+
+        my $ua = LWP::UserAgent->new;
+        $ua->agent("MyApp/0.1 ");
+        $ua->timeout(3600); #1h
+
+        my $xsl_dir = SLUB::LZA::SIPBuilderBagIt::check_xsl_directory();
+        SLUB::LZA::SIPBuilderBagIt::check_marc21_utility($xsl_dir, $ua);
+        SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl($xsl_dir, $ua);
+
+        my $srubase        = $url; # host
+        my $srusearchkey   = $key; # SRU search key
+        my $sruvalue       = $ppn;
+        my $srumaxrecords  = 1;
+        my $srustartrecord = 1;
+        my $sruschema      = $schema;
+        my $sru            = "${srubase}?version=1.1&query=${srusearchkey}%3D${sruvalue}&operation=searchRetrieve&maximumRecords=${srumaxrecords}&startRecord=${srustartrecord}&recordSchema=${sruschema}";
+
+        if ($with_debug) {say "catalog-URL='$sru'";}
+        my $response = $ua->get($sru); # ask SWB for given PPN
+        if ($response->is_success) {
+            # parse ZiNG repsonse, extract MARC-data
+            my $xp = XML::XPath->new($response->decoded_content);
+            my $parser = XML::LibXML->new();
+            if ($with_debug) {
+                say "write DEBUG_${ppn}_response.xml";
+                SLUB::LZA::SIPBuilderBagIt::write_file("DEBUG_${ppn}_response.xml", $response->decoded_content);
+            }
+            my $recordData = $xp->findnodes_as_string('/*[local-name()="searchRetrieveResponse"]/*[local-name()="records"]/*[local-name()="record"]/*[local-name()="recordData"]/*');
+            if (!$recordData) { croak("ERROR: Did not get any <recordData/> for PPN '$ppn' using '$sru'");}
+            my $marcblob = $parser->parse_string($recordData);
+
+
+            my $marcblob_patched = SLUB::LZA::SIPBuilderBagIt::patch_marc_response($marcblob);
+            if ($with_debug) {
+                say "write DEBUG_${ppn}_marc_unpatched.xml";
+                SLUB::LZA::SIPBuilderBagIt::write_file("DEBUG_${ppn}_marc_unpatched.xml", $marcblob);
+                say "write DEBUG_${ppn}_marc.xml";
+                SLUB::LZA::SIPBuilderBagIt::write_file("DEBUG_${ppn}_marc.xml", $marcblob_patched);
+            }
+
+            my $marc_mods_patched_path = SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl($xsl_dir, $ua);
+            my $xslt                   = XML::LibXSLT->new();
+            my $marcmods               = XML::LibXML->load_xml(location => $marc_mods_patched_path, no_cdata => 1);
+            my $stylesheet             = $xslt->parse_stylesheet($marcmods);
+            my $marc                   = $parser->parse_string($marcblob_patched);
+            my $result                 = $stylesheet->transform($marc);
+            if ($with_debug) {
+                say "write DEBUG_${ppn}_unpatched_mods.xml";
+                SLUB::LZA::SIPBuilderBagIt::write_file("DEBUG_${ppn}_unpatched_mods.xml", $stylesheet->output_string($result));
+            }
+            $result = patch_mods($result);
+            my $result_string = $stylesheet->output_string($result);
+            return $result_string;
+        }
+        else {
+            carp("Problem asking catalogue at $url using $ppn");
+        }
+
+        return;
+    }
+
+    sub write_file($$){
+        if(! defined $_[0]) { croak "filename not defined!"; }
+        if(! defined $_[1]) { croak "value not defined!"; }
+        if($_[0] eq "" || $_[1] eq ""){ die "invalid parameters."; }
+
+        my $filename = $_[0];
+        my $value    = $_[1];
+
+        # write data to file (UTF-8)
+        open(my $fh, '>:encoding(UTF-8)', $filename) || (croak "Can't open '$filename', $!");
+        print $fh $value;
+        close($fh) || (croak "could not close file '$filename', $!");
+        return 1;
+    }
+
+    sub check_xsl_directory{
+        my $xsl_dir = path(__FILE__)->parent->realpath->parent->child("xsl");
+        if (! $xsl_dir->is_dir) {
+            say "Rebuilding XSL directory '$xsl_dir'";
+            $xsl_dir->mkpath() || confess("could not mkdir '$xsl_dir', $!");
+        }
+        return $xsl_dir;
+    }
+
+    sub check_marc21_utility($$){
+        # check MARC21 utility xsl
+        if(! defined $_[0]) { croak "xsl directory not defined!"; }
+        if(! defined $_[1]) { croak "user agent not defined!"; }
+        if($_[0] eq "" || $_[1] eq ""){ die "invalid parameters."; }
+
+        my $xsl_dir = shift;
+        my $ua      = shift;
+        my $marc_utils_basename = path($marc_utils_url)->basename;
+        my $marc_utils_path     = path($xsl_dir)->child($marc_utils_basename);
+
+        if (!$marc_utils_path->is_file) {
+            if ($ENV{DOWNLOAD}) {
+                say "Downloading MARC21 utility xsl '$marc_utils_url'";
+                my $result = $ua->get($marc_utils_url);
+                if ($result->is_error) {
+                    croak "Failed to download '$marc_utils_url', " . $result->error_as_HTML;
+                }
+                say "Saving MARC21 utility xsl to file '$marc_utils_path'";
+                my $xsl = $result->decoded_content;
+                SLUB::LZA::SIPBuilderBagIt::write_file($marc_utils_path, $xsl);
+            } else {
+                my $xsl=<<'MARC21SLIMUTILS';
+<?xml version='1.0'?>
+<xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim"
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+    <!-- 08/08/08: tmee added corrected chopPunctuation templates for 260c -->
+    <!-- 08/19/04: ntra added "marc:" prefix to datafield element -->
+    <!-- 12/14/07: ntra added url encoding template -->
+    <!-- url encoding -->
+
+    <xsl:variable name="ascii">
+        <xsl:text> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:text>
+    </xsl:variable>
+
+    <xsl:variable name="latin1">
+        <xsl:text> ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:text>
+    </xsl:variable>
+    <!-- Characters that usually don't need to be escaped -->
+    <xsl:variable name="safe">
+        <xsl:text>!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:text>
+    </xsl:variable>
+
+    <xsl:variable name="hex">0123456789ABCDEF</xsl:variable>
+
+
+    <xsl:template name="datafield">
+        <xsl:param name="tag"/>
+        <xsl:param name="ind1">
+            <xsl:text> </xsl:text>
+        </xsl:param>
+        <xsl:param name="ind2">
+            <xsl:text> </xsl:text>
+        </xsl:param>
+        <xsl:param name="subfields"/>
+        <xsl:element name="marc:datafield">
+            <xsl:attribute name="tag">
+                <xsl:value-of select="$tag"/>
+            </xsl:attribute>
+            <xsl:attribute name="ind1">
+                <xsl:value-of select="$ind1"/>
+            </xsl:attribute>
+            <xsl:attribute name="ind2">
+                <xsl:value-of select="$ind2"/>
+            </xsl:attribute>
+            <xsl:copy-of select="$subfields"/>
+        </xsl:element>
+    </xsl:template>
+
+    <xsl:template name="subfieldSelect">
+        <xsl:param name="codes">abcdefghijklmnopqrstuvwxyz</xsl:param>
+        <xsl:param name="delimeter">
+            <xsl:text> </xsl:text>
+        </xsl:param>
+        <xsl:variable name="str">
+            <xsl:for-each select="marc:subfield">
+                <xsl:if test="contains($codes, @code)">
+                    <xsl:value-of select="text()"/>
+                    <xsl:value-of select="$delimeter"/>
+                </xsl:if>
+            </xsl:for-each>
+        </xsl:variable>
+        <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
+    </xsl:template>
+
+    <xsl:template name="buildSpaces">
+        <xsl:param name="spaces"/>
+        <xsl:param name="char">
+            <xsl:text> </xsl:text>
+        </xsl:param>
+        <xsl:if test="$spaces>0">
+            <xsl:value-of select="$char"/>
+            <xsl:call-template name="buildSpaces">
+                <xsl:with-param name="spaces" select="$spaces - 1"/>
+                <xsl:with-param name="char" select="$char"/>
+            </xsl:call-template>
+        </xsl:if>
+    </xsl:template>
+
+    <xsl:template name="chopPunctuation">
+        <xsl:param name="chopString"/>
+        <xsl:param name="punctuation">
+            <xsl:text>.:,;/ </xsl:text>
+        </xsl:param>
+        <xsl:variable name="length" select="string-length($chopString)"/>
+        <xsl:choose>
+            <xsl:when test="$length=0"/>
+            <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
+                    <xsl:with-param name="punctuation" select="$punctuation"/>
+                </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="not($chopString)"/>
+            <xsl:otherwise>
+                <xsl:value-of select="$chopString"/>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="chopPunctuationFront">
+        <xsl:param name="chopString"/>
+        <xsl:variable name="length" select="string-length($chopString)"/>
+        <xsl:choose>
+            <xsl:when test="$length=0"/>
+            <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
+                <xsl:call-template name="chopPunctuationFront">
+                    <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"
+                    />
+                </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="not($chopString)"/>
+            <xsl:otherwise>
+                <xsl:value-of select="$chopString"/>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="chopPunctuationBack">
+        <xsl:param name="chopString"/>
+        <xsl:param name="punctuation">
+            <xsl:text>.:,;/] </xsl:text>
+        </xsl:param>
+        <xsl:variable name="length" select="string-length($chopString)"/>
+        <xsl:choose>
+            <xsl:when test="$length=0"/>
+            <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
+                    <xsl:with-param name="punctuation" select="$punctuation"/>
+                </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="not($chopString)"/>
+            <xsl:otherwise>
+                <xsl:value-of select="$chopString"/>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <!-- nate added 12/14/2007 for lccn.loc.gov: url encode ampersand, etc. -->
+    <xsl:template name="url-encode">
+
+        <xsl:param name="str"/>
+
+        <xsl:if test="$str">
+            <xsl:variable name="first-char" select="substring($str,1,1)"/>
+            <xsl:choose>
+                <xsl:when test="contains($safe,$first-char)">
+                    <xsl:value-of select="$first-char"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:variable name="codepoint">
+                        <xsl:choose>
+                            <xsl:when test="contains($ascii,$first-char)">
+                                <xsl:value-of
+                                    select="string-length(substring-before($ascii,$first-char)) + 32"
+                                />
+                            </xsl:when>
+                            <xsl:when test="contains($latin1,$first-char)">
+                                <xsl:value-of
+                                    select="string-length(substring-before($latin1,$first-char)) + 160"/>
+                                <!-- was 160 -->
+                            </xsl:when>
+                            <xsl:otherwise>
+                                <xsl:message terminate="no">Warning: string contains a character
+                                    that is out of range! Substituting "?".</xsl:message>
+                                <xsl:text>63</xsl:text>
+                            </xsl:otherwise>
+                        </xsl:choose>
+                    </xsl:variable>
+                    <xsl:variable name="hex-digit1"
+                        select="substring($hex,floor($codepoint div 16) + 1,1)"/>
+                    <xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
+                    <!-- <xsl:value-of select="concat('%',$hex-digit2)"/> -->
+                    <xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
+                </xsl:otherwise>
+            </xsl:choose>
+            <xsl:if test="string-length($str) &gt; 1">
+                <xsl:call-template name="url-encode">
+                    <xsl:with-param name="str" select="substring($str,2)"/>
+                </xsl:call-template>
+            </xsl:if>
+        </xsl:if>
+    </xsl:template>
+</xsl:stylesheet>
+<!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
+<metaInformation>
+<scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
+</metaInformation>
+-->
+MARC21SLIMUTILS
+                write_file($marc_utils_path, $xsl);
+            }
+        }
+        return $marc_utils_path;
+    }
+
+    sub check_marc21_mods_xsl($$){
+        # check MARC21->MODS xsl
+        if(! defined $_[0]) { croak "xsl directory not defined!"; }
+        if(! defined $_[1]) { croak "user agent not defined!"; }
+        if($_[0] eq "" || $_[1] eq ""){ die "invalid parameters."; }
+
+        my $xsl_dir = shift;
+        my $ua      = shift;
+        my $marc_mods_basename         = path($marc_mods_url)->basename;
+        my $marc_mods_path             = path($xsl_dir)->child($marc_mods_basename)->stringify;
+        my $marc_mods_patched_basename = path($marc_mods_url)->basename(".xsl") . ".patched.xsl";
+        my $marc_mods_patched_path     = path($xsl_dir)->child($marc_mods_patched_basename);
+
+        if (! $marc_mods_patched_path->is_file) {
+            my $xsl;
+            if ($ENV{DOWNLOAD}) {
+                say "Downloading MARC21->MODS xsl '$marc_mods_url'";
+                my $result = $ua->get($marc_mods_url);
+                if ($result->is_error) {
+                    croak "Failed to download '$marc_mods_url', " . $result->error_as_HTML;
+                }
+                say "Modifying MARC21->MODS xsl for offline use";
+                $xsl = $result->decoded_content;
+            } else {
+                $xsl =<<'MARC21SLIM2MODS36';
+<xsl:stylesheet xmlns="http://www.loc.gov/mods/v3" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xlink marc" version="1.0">
+    <xsl:include href="http://www.loc.gov/standards/marcxml/xslt/MARC21slimUtils.xsl"/>
+    <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
+    <xsl:strip-space elements="*"/>
+
+    <!-- Maintenance note: For each revision, change the content of <recordInfo><recordOrigin> to reflect the new revision number.
+    MARC21slim2MODS3-6
+
+    MODS 3.6  (Revision 1.138) 20200106
+
+    Revision 1.138 - Update output to notes fields for 500. - 2020/01/06 ws
+    Revision 1.137 - Add displayLabel to tableOfContents. - 2020/01/06 ws
+    Revision 1.136 - Update language objectPart to match mapping. - 2020/01/06 ws
+    Revision 1.135 - Add 588 to notes. - 2020/01/06 ws
+    Revision 1.134 - Update dates to match mapping. - 2020/01/06 ws
+    Revision 1.133 - Update placeTerm to match mapping. - 2020/01/06 ws
+    Revision 1.132 - Remove xlink from 655, icorrect mapping. - 2020/01/06 ws
+    Revision 1.131 - Fix bug in 730[@ind2!=2]/880[@ind2!=2] output . - 2020/01/06 ws
+    Revision 1.130 - Update originInfo altRepGroup and subfields. - 2020/01/06 ws
+    Revision 1.129 - Update physicalDescription altRepGroup. - 2020/01/06 ws
+    Revision 1.128 - Bug fix for 260$c altRepGroup output, strip punctuation. - 2019/12/27 ws
+    Revision 1.127 - Add 521 displayLabel based on mapping. - 2019/12/27 ws
+    Revision 1.126 - Consistent handling of punctiaion in name elements, 100/700/110/710 - 2019/12/02 ws
+    Revision 1.125 - Correct partNumber output for 710,711,810,811 $n after $t  - 2019/11/22 ws
+    Revision 1.124 - Correct incorrect type attribute on 520/abstract. Should be @displayLabel, not @type. - 2019/11/22 ws
+    Revision 1.123 - Correct bugs in @nameTitleGroup - 2019/11/22 ws
+    Revision 1.122 - Add xlink for 6XX, 130, 240, 730, 100, 700, 110, 710, 111, 711, 655  - 2019/11/22 ws
+    Revision 1.121 - Update 880 subfield 6 output to better reflect mapping. - 2019/11/20 ws
+    Revision 1.120 - Update relatedItems output to better match mapping. See specific changes below. - 2019/11/20 ws
+                        1.120 - @76X-78X$g adds subfield g as partNumber
+                        1.120 - @76X-78X$z add isbn identifier
+                        1.120 - @76X-78X$i add displayLabel
+                        1.120 - @762@type fix 762 type
+                        1.120 - @775@type test for ind2
+                        1.120 - @777 add all fields for 777 relatedItem output
+                        1.120 - @787 add all fields for 787 relatedItem output
+                        1.120 - @800$0 add $0 xlink="contents of $0" as URI 800,810, 811, 830
+                        1.120 - @800$v add partNumber 800,810, 811, 830
+                        1.120 - @711$v $v incorrectly added to title in 710,711 and 730
+                        1.120 - @711$4 add role and roleTerm
+                        1.120 - @510$ind1 add ind1 conditions
+                        1.120 - @534$ind1 add ind1 conditions
+                        1.120 - @440$ind1 add ind1 conditions
+                        1.120 - @440$a$v fix subfield output
+                        1.120 - @440$a$v add conditions
+                        1.120 - @490$ind1 add ind1 conditions
+                        1.120 - @490$v add partNumber
+                        1.120 - @830$v add partNumber
+                        1.120 - @856@ind2=2$q added physicalDescription tag
+                        1.120 - @245/@880$ind2 - fix nonSort bugs
+                        1.120 - @246/ind2=1 fix type to translated
+                        1.120 - @264/ind2 fix mapping
+                        1.120 - @260$issuance make conditional so no empty issuance elements can be output
+    Revision 1.119 - Fixed 700 ind1=0 to transform - tmee 2018/06/21
+    Revision 1.118 - Fixed namePart termsOfAddress subelement order - 2018/01/31 tmee
+    Revision 1.117 - Fixed name="corporate" RE: MODS 3.6 - 2017/2/14 tmee
+    Revision 1.116 - Added nameIdentifier to 700/710/711/100/110/111 $0 RE: MODS 3.6 - 2016/3/15 ws
+    Revision 1.115 - Added @otherType for 7xx RE: MODS 3.6 - 2016/3/15 ws
+    Revision 1.114 - Added <itemIdentifier> for 852$p and <itemIdentifier > with type="copy number" for 852$t RE: MODS 3.6 - 2016/3/15 ws
+    Revision 1.113 - Added @valueURI="contents of $0" for 752/662 RE: MODS 3.6 - 2016/3/15 ws
+    Revision 1.112 - Added @xml:space="preserve" to title/nonSort on 245 and 242 RE: MODS 3.6 - 2016/3/15 ws
+
+    Revision 1.111 - Added test to prevent empty authority attribute for 047 with no subfield 2. - ws 2016/03/24
+    Revision 1.110 - Added test to prevent empty authority attribute for 336 with no subfield 2. - ws 2016/03/24
+    Revision 1.109 - Added test to prevent empty authority attribute for 655 and use if ind2 if no subfield 2 is available. - ws 2016/03/24
+    Revision 1.108 - Added filter to name templates to exclude names with title subfields. - ws 2016/03/24
+
+    Revision 1.107 - Added support for 024/@ind1=7 - ws 2016/1/7
+    Revision 1.106 - Added a xsl:when to deal with '#' and ' ' in $leader19 and $controlField008-18 - ws 2014/12/19
+    Revision 1.105 - Add @unit to extent - ws 2014/11/20
+    Revision 1.104 - Fixed 111$n and 711$n to reflect mapping to <namePart> tmee 20141112
+    Revision 1.103 - Fixed 008/28 to reflect revised mapping for government publication tmee 20141104
+    Revision 1.102 - Fixed 240$s duplication tmee 20140812
+    Revision 1.101 - Fixed 130 tmee 20140806
+    Revision 1.100 - Fixed 245c tmee 20140804
+    Revision 1.99 - Fixed 240 issue tmee 20140804
+    Revision 1.98 - Fixed 336 mapping tmee 20140522
+    Revision 1.97 - Fixed 264 mapping tmee 20140521
+    Revision 1.96 - Fixed 310 and 321 and 008 frequency authority for marcfrequency tmee 2014/04/22
+    Revision 1.95 - Modified 035 to include identifier type (WlCaITV) tmee 2014/04/21
+    Revision 1.94 - Leader 07 b changed mapping from continuing to serial tmee 2014/02/21
+
+    MODS 3.5
+    Revision 1.93 - Fixed personal name transform for ind1=0 tmee 2014/01/31
+    Revision 1.92 - Removed duplicate code for 856 1.51 tmee 2014/01/31
+    Revision 1.91 - Fixed createnameFrom720 duplication tmee 2014/01/31
+    Revision 1.90 - Fixed 520 displayLabel tmee tmee 2014/01/31
+    Revision 1.89 - Fixed 008-06 when value = 's' for cartographics tmee tmee 2014/01/31
+    Revision 1.88 - Fixed 510c mapping - tmee 2013/08/29
+    Revision 1.87 - Fixed expressions of <accessCondition> type values - tmee 2013/08/29
+    Revision 1.86 - Fixed 008 <frequency> subfield to occur w/i <originiInfo> - tmee 2013/08/29
+    Revision 1.85 - Fixed 245$c - tmee 2013/03/07
+    Revision 1.84 - Fixed 1.35 and 1.36 date mapping for 008 when 008/06=e,p,r,s,t so only 008/07-10 displays, rather than 008/07-14 - tmee 2013/02/01
+    Revision 1.83 - Deleted mapping for 534 to note - tmee 2013/01/18
+    Revision 1.82 - Added mapping for 264 ind 0,1,2,3 to originInfo - 2013/01/15 tmee
+    Revision 1.81 - Added mapping for 336$a$2, 337$a$2, 338$a$2 - 2012/12/03 tmee
+    Revision 1.80 - Added 100/700 mapping for "family" - 2012/09/10 tmee
+    Revision 1.79 - Added 245 $s mapping - 2012/07/11 tmee
+    Revision 1.78 - Fixed 852 mapping <shelfLocation> was changed to <shelfLocator> - 2012/05/07 tmee
+    Revision 1.77 - Fixed 008-06 when value = 's' - 2012/04/19 tmee
+    Revision 1.76 - Fixed 242 - 2012/02/01 tmee
+    Revision 1.75 - Fixed 653 - 2012/01/31 tmee
+    Revision 1.74 - Fixed 510 note - 2011/07/15 tmee
+    Revision 1.73 - Fixed 506 540 - 2011/07/11 tmee
+    Revision 1.72 - Fixed frequency error - 2011/07/07 and 2011/07/14 tmee
+    Revision 1.71 - Fixed subject titles for subfields t - 2011/04/26 tmee
+    Revision 1.70 - Added mapping for OCLC numbers in 035s to go into <identifier type="oclc"> 2011/02/27 - tmee
+    Revision 1.69 - Added mapping for untyped identifiers for 024 - 2011/02/27 tmee
+    Revision 1.68 - Added <subject><titleInfo> mapping for 600/610/611 subfields t,p,n - 2010/12/22 tmee
+    Revision 1.67 - Added frequency values and authority="marcfrequency" for 008/18 - 2010/12/09 tmee
+    Revision 1.66 - Fixed 008/06=c,d,i,m,k,u, from dateCreated to dateIssued - 2010/12/06 tmee
+    Revision 1.65 - Added back marcsmd and marccategory for 007 cr- 2010/12/06 tmee
+    Revision 1.64 - Fixed identifiers - removed isInvalid template - 2010/12/06 tmee
+    Revision 1.63 - Fixed descriptiveStandard value from aacr2 to aacr - 2010/12/06 tmee
+    Revision 1.62 - Fixed date mapping for 008/06=e,p,r,s,t - 2010/12/01 tmee
+    Revision 1.61 - Added 007 mappings for marccategory - 2010/11/12 tmee
+    Revision 1.60 - Added altRepGroups and 880 linkages for relevant fields, see mapping - 2010/11/26 tmee
+    Revision 1.59 - Added scriptTerm type=text to language for 546b and 066c - 2010/09/23 tmee
+    Revision 1.58 - Expanded script template to include code conversions for extended scripts - 2010/09/22 tmee
+    Revision 1.57 - Added Ldr/07 and Ldr/19 mappings - 2010/09/17 tmee
+    Revision 1.56 - Mapped 1xx usage="primary" - 2010/09/17 tmee
+    Revision 1.55 - Mapped UT 240/1xx nameTitleGroup - 2010/09/17 tmee
+    MODS 3.4
+    Revision 1.54 - Fixed 086 redundancy - 2010/07/27 tmee
+    Revision 1.53 - Added direct href for MARC21slimUtils - 2010/07/27 tmee
+    Revision 1.52 - Mapped 046 subfields c,e,k,l - 2010/04/09 tmee
+    Revision 1.51 - Corrected 856 transform - 2010/01/29 tmee
+    Revision 1.50 - Added 210 $2 authority attribute in <titleInfo type=”abbreviated”> 2009/11/23 tmee
+    Revision 1.49 - Aquifer revision 1.14 - Added 240s (version) data to <titleInfo type="uniform"><title> 2009/11/23 tmee
+    Revision 1.48 - Aquifer revision 1.27 - Added mapping of 242 second indicator (for nonfiling characters) to <titleInfo><nonSort > subelement  2007/08/08 tmee/dlf
+    Revision 1.47 - Aquifer revision 1.26 - Mapped 300 subfield f (type of unit) - and g (size of unit) 2009 ntra
+    Revision 1.46 - Aquifer revision 1.25 - Changed mapping of 767 so that <type="otherVersion>  2009/11/20  tmee
+    Revision 1.45 - Aquifer revision 1.24 - Changed mapping of 765 so that <type="otherVersion>  2009/11/20  tmee
+    Revision 1.44 - Added <recordInfo><recordOrigin> canned text about the version of this stylesheet 2009 ntra
+    Revision 1.43 - Mapped 351 subfields a,b,c 2009/11/20 tmee
+    Revision 1.42 - Changed 856 second indicator=1 to go to <location><url displayLabel=”electronic resource”> instead of to <relatedItem type=”otherVersion”><url> 2009/11/20 tmee
+    Revision 1.41 - Aquifer revision 1.9 Added variable and choice protocol for adding usage=”primary display” 2009/11/19 tmee
+    Revision 1.40 - Dropped <note> for 510 and added <relatedItem type="isReferencedBy"> for 510 2009/11/19 tmee
+    Revision 1.39 - Aquifer revision 1.23 Changed mapping for 762 (Subseries Entry) from <relatedItem type="series"> to <relatedItem type="constituent"> 2009/11/19 tmee
+    Revision 1.38 - Aquifer revision 1.29 Dropped 007s for electronic versions 2009/11/18 tmee
+    Revision 1.37 - Fixed date redundancy in output (with questionable dates) 2009/11/16 tmee
+    Revision 1.36 - If mss material (Ldr/06=d,p,f,t) map 008 dates and 260$c/$g dates to dateCreated 2009/11/24, otherwise map 008 and 260$c/$g to dateIssued 2010/01/08 tmee
+    Revision 1.35 - Mapped appended detailed dates from 008/07-10 and 008/11-14 to dateIssued or DateCreated w/encoding="marc" 2010/01/12 tmee
+    Revision 1.34 - Mapped 045b B.C. and C.E. date range info to iso8601-compliant dates in <subject><temporal> 2009/01/08 ntra
+    Revision 1.33 - Mapped Ldr/06 "o" to <typeOfResource>kit 2009/11/16 tmee
+    Revision 1.32 - Mapped specific note types from the MODS Note Type list <http://www.loc.gov/standards/mods/mods-notes.html> tmee 2009/11/17
+    Revision 1.31 - Mapped 540 to <accessCondition type="use and reproduction"> and 506 to <accessCondition type="restriction on access"> and delete mappings of 540 and 506 to <note>
+    Revision 1.30 - Mapped 037c to <identifier displayLabel=""> 2009/11/13 tmee
+    Revision 1.29 - Corrected schemaLocation to 3.3 2009/11/13 tmee
+    Revision 1.28 - Changed mapping from 752,662 g going to mods:hierarchicalGeographic/area instead of "region" 2009/07/30 ntra
+    Revision 1.27 - Mapped 648 to <subject> 2009/03/13 tmee
+    Revision 1.26 - Added subfield $s mapping for 130/240/730  2008/10/16 tmee
+    Revision 1.25 - Mapped 040e to <descriptiveStandard> and Leader/18 to <descriptive standard>aacr2  2008/09/18 tmee
+    Revision 1.24 - Mapped 852 subfields $h, $i, $j, $k, $l, $m, $t to <shelfLocation> and 852 subfield $u to <physicalLocation> with @xlink 2008/09/17 tmee
+    Revision 1.23 - Commented out xlink/uri for subfield 0 for 130/240/730, 100/700, 110/710, 111/711 as these are currently unactionable  2008/09/17 tmee
+    Revision 1.22 - Mapped 022 subfield $l to type "issn-l" subfield $m to output identifier element with corresponding @type and @invalid eq 'yes'2008/09/17 tmee
+    Revision 1.21 - Mapped 856 ind2=1 or ind2=2 to <relatedItem><location><url>  2008/07/03 tmee
+    Revision 1.20 - Added genre w/@auth="contents of 2" and type= "musical composition"  2008/07/01 tmee
+    Revision 1.19 - Added genre offprint for 008/24+ BK code 2  2008/07/01  tmee
+    Revision 1.18 - Added xlink/uri for subfield 0 for 130/240/730, 100/700, 110/710, 111/711  2008/06/26 tmee
+    Revision 1.17 - Added mapping of 662 2008/05/14 tmee
+    Revision 1.16 - Changed @authority from "marc" to "marcgt" for 007 and 008 codes mapped to a term in <genre> 2007/07/10 tmee
+    Revision 1.15 - For field 630, moved call to part template outside title element  2007/07/10 tmee
+    Revision 1.14 - Fixed template isValid and fields 010, 020, 022, 024, 028, and 037 to output additional identifier elements with corresponding @type and @invalid eq 'yes' when subfields z or y (in the case of 022) exist in the MARCXML ::: 2007/01/04 17:35:20 cred
+    Revision 1.13 - Changed order of output under cartographics to reflect schema  2006/11/28 tmee
+    Revision 1.12 - Updated to reflect MODS 3.2 Mapping  2006/10/11 tmee
+    Revision 1.11 - The attribute objectPart moved from <languageTerm> to <language>  2006/04/08  jrad
+    Revision 1.10 - MODS 3.1 revisions to language and classification elements (plus ability to find marc:collection embedded in wrapper elements such as SRU zs: wrappers)  2006/02/06  ggar
+    Revision 1.09 - Subfield $y was added to field 242 2004/09/02 10:57 jrad
+    Revision 1.08 - Subject chopPunctuation expanded and attribute fixes 2004/08/12 jrad
+    Revision 1.07 - 2004/03/25 08:29 jrad
+    Revision 1.06 - Various validation fixes 2004/02/20 ntra
+    Revision 1.05 - MODS2 to MODS3 updates, language unstacking and de-duping, chopPunctuation expanded  2003/10/02 16:18:58  ntra
+    Revision 1.03 - Additional Changes not related to MODS Version 2.0 by ntra
+    Revision 1.02 - Added Log Comment  2003/03/24 19:37:42  ckeith
+    -->
+
+    <xsl:template match="/">
+        <xsl:choose>
+            <xsl:when test="//marc:collection">
+                <modsCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd">
+                    <xsl:for-each select="//marc:collection/marc:record">
+                        <mods version="3.6">
+                            <xsl:call-template name="marcRecord"/>
+                        </mods>
+                    </xsl:for-each>
+                </modsCollection>
+            </xsl:when>
+            <xsl:otherwise>
+                <mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.6" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd">
+                    <xsl:for-each select="//marc:record">
+                        <xsl:call-template name="marcRecord"/>
+                    </xsl:for-each>
+                </mods>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+    <xsl:template name="marcRecord">
+        <xsl:variable name="leader" select="marc:leader"/>
+        <xsl:variable name="leader6" select="substring($leader,7,1)"/>
+        <xsl:variable name="leader7" select="substring($leader,8,1)"/>
+        <xsl:variable name="leader19" select="substring($leader,20,1)"/>
+        <xsl:variable name="controlField008" select="marc:controlfield[@tag='008']"/>
+        <xsl:variable name="typeOf008">
+            <xsl:choose>
+                <xsl:when test="$leader6='a'">
+                    <xsl:choose>
+                        <xsl:when test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'">BK</xsl:when>
+                        <xsl:when test="$leader7='b' or $leader7='i' or $leader7='s'">SE</xsl:when>
+                    </xsl:choose>
+                </xsl:when>
+                <xsl:when test="$leader6='t'">BK</xsl:when>
+                <xsl:when test="$leader6='p'">MM</xsl:when>
+                <xsl:when test="$leader6='m'">CF</xsl:when>
+                <xsl:when test="$leader6='e' or $leader6='f'">MP</xsl:when>
+                <xsl:when test="$leader6='g' or $leader6='k' or $leader6='o' or $leader6='r'">VM</xsl:when>
+                <xsl:when test="$leader6='c' or $leader6='d' or $leader6='i' or $leader6='j'">MU</xsl:when>
+            </xsl:choose>
+        </xsl:variable>
+
+        <!-- titleInfo -->
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='245'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'245')]">
+            <xsl:call-template name="createTitleInfoFrom245"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='210'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'210')]">
+            <xsl:call-template name="createTitleInfoFrom210"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='246'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'246')]">
+            <xsl:call-template name="createTitleInfoFrom246"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='240'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'240')]">
+            <xsl:call-template name="createTitleInfoFrom240"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='740'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'740')]">
+            <xsl:call-template name="createTitleInfoFrom740"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='130'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'130')]">
+            <xsl:call-template name="createTitleInfoFrom130"/>
+        </xsl:for-each>
+        <!-- 1.121, 1.131-->
+        <xsl:for-each select="marc:datafield[@tag='730'][@ind2 !='2'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'730')][@ind2 !='2']">
+            <xsl:call-template name="createTitleInfoFrom730"/>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag='242']">
+            <titleInfo type="translated">
+
+                <!--09/01/04 Added subfield $y-->
+                <xsl:for-each select="marc:subfield[@code='y']">
+                    <xsl:attribute name="lang">
+                        <xsl:value-of select="text()"/>
+                    </xsl:attribute>
+                </xsl:for-each>
+
+                <!-- AQ1.27 tmee/dlf -->
+                <xsl:variable name="title">
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString">
+                            <xsl:call-template name="subfieldSelect">
+                                <!-- 1/04 removed $h, b -->
+                                <xsl:with-param name="codes">a</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </xsl:variable>
+                <xsl:variable name="titleChop">
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString">
+                            <xsl:value-of select="$title"/>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </xsl:variable>
+                <xsl:choose>
+                    <!-- 1.120 - @245/@880$ind2-->
+                    <xsl:when test="@ind2 != ' ' and @ind2&gt;0">
+                        <!-- 1.112 -->
+                        <nonSort xml:space="preserve"><xsl:value-of select="substring($titleChop,1,@ind2)"/> </nonSort>
+                        <title>
+                            <xsl:value-of select="substring($titleChop,@ind2+1)"/>
+                        </title>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <title>
+                            <xsl:value-of select="$titleChop"/>
+                        </title>
+                    </xsl:otherwise>
+                </xsl:choose>
+
+                <!-- 1/04 fix -->
+                <xsl:call-template name="subtitle"/>
+                <xsl:call-template name="part"/>
+            </titleInfo>
+        </xsl:for-each>
+
+        <!-- name -->
+        <!-- 1.121 --><!-- 1.108  -->
+        <xsl:for-each select="marc:datafield[@tag='100'][not(marc:subfield[@code='t'])] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'100')][not(marc:subfield[@code='t'])]">
+            <xsl:call-template name="createNameFrom100"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='110'][not(marc:subfield[@code='t'])] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'110')][not(marc:subfield[@code='t'])]">
+            <xsl:call-template name="createNameFrom110"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='111'][not(marc:subfield[@code='t'])] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'111')][not(marc:subfield[@code='t'])]">
+            <xsl:call-template name="createNameFrom111"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='700'][not(marc:subfield[@code='t'])] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'700')][not(marc:subfield[@code='t'])]">
+            <xsl:call-template name="createNameFrom700"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='710'][not(marc:subfield[@code='t'])] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'710')][not(marc:subfield[@code='t'])]">
+            <xsl:call-template name="createNameFrom710"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='711'][not(marc:subfield[@code='t'])] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'711')][not(marc:subfield[@code='t'])]">
+            <xsl:call-template name="createNameFrom711"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='720'][not(marc:subfield[@code='t'])] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'720')][not(marc:subfield[@code='t'])]">
+            <xsl:call-template name="createNameFrom720"/>
+        </xsl:for-each>
+
+        <!--old 7XXs
+        <xsl:for-each select="marc:datafield[@tag='700'][not(marc:subfield[@code='t'])]">
+            <name type="personal">
+                <xsl:call-template name="nameABCDQ"/>
+                <xsl:call-template name="affiliation"/>
+                <xsl:call-template name="role"/>
+            </name>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag='710'][not(marc:subfield[@code='t'])]">
+            <name type="corporate">
+                <xsl:call-template name="nameABCDN"/>
+                <xsl:call-template name="role"/>
+            </name>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag='711'][not(marc:subfield[@code='t'])]">
+            <name type="conference">
+                <xsl:call-template name="nameACDEQ"/>
+                <xsl:call-template name="role"/>
+            </name>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag='720'][not(marc:subfield[@code='t'])]">
+        <name>
+        <xsl:if test="@ind1=1">
+        <xsl:attribute name="type">
+        <xsl:text>personal</xsl:text>
+        </xsl:attribute>
+        </xsl:if>
+        <namePart>
+        <xsl:value-of select="marc:subfield[@code='a']"/>
+        </namePart>
+        <xsl:call-template name="role"/>
+        </name>
+        </xsl:for-each>
+-->
+
+        <typeOfResource>
+            <xsl:if test="$leader7='c'">
+                <xsl:attribute name="collection">yes</xsl:attribute>
+            </xsl:if>
+            <xsl:if test="$leader6='d' or $leader6='f' or $leader6='p' or $leader6='t'">
+                <xsl:attribute name="manuscript">yes</xsl:attribute>
+            </xsl:if>
+            <xsl:choose>
+                <xsl:when test="$leader6='a' or $leader6='t'">text</xsl:when>
+                <xsl:when test="$leader6='e' or $leader6='f'">cartographic</xsl:when>
+                <xsl:when test="$leader6='c' or $leader6='d'">notated music</xsl:when>
+                <xsl:when test="$leader6='i'">sound recording-nonmusical</xsl:when>
+                <xsl:when test="$leader6='j'">sound recording-musical</xsl:when>
+                <xsl:when test="$leader6='k'">still image</xsl:when>
+                <xsl:when test="$leader6='g'">moving image</xsl:when>
+                <xsl:when test="$leader6='r'">three dimensional object</xsl:when>
+                <xsl:when test="$leader6='m'">software, multimedia</xsl:when>
+                <xsl:when test="$leader6='p'">mixed material</xsl:when>
+            </xsl:choose>
+        </typeOfResource>
+        <xsl:if test="substring($controlField008,26,1)='d'">
+            <genre authority="marcgt">globe</genre>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
+            <genre authority="marcgt">remote-sensing image</genre>
+        </xsl:if>
+        <xsl:if test="$typeOf008='MP'">
+            <xsl:variable name="controlField008-25" select="substring($controlField008,26,1)"/>
+            <xsl:choose>
+                <xsl:when test="$controlField008-25='a' or $controlField008-25='b' or $controlField008-25='c' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='j']">
+                    <genre authority="marcgt">map</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-25='e' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
+                    <genre authority="marcgt">atlas</genre>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+        <xsl:if test="$typeOf008='SE'">
+            <xsl:variable name="controlField008-21" select="substring($controlField008,22,1)"/>
+            <xsl:choose>
+                <xsl:when test="$controlField008-21='d'">
+                    <genre authority="marcgt">database</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-21='l'">
+                    <genre authority="marcgt">loose-leaf</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-21='m'">
+                    <genre authority="marcgt">series</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-21='n'">
+                    <genre authority="marcgt">newspaper</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-21='p'">
+                    <genre authority="marcgt">periodical</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-21='w'">
+                    <genre authority="marcgt">web site</genre>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+        <xsl:if test="$typeOf008='BK' or $typeOf008='SE'">
+            <xsl:variable name="controlField008-24" select="substring($controlField008,25,4)"/>
+            <xsl:choose>
+                <xsl:when test="contains($controlField008-24,'a')">
+                    <genre authority="marcgt">abstract or summary</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'b')">
+                    <genre authority="marcgt">bibliography</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'c')">
+                    <genre authority="marcgt">catalog</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'d')">
+                    <genre authority="marcgt">dictionary</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'e')">
+                    <genre authority="marcgt">encyclopedia</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'f')">
+                    <genre authority="marcgt">handbook</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'g')">
+                    <genre authority="marcgt">legal article</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'i')">
+                    <genre authority="marcgt">index</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'k')">
+                    <genre authority="marcgt">discography</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'l')">
+                    <genre authority="marcgt">legislation</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'m')">
+                    <genre authority="marcgt">theses</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'n')">
+                    <genre authority="marcgt">survey of literature</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'o')">
+                    <genre authority="marcgt">review</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'p')">
+                    <genre authority="marcgt">programmed text</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'q')">
+                    <genre authority="marcgt">filmography</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'r')">
+                    <genre authority="marcgt">directory</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'s')">
+                    <genre authority="marcgt">statistics</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'t')">
+                    <genre authority="marcgt">technical report</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'v')">
+                    <genre authority="marcgt">legal case and case notes</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'w')">
+                    <genre authority="marcgt">law report or digest</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-24,'z')">
+                    <genre authority="marcgt">treaty</genre>
+                </xsl:when>
+            </xsl:choose>
+            <xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"/>
+            <xsl:choose>
+                <xsl:when test="$controlField008-29='1'">
+                    <genre authority="marcgt">conference publication</genre>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+        <xsl:if test="$typeOf008='CF'">
+            <xsl:variable name="controlField008-26" select="substring($controlField008,27,1)"/>
+            <xsl:choose>
+                <xsl:when test="$controlField008-26='a'">
+                    <genre authority="marcgt">numeric data</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-26='e'">
+                    <genre authority="marcgt">database</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-26='f'">
+                    <genre authority="marcgt">font</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-26='g'">
+                    <genre authority="marcgt">game</genre>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+        <xsl:if test="$typeOf008='BK'">
+            <xsl:if test="substring($controlField008,25,1)='j'">
+                <genre authority="marcgt">patent</genre>
+            </xsl:if>
+            <xsl:if test="substring($controlField008,25,1)='2'">
+                <genre authority="marcgt">offprint</genre>
+            </xsl:if>
+            <xsl:if test="substring($controlField008,31,1)='1'">
+                <genre authority="marcgt">festschrift</genre>
+            </xsl:if>
+            <xsl:variable name="controlField008-34" select="substring($controlField008,35,1)"/>
+            <xsl:if test="$controlField008-34='a' or $controlField008-34='b' or $controlField008-34='c' or $controlField008-34='d'">
+                <genre authority="marcgt">biography</genre>
+            </xsl:if>
+            <xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"/>
+            <xsl:choose>
+                <xsl:when test="$controlField008-33='e'">
+                    <genre authority="marcgt">essay</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='d'">
+                    <genre authority="marcgt">drama</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='c'">
+                    <genre authority="marcgt">comic strip</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='l'">
+                    <genre authority="marcgt">fiction</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='h'">
+                    <genre authority="marcgt">humor, satire</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='i'">
+                    <genre authority="marcgt">letter</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='f'">
+                    <genre authority="marcgt">novel</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='j'">
+                    <genre authority="marcgt">short story</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='s'">
+                    <genre authority="marcgt">speech</genre>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+        <xsl:if test="$typeOf008='MU'">
+            <xsl:variable name="controlField008-30-31" select="substring($controlField008,31,2)"/>
+            <xsl:if test="contains($controlField008-30-31,'b')">
+                <genre authority="marcgt">biography</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'c')">
+                <genre authority="marcgt">conference publication</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'d')">
+                <genre authority="marcgt">drama</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'e')">
+                <genre authority="marcgt">essay</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'f')">
+                <genre authority="marcgt">fiction</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'o')">
+                <genre authority="marcgt">folktale</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'h')">
+                <genre authority="marcgt">history</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'k')">
+                <genre authority="marcgt">humor, satire</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'m')">
+                <genre authority="marcgt">memoir</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'p')">
+                <genre authority="marcgt">poetry</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'r')">
+                <genre authority="marcgt">rehearsal</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'g')">
+                <genre authority="marcgt">reporting</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'s')">
+                <genre authority="marcgt">sound</genre>
+            </xsl:if>
+            <xsl:if test="contains($controlField008-30-31,'l')">
+                <genre authority="marcgt">speech</genre>
+            </xsl:if>
+        </xsl:if>
+        <xsl:if test="$typeOf008='VM'">
+            <xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"/>
+            <xsl:choose>
+                <xsl:when test="$controlField008-33='a'">
+                    <genre authority="marcgt">art original</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='b'">
+                    <genre authority="marcgt">kit</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='c'">
+                    <genre authority="marcgt">art reproduction</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='d'">
+                    <genre authority="marcgt">diorama</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='f'">
+                    <genre authority="marcgt">filmstrip</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='g'">
+                    <genre authority="marcgt">legal article</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='i'">
+                    <genre authority="marcgt">picture</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='k'">
+                    <genre authority="marcgt">graphic</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='l'">
+                    <genre authority="marcgt">technical drawing</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='m'">
+                    <genre authority="marcgt">motion picture</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='n'">
+                    <genre authority="marcgt">chart</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='o'">
+                    <genre authority="marcgt">flash card</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='p'">
+                    <genre authority="marcgt">microscope slide</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='q' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
+                    <genre authority="marcgt">model</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='r'">
+                    <genre authority="marcgt">realia</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='s'">
+                    <genre authority="marcgt">slide</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='t'">
+                    <genre authority="marcgt">transparency</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='v'">
+                    <genre authority="marcgt">videorecording</genre>
+                </xsl:when>
+                <xsl:when test="$controlField008-33='w'">
+                    <genre authority="marcgt">toy</genre>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+
+<!-- 111$n, 711$n 1.103 -->
+
+        <xsl:if test="$typeOf008='BK'">
+            <xsl:variable name="controlField008-28" select="substring($controlField008,29,1)"/>
+            <xsl:choose>
+                <xsl:when test="contains($controlField008-28,'a')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'c')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'f')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'m')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'i')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'l')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'m')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'o')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'s')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'u')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'z')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'|')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+        <xsl:if test="$typeOf008='CF'">
+            <xsl:variable name="controlField008-28" select="substring($controlField008,29,1)"/>
+            <xsl:choose>
+                <xsl:when test="contains($controlField008-28,'a')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'c')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'f')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'m')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'i')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'l')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'m')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'o')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'s')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'u')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'z')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'|')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+        <xsl:if test="$typeOf008='CR'">
+            <xsl:variable name="controlField008-28" select="substring($controlField008,29,1)"/>
+            <xsl:choose>
+                <xsl:when test="contains($controlField008-28,'a')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'c')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'f')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'m')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'i')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'l')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'m')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'o')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'s')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'u')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'z')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'|')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+        <xsl:if test="$typeOf008='MP'">
+            <xsl:variable name="controlField008-28" select="substring($controlField008,29,1)"/>
+            <xsl:choose>
+                <xsl:when test="contains($controlField008-28,'a')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'c')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'f')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'m')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'i')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'l')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'m')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'o')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'s')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'u')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'z')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'|')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+        <xsl:if test="$typeOf008='VM'">
+            <xsl:variable name="controlField008-28" select="substring($controlField008,29,1)"/>
+            <xsl:choose>
+                <xsl:when test="contains($controlField008-28,'a')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'c')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'f')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'m')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'i')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'l')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'m')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'o')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'s')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'u')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'z')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+                <xsl:when test="contains($controlField008-28,'|')">
+                    <genre authority="marcgt">government publication</genre>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+
+
+        <!-- genre -->
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=047] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'047')]">
+            <xsl:call-template name="createGenreFrom047"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=336] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'336')]">
+            <xsl:call-template name="createGenreFrom336"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=655] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'655')]">
+            <xsl:call-template name="createGenreFrom655"/>
+        </xsl:for-each>
+
+        <!-- 1.130 originInfo  -->
+        <xsl:call-template name="originInfo">
+            <xsl:with-param name="leader6" select="$leader6"/>
+            <xsl:with-param name="leader7" select="$leader7"/>
+            <xsl:with-param name="leader19" select="$leader19"/>
+            <xsl:with-param name="typeOf008" select="$typeOf008"/>
+            <xsl:with-param name="controlField008" select="$controlField008"/>
+        </xsl:call-template>
+
+        <!-- 1.130 depreciated
+        <originInfo>
+            <xsl:call-template name="scriptCode"/>
+            <xsl:for-each select="marc:datafield[(@tag=260 or @tag=250) and marc:subfield[@code='a' or code='b' or @code='c' or code='g']]">
+                <xsl:call-template name="z2xx880"/>
+            </xsl:for-each>
+
+            <xsl:variable name="MARCpublicationCode" select="normalize-space(substring($controlField008,16,3))"/>
+            <xsl:if test="translate($MARCpublicationCode,'|','')">
+                <place>
+                    <placeTerm>
+                        <xsl:attribute name="type">code</xsl:attribute>
+                        <xsl:attribute name="authority">marccountry</xsl:attribute>
+                        <xsl:value-of select="$MARCpublicationCode"/>
+                    </placeTerm>
+                </place>
+            </xsl:if>
+            <xsl:for-each select="marc:datafield[@tag=044]/marc:subfield[@code='c']">
+                <place>
+                    <placeTerm>
+                        <xsl:attribute name="type">code</xsl:attribute>
+                        <xsl:attribute name="authority">iso3166</xsl:attribute>
+                        <xsl:value-of select="."/>
+                    </placeTerm>
+                </place>
+            </xsl:for-each>
+            <xsl:for-each select="marc:datafield[@tag=260]/marc:subfield[@code='a']">
+                <place>
+                    <placeTerm>
+                        <xsl:attribute name="type">text</xsl:attribute>
+                        <xsl:call-template name="chopPunctuationFront">
+                            <xsl:with-param name="chopString">
+                                <xsl:call-template name="chopPunctuation">
+                                    <xsl:with-param name="chopString" select="."/>
+                                </xsl:call-template>
+                            </xsl:with-param>
+                        </xsl:call-template>
+                    </placeTerm>
+                </place>
+            </xsl:for-each>
+            <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='m']">
+                <dateValid point="start">
+                    <xsl:value-of select="."/>
+                </dateValid>
+            </xsl:for-each>
+            <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='n']">
+                <dateValid point="end">
+                    <xsl:value-of select="."/>
+                </dateValid>
+            </xsl:for-each>
+            <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='j']">
+                <dateModified>
+                    <xsl:value-of select="."/>
+                </dateModified>
+            </xsl:for-each>
+
+            //- tmee 1.52 -//
+
+            <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='c']">
+                <dateIssued encoding="marc" point="start">
+                    <xsl:value-of select="."/>
+                </dateIssued>
+            </xsl:for-each>
+            <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='e']">
+                <dateIssued encoding="marc" point="end">
+                    <xsl:value-of select="."/>
+                </dateIssued>
+            </xsl:for-each>
+
+            <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='k']">
+                <dateCreated encoding="marc" point="start">
+                    <xsl:value-of select="."/>
+                </dateCreated>
+            </xsl:for-each>
+            <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='l']">
+                <dateCreated encoding="marc" point="end">
+                    <xsl:value-of select="."/>
+                </dateCreated>
+            </xsl:for-each>
+
+            //- tmee 1.35 1.36 dateIssued/nonMSS vs dateCreated/MSS -//
+            <xsl:for-each select="marc:datafield[@tag=260]/marc:subfield[@code='b' or @code='c' or @code='g']">
+                <xsl:choose>
+                    <xsl:when test="@code='b'">
+                        <publisher>
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString" select="."/>
+                                <xsl:with-param name="punctuation">
+                                    <xsl:text>:,;/ </xsl:text>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </publisher>
+                    </xsl:when>
+                    <xsl:when test="(@code='c')">
+                        <xsl:if test="$leader6='d' or $leader6='f' or $leader6='p' or $leader6='t'">
+                            <dateCreated>
+                                <xsl:call-template name="chopPunctuation">
+                                    <xsl:with-param name="chopString" select="."/>
+                                </xsl:call-template>
+                            </dateCreated>
+                        </xsl:if>
+
+                        <xsl:if test="not($leader6='d' or $leader6='f' or $leader6='p' or $leader6='t')">
+                            <dateIssued>
+                                <xsl:call-template name="chopPunctuation">
+                                    <xsl:with-param name="chopString" select="."/>
+                                </xsl:call-template>
+                            </dateIssued>
+                        </xsl:if>
+                    </xsl:when>
+                    <xsl:when test="@code='g'">
+                        <xsl:if test="$leader6='d' or $leader6='f' or $leader6='p' or $leader6='t'">
+                            <dateCreated>
+                                <xsl:value-of select="."/>
+                            </dateCreated>
+                        </xsl:if>
+                        <xsl:if test="not($leader6='d' or $leader6='f' or $leader6='p' or $leader6='t')">
+                            <dateCreated>
+                                <xsl:value-of select="."/>
+                            </dateCreated>
+                        </xsl:if>
+                    </xsl:when>
+                </xsl:choose>
+            </xsl:for-each>
+            <xsl:variable name="dataField260c">
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString" select="marc:datafield[@tag=260]/marc:subfield[@code='c']"/>
+                </xsl:call-template>
+            </xsl:variable>
+            <xsl:variable name="controlField008-7-10" select="normalize-space(substring($controlField008, 8, 4))"/>
+            <xsl:variable name="controlField008-11-14" select="normalize-space(substring($controlField008, 12, 4))"/>
+            <xsl:variable name="controlField008-6" select="normalize-space(substring($controlField008, 7, 1))"/>
+
+            //- tmee 1.35 and 1.36 and 1.84-//
+            <xsl:if test="($controlField008-6='e' or $controlField008-6='p' or $controlField008-6='r' or $controlField008-6='s' or $controlField008-6='t') and ($leader6='d' or $leader6='f' or $leader6='p' or $leader6='t')">
+                <xsl:if test="$controlField008-7-10 and ($controlField008-7-10 != $dataField260c)">
+                    <dateCreated encoding="marc">
+                        <xsl:value-of select="$controlField008-7-10"/>
+                    </dateCreated>
+                </xsl:if>
+            </xsl:if>
+
+            <xsl:if test="($controlField008-6='e' or $controlField008-6='p' or $controlField008-6='r' or $controlField008-6='s' or $controlField008-6='t') and not($leader6='d' or $leader6='f' or $leader6='p' or $leader6='t')">
+                <xsl:if test="$controlField008-7-10 and ($controlField008-7-10 != $dataField260c)">
+                    <dateIssued encoding="marc">
+                        <xsl:value-of select="$controlField008-7-10"/></dateIssued>
+                </xsl:if>
+            </xsl:if>
+
+            <xsl:if test="$controlField008-6='c' or $controlField008-6='d' or $controlField008-6='i' or $controlField008-6='k' or $controlField008-6='m' or $controlField008-6='u'">
+                <xsl:if test="$controlField008-7-10">
+                    <dateIssued encoding="marc" point="start">
+                        <xsl:value-of select="$controlField008-7-10"/>
+                    </dateIssued>
+                </xsl:if>
+            </xsl:if>
+
+            <xsl:if test="$controlField008-6='c' or $controlField008-6='d' or $controlField008-6='i' or $controlField008-6='k' or $controlField008-6='m' or $controlField008-6='u'">
+                <xsl:if test="$controlField008-11-14">
+                    <dateIssued encoding="marc" point="end">
+                        <xsl:value-of select="$controlField008-11-14"/>
+                    </dateIssued>
+                </xsl:if>
+            </xsl:if>
+
+            <xsl:if test="$controlField008-6='q'">
+                <xsl:if test="$controlField008-7-10">
+                    <dateIssued encoding="marc" point="start" qualifier="questionable">
+                        <xsl:value-of select="$controlField008-7-10"/>
+                    </dateIssued>
+                </xsl:if>
+            </xsl:if>
+            <xsl:if test="$controlField008-6='q'">
+                <xsl:if test="$controlField008-11-14">
+                    <dateIssued encoding="marc" point="end" qualifier="questionable">
+                        <xsl:value-of select="$controlField008-11-14"/>
+                    </dateIssued>
+                </xsl:if>
+            </xsl:if>
+            //- tmee 1.77 008-06 dateIssued for value 's' 1.89 removed 20130920
+            <xsl:if test="$controlField008-6='s'">
+                <xsl:if test="$controlField008-7-10">
+                    <dateIssued encoding="marc">
+                        <xsl:value-of select="$controlField008-7-10"/>
+                    </dateIssued>
+                </xsl:if>
+            </xsl:if>
+            -//
+
+            <xsl:if test="$controlField008-6='t'">
+                <xsl:if test="$controlField008-11-14">
+                    <copyrightDate encoding="marc">
+                        <xsl:value-of select="$controlField008-11-14"/>
+                    </copyrightDate>
+                </xsl:if>
+            </xsl:if>
+            <xsl:for-each select="marc:datafield[@tag=033][@ind1=0 or @ind1=1]/marc:subfield[@code='a']">
+                <dateCaptured encoding="iso8601">
+                    <xsl:value-of select="."/>
+                </dateCaptured>
+            </xsl:for-each>
+            <xsl:for-each select="marc:datafield[@tag=033][@ind1=2]/marc:subfield[@code='a'][1]">
+                <dateCaptured encoding="iso8601" point="start">
+                    <xsl:value-of select="."/>
+                </dateCaptured>
+            </xsl:for-each>
+            <xsl:for-each select="marc:datafield[@tag=033][@ind1=2]/marc:subfield[@code='a'][2]">
+                <dateCaptured encoding="iso8601" point="end">
+                    <xsl:value-of select="."/>
+                </dateCaptured>
+            </xsl:for-each>
+            <xsl:for-each select="marc:datafield[@tag=250]/marc:subfield[@code='a']">
+                <edition>
+                    <xsl:value-of select="."/>
+                </edition>
+            </xsl:for-each>
+            <xsl:for-each select="marc:leader">
+                //- 1.120 - @260$issuance -//
+                <xsl:if test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m' or $leader7='b'
+                    or ($leader7='m' and ($leader19='a' or $leader19='b' or $leader19='c'))
+                    or ($leader7='m' and ($leader19=' ')) or $leader7='m' and ($leader19='#') or $leader7='i' or $leader7='s'">
+                    <issuance>
+                        <xsl:choose>
+                            <xsl:when test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'">monographic</xsl:when>
+                            <xsl:when test="$leader7='m' and ($leader19='a' or $leader19='b' or $leader19='c')">multipart monograph</xsl:when>
+                            //- 1.106 20141218 -//
+                            <xsl:when test="$leader7='m' and ($leader19=' ')">single unit</xsl:when>
+                            <xsl:when test="$leader7='m' and ($leader19='#')">single unit</xsl:when>
+                            <xsl:when test="$leader7='i'">integrating resource</xsl:when>
+                            <xsl:when test="$leader7='b' or $leader7='s'">serial</xsl:when>
+                        </xsl:choose>
+                    </issuance>
+                </xsl:if>
+            </xsl:for-each>
+
+            //- 1.96 20140422 -//
+            <xsl:for-each select="marc:datafield[@tag=310]|marc:datafield[@tag=321]">
+                <frequency>
+                    <xsl:call-template name="subfieldSelect">
+                        <xsl:with-param name="codes">ab</xsl:with-param>
+                    </xsl:call-template>
+                </frequency>
+            </xsl:for-each>
+
+            //- 1.67 1.72 updated fixed location issue 201308 1.86    -//
+
+            <xsl:if test="$typeOf008='SE'">
+                <xsl:for-each select="marc:controlfield[@tag=008]">
+                    <xsl:variable name="controlField008-18" select="substring($controlField008,19,1)"/>
+                    <xsl:variable name="frequency">
+                        <frequency>
+                            <xsl:choose>
+                                <xsl:when test="$controlField008-18='a'">Annual</xsl:when>
+                                <xsl:when test="$controlField008-18='b'">Bimonthly</xsl:when>
+                                <xsl:when test="$controlField008-18='c'">Semiweekly</xsl:when>
+                                <xsl:when test="$controlField008-18='d'">Daily</xsl:when>
+                                <xsl:when test="$controlField008-18='e'">Biweekly</xsl:when>
+                                <xsl:when test="$controlField008-18='f'">Semiannual</xsl:when>
+                                <xsl:when test="$controlField008-18='g'">Biennial</xsl:when>
+                                <xsl:when test="$controlField008-18='h'">Triennial</xsl:when>
+                                <xsl:when test="$controlField008-18='i'">Three times a week</xsl:when>
+                                <xsl:when test="$controlField008-18='j'">Three times a month</xsl:when>
+                                <xsl:when test="$controlField008-18='k'">Continuously updated</xsl:when>
+                                <xsl:when test="$controlField008-18='m'">Monthly</xsl:when>
+                                <xsl:when test="$controlField008-18='q'">Quarterly</xsl:when>
+                                <xsl:when test="$controlField008-18='s'">Semimonthly</xsl:when>
+                                <xsl:when test="$controlField008-18='t'">Three times a year</xsl:when>
+                                <xsl:when test="$controlField008-18='u'">Unknown</xsl:when>
+                                <xsl:when test="$controlField008-18='w'">Weekly</xsl:when>
+                                //- 1.106 20141218 -//
+                                <xsl:when test="$controlField008-18=' '">Completely irregular</xsl:when>
+                                <xsl:when test="$controlField008-18='#'">Completely irregular</xsl:when>
+                                <xsl:otherwise/>
+                            </xsl:choose>
+                        </frequency>
+                    </xsl:variable>
+                    <xsl:if test="$frequency!=''">
+                        <frequency authority="marcfrequency">
+                            <xsl:value-of select="$frequency"/>
+                        </frequency>
+                    </xsl:if>
+                </xsl:for-each>
+            </xsl:if>
+        </originInfo>
+-->
+
+        <!-- originInfo - 264 -->
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=264][@ind2=0] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'264')][@ind2=0]">
+            <!-- 1.120 - @264/ind2 -->
+            <originInfo eventType="producer">
+                <!-- Template checks for altRepGroup - 880 $6 -->
+                <xsl:call-template name="xxx880"/>
+                <!-- 1.133 -->
+                <xsl:choose>
+                    <xsl:when test="count(marc:subfield[@code='a']) &gt; 1">
+                        <xsl:for-each select="marc:subfield[@code='a']">
+                            <place>
+                                <placeTerm type="text">
+                                    <xsl:value-of select="."/>
+                                </placeTerm>
+                            </place>
+                            <xsl:if test="following-sibling::marc:subfield[@code='b']">
+                                <xsl:for-each select="following-sibling::marc:subfield[@code='b'][1]">
+                                    <publisher><xsl:value-of select="."/></publisher>
+                                </xsl:for-each>
+                            </xsl:if>
+                        </xsl:for-each>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <place>
+                            <placeTerm type="text">
+                                <xsl:value-of select="marc:subfield[@code='a']"/>
+                            </placeTerm>
+                        </place>
+                        <publisher>
+                            <xsl:value-of select="marc:subfield[@code='b']"/>
+                        </publisher>
+                    </xsl:otherwise>
+                </xsl:choose>
+                <!-- 1.134 -->
+                <xsl:if test="marc:subfield[@code='c']">
+                    <dateOther type="production">
+                        <xsl:value-of select="marc:subfield[@code='c']"/>
+                    </dateOther>
+                </xsl:if>
+            </originInfo>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=264][@ind2=1] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'264')][@ind2=1]">
+            <!-- 1.120 - @264/ind2 -->
+            <originInfo eventType="publisher">
+                <!-- Template checks for altRepGroup - 880 $6 1.88 20130829 added chopPunc-->
+                <xsl:call-template name="xxx880"/>
+                <!-- 1.133 -->
+                <xsl:choose>
+                    <xsl:when test="count(marc:subfield[@code='a']) &gt; 1">
+                        <xsl:for-each select="marc:subfield[@code='a']">
+                            <place>
+                                <placeTerm type="text">
+                                    <xsl:value-of select="."/>
+                                </placeTerm>
+                            </place>
+                            <xsl:if test="following-sibling::marc:subfield[@code='b']">
+                                <xsl:for-each select="following-sibling::marc:subfield[@code='b'][1]">
+                                    <publisher><xsl:value-of select="."/></publisher>
+                                </xsl:for-each>
+                            </xsl:if>
+                        </xsl:for-each>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <place>
+                            <placeTerm type="text">
+                                <xsl:value-of select="marc:subfield[@code='a']"/>
+                            </placeTerm>
+                        </place>
+                        <publisher>
+                            <xsl:value-of select="marc:subfield[@code='b']"/>
+                        </publisher>
+                    </xsl:otherwise>
+                </xsl:choose>
+                <!-- 1.134 -->
+                <xsl:if test="marc:subfield[@code='c']">
+                <dateIssued>
+                    <xsl:value-of select="marc:subfield[@code='c']"/>
+                </dateIssued>
+                </xsl:if>
+            </originInfo>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=264][@ind2=2] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'264')][@ind2=2]">
+            <!-- 1.120 - @264/ind2 -->
+            <originInfo eventType="distributor">
+                <!-- Template checks for altRepGroup - 880 $6 -->
+                <xsl:call-template name="xxx880"/>
+                <!-- 1.133 -->
+                <xsl:choose>
+                    <xsl:when test="count(marc:subfield[@code='a']) &gt; 1">
+                        <xsl:for-each select="marc:subfield[@code='a']">
+                            <place>
+                                <placeTerm type="text">
+                                    <xsl:value-of select="."/>
+                                </placeTerm>
+                            </place>
+                            <xsl:if test="following-sibling::marc:subfield[@code='b']">
+                                <xsl:for-each select="following-sibling::marc:subfield[@code='b'][1]">
+                                    <publisher><xsl:value-of select="."/></publisher>
+                                </xsl:for-each>
+                            </xsl:if>
+                        </xsl:for-each>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <place>
+                            <placeTerm type="text">
+                                <xsl:value-of select="marc:subfield[@code='a']"/>
+                            </placeTerm>
+                        </place>
+                        <publisher>
+                            <xsl:value-of select="marc:subfield[@code='b']"/>
+                        </publisher>
+                    </xsl:otherwise>
+                </xsl:choose>
+                <!-- 1.134 -->
+                <xsl:if test="marc:subfield[@code='c']">
+                <dateOther type="distribution">
+                    <xsl:value-of select="marc:subfield[@code='c']"/>
+                </dateOther>
+                </xsl:if>
+            </originInfo>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=264][@ind2=3] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'264')][@ind2=3]">
+            <!-- 1.120 - @264/ind2 -->
+            <originInfo eventType="manufacturer">
+                <!-- Template checks for altRepGroup - 880 $6 -->
+                <xsl:call-template name="xxx880"/>
+                <!-- 1.133 -->
+                <xsl:choose>
+                    <xsl:when test="count(marc:subfield[@code='a']) &gt; 1">
+                        <xsl:for-each select="marc:subfield[@code='a']">
+                            <place>
+                                <placeTerm type="text">
+                                    <xsl:value-of select="."/>
+                                </placeTerm>
+                            </place>
+                            <xsl:if test="following-sibling::marc:subfield[@code='b']">
+                                <xsl:for-each select="following-sibling::marc:subfield[@code='b'][1]">
+                                    <publisher><xsl:value-of select="."/></publisher>
+                                </xsl:for-each>
+                            </xsl:if>
+                        </xsl:for-each>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <place>
+                            <placeTerm type="text">
+                                <xsl:value-of select="marc:subfield[@code='a']"/>
+                            </placeTerm>
+                        </place>
+                        <publisher>
+                            <xsl:value-of select="marc:subfield[@code='b']"/>
+                        </publisher>
+                    </xsl:otherwise>
+                </xsl:choose>
+                <!-- 1.134 -->
+                <xsl:if test="marc:subfield[@code='c']">
+                <dateOther type="manufacture">
+                    <xsl:value-of select="marc:subfield[@code='c']"/>
+                </dateOther>
+                </xsl:if>
+            </originInfo>
+        </xsl:for-each>
+        <!-- 1.130 depreciated
+        <xsl:for-each select="marc:datafield[@tag=880]">
+            <xsl:variable name="related_datafield" select="substring-before(marc:subfield[@code='6'],'-')"/>
+            <xsl:variable name="occurence_number" select="substring( substring-after(marc:subfield[@code='6'],'-') , 1 , 2 )"/>
+            <xsl:variable name="hit" select="../marc:datafield[@tag=$related_datafield and contains(marc:subfield[@code='6'] , concat('880-' , $occurence_number))]/@tag"/>
+
+            <xsl:choose>
+                <xsl:when test="$hit='260'">
+                    <originInfo>
+                        <xsl:call-template name="scriptCode"/>
+                        <xsl:for-each select="../marc:datafield[@tag=260 and marc:subfield[@code='a' or code='b' or @code='c' or code='g']]">
+                            <xsl:call-template name="z2xx880"/>
+                        </xsl:for-each>
+                        <xsl:if test="marc:subfield[@code='a']">
+                            <place>
+                                <placeTerm type="text">
+                                    <xsl:value-of select="marc:subfield[@code='a']"/>
+                                </placeTerm>
+                            </place>
+                        </xsl:if>
+                        <xsl:if test="marc:subfield[@code='b']">
+                            <publisher>
+                                <xsl:value-of select="marc:subfield[@code='b']"/>
+                            </publisher>
+                        </xsl:if>
+                        <xsl:if test="marc:subfield[@code='c']">
+                            <dateIssued>
+                                //- 1.128 -//
+                                <xsl:call-template name="chopPunctuation">
+                                    <xsl:with-param name="chopString" select="marc:subfield[@code='c']"/>
+                                </xsl:call-template>
+                            </dateIssued>
+                        </xsl:if>
+                        <xsl:if test="marc:subfield[@code='g']">
+                            <dateCreated>
+                                <xsl:value-of select="marc:subfield[@code='g']"/>
+                            </dateCreated>
+                        </xsl:if>
+                        <xsl:for-each select="../marc:datafield[@tag=880]/marc:subfield[@code=6][contains(text(),'250')]">
+                            <edition>
+                                <xsl:value-of select="following-sibling::marc:subfield"/>
+                            </edition>
+                        </xsl:for-each>
+                    </originInfo>
+                </xsl:when>
+                <xsl:when test="$hit='300'">
+                    <physicalDescription>
+                        <xsl:for-each select="../marc:datafield[@tag=300]">
+                            <xsl:call-template name="z3xx880"/>
+                        </xsl:for-each>
+                        <extent>
+                            <xsl:for-each select="marc:subfield">
+                                <xsl:if test="@code='a' or @code='3' or @code='b' or @code='c'">
+                                    <xsl:value-of select="."/>
+                                    <xsl:text> </xsl:text>
+                                </xsl:if>
+                            </xsl:for-each>
+                        </extent>
+                        <form>
+                            <xsl:attribute name="authority">
+                                <xsl:value-of select="marc:subfield[@code='2']"/>
+                            </xsl:attribute>
+                            <xsl:call-template name="xxx880"/>
+                            <xsl:call-template name="subfieldSelect">
+                                <xsl:with-param name="codes">a</xsl:with-param>
+                            </xsl:call-template>
+                        </form>
+                    </physicalDescription>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:for-each>
+-->
+
+        <!-- language 041 -->
+        <xsl:variable name="controlField008-35-37" select="normalize-space(translate(substring($controlField008,36,3),'|#',''))"/>
+        <xsl:if test="$controlField008-35-37">
+            <language>
+                <languageTerm authority="iso639-2b" type="code">
+                    <xsl:value-of select="substring($controlField008,36,3)"/>
+                </languageTerm>
+            </language>
+        </xsl:if>
+        <xsl:for-each select="marc:datafield[@tag=041]">
+            <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='d' or @code='e' or @code='f' or @code='g' or @code='h']">
+                <xsl:variable name="langCodes" select="."/>
+                <xsl:choose>
+                    <xsl:when test="../marc:subfield[@code='2']='rfc3066'">
+                        <!-- not stacked but could be repeated -->
+                        <xsl:call-template name="rfcLanguages">
+                            <xsl:with-param name="nodeNum">
+                                <xsl:value-of select="1"/>
+                            </xsl:with-param>
+                            <xsl:with-param name="usedLanguages">
+                                <xsl:text/>
+                            </xsl:with-param>
+                            <xsl:with-param name="controlField008-35-37">
+                                <xsl:value-of select="$controlField008-35-37"/>
+                            </xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <!-- iso -->
+                        <xsl:variable name="allLanguages">
+                            <xsl:copy-of select="$langCodes"/>
+                        </xsl:variable>
+                        <xsl:variable name="currentLanguage">
+                            <xsl:value-of select="substring($allLanguages,1,3)"/>
+                        </xsl:variable>
+                        <xsl:call-template name="isoLanguage">
+                            <xsl:with-param name="currentLanguage">
+                                <xsl:value-of select="substring($allLanguages,1,3)"/>
+                            </xsl:with-param>
+                            <xsl:with-param name="remainingLanguages">
+                                <xsl:value-of select="substring($allLanguages,4,string-length($allLanguages)-3)"/>
+                            </xsl:with-param>
+                            <xsl:with-param name="usedLanguages">
+                                <xsl:if test="$controlField008-35-37">
+                                    <xsl:value-of select="$controlField008-35-37"/>
+                                </xsl:if>
+                            </xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:otherwise>
+                </xsl:choose>
+            </xsl:for-each>
+        </xsl:for-each>
+
+        <!-- 1.129 physicalDescription  -->
+        <xsl:variable name="physicalDescription">
+            <xsl:call-template name="digitalOrigin">
+                <xsl:with-param name="typeOf008" select="$typeOf008"/>
+            </xsl:call-template>
+            <xsl:call-template name="form">
+                <xsl:with-param name="controlField008" select="$controlField008"/>
+                <xsl:with-param name="typeOf008" select="$typeOf008"/>
+                <xsl:with-param name="leader6" select="$leader6"/>
+            </xsl:call-template>
+            <xsl:call-template name="reformattingQuality"/>
+            <xsl:apply-templates
+                select="marc:datafield[@tag='130']/marc:subfield[@code='h'] | marc:datafield[@tag='240']/marc:subfield[@code='h'] |
+                marc:datafield[@tag='242']/marc:subfield[@code='h'] | marc:datafield[@tag='245']/marc:subfield[@code='h']
+                | marc:datafield[@tag='246']/marc:subfield[@code='h'] | marc:datafield[@tag='730']/marc:subfield[@code='h']
+                | marc:datafield[@tag='256']/marc:subfield[@code='a'] | marc:datafield[@tag='337']/marc:subfield[@code='a'] | marc:datafield[@tag='338']/marc:subfield[@code='a']"
+                mode="physDesc"/>
+            <xsl:apply-templates select="marc:datafield[@tag='856']/marc:subfield[@code='q']" mode="physDesc"/>
+            <xsl:apply-templates select="marc:datafield[@tag='300']" mode="physDesc"/>
+            <xsl:apply-templates select="marc:datafield[@tag='351']" mode="physDesc"/>
+        </xsl:variable>
+        <xsl:choose>
+            <xsl:when test="marc:datafield[@tag='130'][marc:subfield[@code='6']][child::*[@code='h']] or
+                marc:datafield[@tag='240'][marc:subfield[@code='6']][child::*[@code='h']] or
+                marc:datafield[@tag='242'][marc:subfield[@code='6']][child::*[@code='h']] or
+                marc:datafield[@tag='245'][marc:subfield[@code='6']][child::*[@code='h']] or
+                marc:datafield[@tag='246'][marc:subfield[@code='6']][child::*[@code='h']] or
+                marc:datafield[@tag='730'][marc:subfield[@code='6']][child::*[@code='h']] or
+                marc:datafield[@tag='256'][marc:subfield[@code='6']][child::*[@code='a']] or
+                marc:datafield[@tag='337'][marc:subfield[@code='6']][child::*[@code='a']] or
+                marc:datafield[@tag='338'][marc:subfield[@code='6']][child::*[@code='a']] or
+                marc:datafield[@tag='300'][marc:subfield[@code='6']] or
+                marc:datafield[@tag='856'][marc:subfield[@code='6']][child::*[@code='q']]">
+                <xsl:for-each select="marc:datafield[@tag='130'][marc:subfield[@code='6']]/child::*[@code='h'] |
+                    marc:datafield[@tag='240'][marc:subfield[@code='6']]/child::*[@code='h'] |
+                    marc:datafield[@tag='242'][marc:subfield[@code='6']]/child::*[@code='h'] |
+                    marc:datafield[@tag='245'][marc:subfield[@code='6']]/child::*[@code='h'] |
+                    marc:datafield[@tag='246'][marc:subfield[@code='6']]/child::*[@code='h'] |
+                    marc:datafield[@tag='730'][marc:subfield[@code='6']]/child::*[@code='h'] |
+                    marc:datafield[@tag='256'][marc:subfield[@code='6']]/child::*[@code='a'] |
+                    marc:datafield[@tag='337'][marc:subfield[@code='6']]/child::*[@code='a'] |
+                    marc:datafield[@tag='338'][marc:subfield[@code='6']]/child::*[@code='a'] |
+                    marc:datafield[@tag='300'][marc:subfield[@code='6']] |
+                    marc:datafield[@tag='856'][marc:subfield[@code='6']]/child::*[@code='q']">
+                    <physicalDescription>
+                        <!--  880 field -->
+                        <xsl:choose>
+                            <xsl:when test="self::marc:subfield"><xsl:call-template name="xxs880"/></xsl:when>
+                            <xsl:when test="self::marc:datafield"><xsl:call-template name="xxx880"/></xsl:when>
+                        </xsl:choose>
+                        <xsl:call-template name="digitalOrigin">
+                            <xsl:with-param name="typeOf008" select="$typeOf008"/>
+                        </xsl:call-template>
+                        <xsl:call-template name="form">
+                            <xsl:with-param name="controlField008" select="$controlField008"/>
+                            <xsl:with-param name="typeOf008" select="$typeOf008"/>
+                            <xsl:with-param name="leader6" select="$leader6"/>
+                        </xsl:call-template>
+                        <xsl:call-template name="reformattingQuality"/>
+                        <xsl:apply-templates select="." mode="physDesc"/>
+                    </physicalDescription>
+                </xsl:for-each>
+                <!-- Cover any physical -->
+                <xsl:if test="marc:datafield[@tag='130'][not(marc:subfield[@code='6'])][child::*[@code='h']] or
+                    marc:datafield[@tag='240'][not(marc:subfield[@code='6'])][child::*[@code='h']] or
+                    marc:datafield[@tag='242'][not(marc:subfield[@code='6'])][child::*[@code='h']] or
+                    marc:datafield[@tag='245'][not(marc:subfield[@code='6'])][child::*[@code='h']] or
+                    marc:datafield[@tag='246'][not(marc:subfield[@code='6'])][child::*[@code='h']] or
+                    marc:datafield[@tag='730'][not(marc:subfield[@code='6'])][child::*[@code='h']] or
+                    marc:datafield[@tag='256'][not(marc:subfield[@code='6'])][child::*[@code='a']] or
+                    marc:datafield[@tag='337'][not(marc:subfield[@code='6'])][child::*[@code='a']] or
+                    marc:datafield[@tag='338'][not(marc:subfield[@code='6'])][child::*[@code='a']] or
+                    marc:datafield[@tag='300'][not(marc:subfield[@code='6'])] or
+                    marc:datafield[@tag='856'][not(marc:subfield[@code='6'])][child::*[@code='q']]">
+                    <physicalDescription>
+                        <!--  880 field -->
+                        <xsl:call-template name="digitalOrigin">
+                            <xsl:with-param name="typeOf008" select="$typeOf008"/>
+                        </xsl:call-template>
+                        <xsl:call-template name="form">
+                            <xsl:with-param name="controlField008" select="$controlField008"/>
+                            <xsl:with-param name="typeOf008" select="$typeOf008"/>
+                            <xsl:with-param name="leader6" select="$leader6"/>
+                        </xsl:call-template>
+                        <xsl:call-template name="reformattingQuality"/>
+                        <xsl:apply-templates select="marc:datafield[@tag='130'][not(marc:subfield[@code='6'])][child::*[@code='h']] |
+                            marc:datafield[@tag='240'][not(marc:subfield[@code='6'])][child::*[@code='h']] |
+                            marc:datafield[@tag='242'][not(marc:subfield[@code='6'])][child::*[@code='h']] |
+                            marc:datafield[@tag='245'][not(marc:subfield[@code='6'])][child::*[@code='h']] |
+                            marc:datafield[@tag='246'][not(marc:subfield[@code='6'])][child::*[@code='h']] |
+                            marc:datafield[@tag='730'][not(marc:subfield[@code='6'])][child::*[@code='h']] |
+                            marc:datafield[@tag='256'][not(marc:subfield[@code='6'])][child::*[@code='a']] |
+                            marc:datafield[@tag='337'][not(marc:subfield[@code='6'])][child::*[@code='a']] |
+                            marc:datafield[@tag='338'][not(marc:subfield[@code='6'])][child::*[@code='a']] |
+                            marc:datafield[@tag='300'][not(marc:subfield[@code='6'])] |
+                            marc:datafield[@tag='856'][not(marc:subfield[@code='6'])][child::*[@code='q']]" mode="physDesc"/>
+                    </physicalDescription>
+                </xsl:if>
+            </xsl:when>
+            <xsl:when test="string-length(normalize-space($physicalDescription))">
+                <physicalDescription>
+                    <!--  880 field -->
+                    <xsl:call-template name="z3xx880"/>
+                    <xsl:copy-of select="$physicalDescription"/>
+                </physicalDescription>
+            </xsl:when>
+        </xsl:choose>
+        <!-- 130, 240, 242, 245, 246, 730 $h, 256, 337, 338, 300, 856 -->
+        <xsl:for-each select="marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'130')]/child::*[@code='h'] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'240')]/child::*[@code='h'] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'242')]/child::*[@code='h'] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'245')]/child::*[@code='h'] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'246')]/child::*[@code='h'] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'730')]/child::*[@code='h'] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'256')]/child::*[@code='a'] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'337')]/child::*[@code='a'] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'338')]/child::*[@code='a'] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'300')] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'856')]/child::*[code='q']">
+            <physicalDescription>
+                <xsl:choose>
+                    <xsl:when test="self::marc:subfield"><xsl:call-template name="xxs880"/></xsl:when>
+                    <xsl:when test="self::marc:datafield"><xsl:call-template name="xxx880"/></xsl:when>
+                </xsl:choose>
+                <xsl:apply-templates select="." mode="physDesc"/>
+            </physicalDescription>
+        </xsl:for-each>
+
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=520] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'520')]">
+            <xsl:call-template name="createAbstractFrom520"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=505] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'505')]">
+            <xsl:call-template name="createTOCFrom505"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=521] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'521')]">
+            <xsl:call-template name="createTargetAudienceFrom521"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=506] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'506')]">
+            <xsl:call-template name="createAccessConditionFrom506"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=540] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'540')]">
+            <xsl:call-template name="createAccessConditionFrom540"/>
+        </xsl:for-each>
+
+        <xsl:if test="$typeOf008='BK' or $typeOf008='CF' or $typeOf008='MU' or $typeOf008='VM'">
+            <xsl:variable name="controlField008-22" select="substring($controlField008,23,1)"/>
+            <xsl:choose>
+                <!-- 01/04 fix -->
+                <xsl:when test="$controlField008-22='d'">
+                    <targetAudience authority="marctarget">adolescent</targetAudience>
+                </xsl:when>
+                <xsl:when test="$controlField008-22='e'">
+                    <targetAudience authority="marctarget">adult</targetAudience>
+                </xsl:when>
+                <xsl:when test="$controlField008-22='g'">
+                    <targetAudience authority="marctarget">general</targetAudience>
+                </xsl:when>
+                <xsl:when test="$controlField008-22='b' or $controlField008-22='c' or $controlField008-22='j'">
+                    <targetAudience authority="marctarget">juvenile</targetAudience>
+                </xsl:when>
+                <xsl:when test="$controlField008-22='a'">
+                    <targetAudience authority="marctarget">preschool</targetAudience>
+                </xsl:when>
+                <xsl:when test="$controlField008-22='f'">
+                    <targetAudience authority="marctarget">specialized</targetAudience>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+
+        <!-- 1.32 tmee Drop note mapping for 510 and map only to <relatedItem>
+        <xsl:for-each select="marc:datafield[@tag=510]">
+            <note type="citation/reference">
+                <xsl:call-template name="uri"/>
+                <xsl:variable name="str">
+                    <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
+                        <xsl:value-of select="."/>
+                        <xsl:text> </xsl:text>
+                    </xsl:for-each>
+                </xsl:variable>
+                <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+            </note>
+        </xsl:for-each>
+        -->
+
+        <!-- 245c 362az 502-585 5XX-->
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=245] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'245')]">
+            <xsl:call-template name="createNoteFrom245c"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=362] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'362')]">
+            <xsl:call-template name="createNoteFrom362"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=500] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'500')]">
+            <xsl:call-template name="createNoteFrom500"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=502] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'502')]">
+            <xsl:call-template name="createNoteFrom502"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=504] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'504')]">
+            <xsl:call-template name="createNoteFrom504"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=508] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'508')]">
+            <xsl:call-template name="createNoteFrom508"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=511] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'511')]">
+            <xsl:call-template name="createNoteFrom511"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=515] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'515')]">
+            <xsl:call-template name="createNoteFrom515"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=518] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'518')]">
+            <xsl:call-template name="createNoteFrom518"/>
+
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=524] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'524')]">
+            <xsl:call-template name="createNoteFrom524"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=530] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'530')]">
+            <xsl:call-template name="createNoteFrom530"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=533] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'533')]">
+            <xsl:call-template name="createNoteFrom533"/>
+        </xsl:for-each>
+        <!--
+        <xsl:for-each select="marc:datafield[@tag=534]">
+            <xsl:call-template name="createNoteFrom534"/>
+        </xsl:for-each>
+-->
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=535] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'535')]">
+            <xsl:call-template name="createNoteFrom535"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=536] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'536')]">
+            <xsl:call-template name="createNoteFrom536"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=538] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'538')]">
+            <xsl:call-template name="createNoteFrom538"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=541] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'541')]">
+            <xsl:call-template name="createNoteFrom541"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=545] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'545')]">
+            <xsl:call-template name="createNoteFrom545"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=546] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'546')]">
+            <xsl:call-template name="createNoteFrom546"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=561] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'561')]">
+            <xsl:call-template name="createNoteFrom561"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=562] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'562')]">
+            <xsl:call-template name="createNoteFrom562"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=581] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'581')]">
+            <xsl:call-template name="createNoteFrom581"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=583] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'583')]">
+            <xsl:call-template name="createNoteFrom583"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=585] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'585')]">
+            <xsl:call-template name="createNoteFrom585"/>
+        </xsl:for-each>
+        <!-- 1.121, 1.135 -->
+        <xsl:for-each select="marc:datafield[@tag=501 or @tag=507 or @tag=513 or @tag=514 or @tag=516
+            or @tag=522 or @tag=525 or @tag=526 or @tag=544 or @tag=547
+            or @tag=550 or @tag=552 or @tag=555 or @tag=556
+            or @tag=565 or @tag=567 or @tag=580 or @tag=584 or @tag=586 or @tag=588]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'501')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'507')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'513')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'514')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'516')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'522')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'525')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'526')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'544')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'547')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'550')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'552')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'555')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'556')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'565')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'567')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'580')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'585')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'584')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'586')]">
+            <xsl:call-template name="createNoteFrom5XX"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=034] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'034')]">
+            <xsl:call-template name="createSubGeoFrom034"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=043] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'043')]">
+            <xsl:call-template name="createSubGeoFrom043"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=045] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'045')]">
+            <xsl:call-template name="createSubTemFrom045"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=255] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'255')]">
+            <xsl:call-template name="createSubGeoFrom255"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=600] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'600')]">
+            <xsl:call-template name="createSubNameFrom600"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=610] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'610')]">
+            <xsl:call-template name="createSubNameFrom610"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=611] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'611')]">
+            <xsl:call-template name="createSubNameFrom611"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=630] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'630')]">
+            <xsl:call-template name="createSubTitleFrom630"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=648] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'648')]">
+            <xsl:call-template name="createSubChronFrom648"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=650] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'650')]">
+            <xsl:call-template name="createSubTopFrom650"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=651] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'651')]">
+            <xsl:call-template name="createSubGeoFrom651"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=653] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'653')]">
+            <xsl:call-template name="createSubFrom653"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=656] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'656')]">
+            <xsl:call-template name="createSubFrom656"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=662] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'662')]">
+            <xsl:call-template name="createSubGeoFrom662752"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=752] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'752')]">
+            <xsl:call-template name="createSubGeoFrom662752"/>
+        </xsl:for-each>
+
+        <!-- createClassificationFrom 0XX-->
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='050'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'050')]">
+            <xsl:call-template name="createClassificationFrom050"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='060'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'060')]">
+            <xsl:call-template name="createClassificationFrom060"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='080'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'080')]">
+            <xsl:call-template name="createClassificationFrom080"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='082'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'082')]">
+            <xsl:call-template name="createClassificationFrom082"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='084'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'084')]">
+            <xsl:call-template name="createClassificationFrom084"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='086'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'086')]">
+            <xsl:call-template name="createClassificationFrom086"/>
+        </xsl:for-each>
+
+        <!--    location    -->
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=852] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'852')]">
+            <xsl:call-template name="createLocationFrom852"/>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=856] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'856')]">
+            <xsl:call-template name="createLocationFrom856"/>
+        </xsl:for-each>
+
+        <!-- 1.120 - @490$ind1 -->
+        <xsl:for-each select="marc:datafield[@tag=490][@ind1='0' or @ind1=' '] | marc:datafield[@tag='880'][@ind1='0' or @ind1=' '][starts-with(marc:subfield[@code='6'],'490')]">
+            <xsl:call-template name="createRelatedItemFrom490"/>
+        </xsl:for-each>
+
+        <!-- 1.120 - @440$ind1 --><!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=440][@ind1='0' or @ind1=' '] | marc:datafield[@tag='880'][@ind1='0' or @ind1=' '][starts-with(marc:subfield[@code='6'],'440')]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=440 or (@tag='880' and not(../marc:datafield[@tag='440'][@ind1='0' or @ind1=' '][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem type="series">
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][@ind1='0' or @ind1=' '][starts-with(marc:subfield[@code='6'],'440')][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <titleInfo>
+                        <xsl:call-template name="xxx880"/>
+                        <!-- 1.120 - @440$a$v -->
+                        <title>
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="subfieldSelect">
+                                        <xsl:with-param name="codes">a</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </title>
+                        <xsl:if test="marc:subfield[@code='v']">
+                            <partNumber>
+                                <xsl:call-template name="chopPunctuation">
+                                    <xsl:with-param name="chopString">
+                                        <xsl:call-template name="subfieldSelect">
+                                            <xsl:with-param name="codes">v</xsl:with-param>
+                                        </xsl:call-template>
+                                    </xsl:with-param>
+                                </xsl:call-template>
+                            </partNumber>
+                        </xsl:if>
+                    </titleInfo>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+
+        <!-- tmee 1.40 1.74 1.88 fixed 510c mapping 20130829-->
+        <!-- 1.120 - @510$ind1 --><!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=510][@ind1='0' or @ind1=' '] | marc:datafield[@tag='880'][@ind1='0' or @ind1=' '][starts-with(marc:subfield[@code='6'],'510')]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=510 or (@tag='880' and not(../marc:datafield[@tag='510'][@ind1='0' or @ind1=' '][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem type="isReferencedBy">
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][@ind1='0' or @ind1=' '][starts-with(marc:subfield[@code='6'],'510')][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                <xsl:for-each select="marc:subfield[@code='a']">
+                    <titleInfo>
+                        <xsl:call-template name="xxs880"/>
+                        <title>
+                            <xsl:value-of select="."/>
+                        </title>
+                    </titleInfo>
+                </xsl:for-each>
+                <xsl:for-each select="marc:subfield[@code='b']">
+                    <originInfo>
+                        <xsl:call-template name="xxs880"/>
+                        <dateOther type="coverage">
+                            <xsl:value-of select="."/>
+                        </dateOther>
+                    </originInfo>
+                </xsl:for-each>
+                <part>
+                    <xsl:call-template name="xxx880"/>
+                    <detail type="part">
+                        <number>
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString">
+                            <xsl:call-template name="subfieldSelect">
+                                <xsl:with-param name="codes">c</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                        </number>
+                    </detail>
+                    </part>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+
+        <!-- 1.120 - @534$ind1 --><!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=534][@ind1='0' or @ind1=' '] | marc:datafield[@tag='880'][@ind1='0' or @ind1=' '][starts-with(marc:subfield[@code='6'],'534')]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=534 or (@tag='880' and not(../marc:datafield[@tag='534'][@ind1='0' or @ind1=' '][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem type="original">
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][@ind1='0' or @ind1=' '][starts-with(marc:subfield[@code='6'],'534')][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <xsl:call-template name="relatedTitle"/>
+                    <xsl:call-template name="relatedName"/>
+                    <xsl:if test="marc:subfield[@code='b' or @code='c']">
+                        <originInfo>
+                            <xsl:call-template name="xxx880"/>
+                            <xsl:for-each select="marc:subfield[@code='c']">
+                                <publisher>
+                                    <xsl:value-of select="."/>
+                                </publisher>
+                            </xsl:for-each>
+                            <xsl:for-each select="marc:subfield[@code='b']">
+                                <edition>
+                                    <xsl:value-of select="."/>
+                                </edition>
+                            </xsl:for-each>
+                        </originInfo>
+                    </xsl:if>
+                    <!-- related item id -->
+                    <xsl:apply-templates select="marc:subfield[@code='x']" mode="relatedItem"/>
+                    <xsl:apply-templates select="marc:subfield[@code='z']" mode="relatedItem"/>
+                    <xsl:call-template name="relatedNote"/>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=700][marc:subfield[@code='t']] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'700')][marc:subfield[@code='t']]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=700 or (@tag='880' and not(../marc:datafield[@tag='700'][marc:subfield[@code='t']][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem>
+                <!-- 1.115 -->
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="constituentOrRelatedType"/>
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'700')][marc:subfield[@code='t']][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <titleInfo>
+                        <xsl:call-template name="xxx880"/>
+                        <title>
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="specialSubfieldSelect">
+                                        <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
+                                        <xsl:with-param name="axis">t</xsl:with-param>
+                                        <xsl:with-param name="afterCodes">g</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </title>
+                        <xsl:call-template name="part"/>
+                    </titleInfo>
+                    <name type="personal">
+                        <xsl:call-template name="xxx880"/>
+                        <namePart>
+                            <xsl:call-template name="specialSubfieldSelect">
+                                <xsl:with-param name="anyCodes">aq</xsl:with-param>
+                                <xsl:with-param name="axis">t</xsl:with-param>
+                                <xsl:with-param name="beforeCodes">g</xsl:with-param>
+                            </xsl:call-template>
+                        </namePart>
+                        <xsl:call-template name="termsOfAddress"/>
+                        <xsl:call-template name="nameDate"/>
+                        <xsl:call-template name="role"/>
+                    </name>
+                    <xsl:call-template name="relatedForm"/>
+                    <!-- issn -->
+                    <xsl:apply-templates select="marc:subfield[@code='x']" mode="relatedItem"/>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=710][marc:subfield[@code='t']] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'710')][marc:subfield[@code='t']]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=710 or (@tag='880' and not(../marc:datafield[@tag='710'][marc:subfield[@code='t']][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem>
+                <!-- 1.115 -->
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="constituentOrRelatedType"/>
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'710')][marc:subfield[@code='t']][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <titleInfo>
+                        <xsl:call-template name="xxx880"/>
+                        <title>
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="specialSubfieldSelect">
+                                        <!-- 1.120 @711$v -->
+                                        <xsl:with-param name="anyCodes">tfklmors</xsl:with-param>
+                                        <xsl:with-param name="axis">t</xsl:with-param>
+                                        <xsl:with-param name="afterCodes">dg</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </title>
+                        <!-- 1.125 -->
+                        <xsl:variable name="partNumber">
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="specialSubfieldSelect">
+                                        <xsl:with-param name="anyCodes">n</xsl:with-param>
+                                        <xsl:with-param name="axis">t</xsl:with-param>
+                                        <xsl:with-param name="afterCodes">n</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:variable>
+                        <xsl:if test="$partNumber != ''">
+                            <partNumber><xsl:value-of select="$partNumber"/></partNumber>
+                        </xsl:if>
+                        <xsl:apply-templates select="marc:subfield[@code='p']" mode="relatedItem"/>
+                    </titleInfo>
+                    <name type="corporate">
+                        <xsl:call-template name="xxx880"/>
+                        <xsl:for-each select="marc:subfield[@code='a']">
+                            <namePart>
+                                <xsl:value-of select="."/>
+                            </namePart>
+                        </xsl:for-each>
+                        <xsl:for-each select="marc:subfield[@code='b']">
+                            <namePart>
+                                <xsl:value-of select="."/>
+                            </namePart>
+                        </xsl:for-each>
+                        <xsl:variable name="tempNamePart">
+                            <xsl:call-template name="specialSubfieldSelect">
+                                <xsl:with-param name="anyCodes">c</xsl:with-param>
+                                <xsl:with-param name="axis">t</xsl:with-param>
+                                <xsl:with-param name="beforeCodes">dgn</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:variable>
+                        <xsl:if test="normalize-space($tempNamePart)">
+                            <namePart>
+                                <xsl:value-of select="$tempNamePart"/>
+                            </namePart>
+                        </xsl:if>
+                        <xsl:call-template name="role"/>
+                    </name>
+                    <xsl:call-template name="relatedForm"/>
+                    <!-- issn -->
+                    <xsl:apply-templates select="marc:subfield[@code='x']" mode="relatedItem"/>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=711][marc:subfield[@code='t']] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'711')][marc:subfield[@code='t']]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=711 or (@tag='880' and not(../marc:datafield[@tag='711'][marc:subfield[@code='t']][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem>
+                <!-- 1.115 -->
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="constituentOrRelatedType"/>
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'711')][marc:subfield[@code='t']][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <titleInfo>
+                        <xsl:call-template name="xxx880"/>
+                        <title>
+                            <!-- 1.120 - @711$v -->
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="specialSubfieldSelect">
+                                        <xsl:with-param name="anyCodes">tfkls</xsl:with-param>
+                                        <xsl:with-param name="axis">t</xsl:with-param>
+                                        <xsl:with-param name="afterCodes">g</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </title>
+                        <!-- 1.125 -->
+                        <xsl:variable name="partNumber">
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="specialSubfieldSelect">
+                                        <xsl:with-param name="anyCodes">n</xsl:with-param>
+                                        <xsl:with-param name="axis">t</xsl:with-param>
+                                        <xsl:with-param name="afterCodes">n</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:variable>
+                        <xsl:if test="$partNumber != ''">
+                            <partNumber><xsl:value-of select="$partNumber"/></partNumber>
+                        </xsl:if>
+                        <xsl:apply-templates select="marc:subfield[@code='p']" mode="relatedItem"/>
+                    </titleInfo>
+                    <name type="conference">
+                        <xsl:call-template name="xxx880"/>
+                        <namePart>
+                            <xsl:call-template name="specialSubfieldSelect">
+                                <xsl:with-param name="anyCodes">aqdc</xsl:with-param>
+                                <xsl:with-param name="axis">t</xsl:with-param>
+                                <xsl:with-param name="beforeCodes">gn</xsl:with-param>
+                            </xsl:call-template>
+                        </namePart>
+                        <!-- 1.120 - @711$4 -->
+                        <xsl:call-template name="role"/>
+                    </name>
+                    <xsl:call-template name="relatedForm"/>
+                    <!-- issn -->
+                    <xsl:apply-templates select="marc:subfield[@code='x']" mode="relatedItem"/>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=730][@ind2=2] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'730')][@ind2='2']">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=730 or (@tag='880' and not(../marc:datafield[@tag='730'][@ind2=2][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+                <relatedItem>
+                    <!-- 1.115 -->
+                    <xsl:if test="marc:subfield[@code='i']">
+                        <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                    </xsl:if>
+                    <xsl:call-template name="constituentOrRelatedType"/>
+                    <xsl:for-each
+                        select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'730')][@ind2='2'][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                        <titleInfo>
+                            <xsl:call-template name="xxx880"/>
+                            <title>
+                                <xsl:call-template name="chopPunctuation">
+                                    <xsl:with-param name="chopString">
+                                        <!-- 1.120 @711$v -->
+                                        <xsl:call-template name="subfieldSelect">
+                                            <xsl:with-param name="codes">adfgklmors</xsl:with-param>
+                                        </xsl:call-template>
+                                    </xsl:with-param>
+                                </xsl:call-template>
+                            </title>
+                            <xsl:call-template name="part"/>
+                        </titleInfo>
+                        <xsl:call-template name="relatedForm"/>
+                        <!-- issn -->
+                        <xsl:apply-templates select="marc:subfield[@code='x']" mode="relatedItem"/>
+                    </xsl:for-each>
+                </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=740][@ind2=2] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'740')][@ind2='2']">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=740 or (@tag='880' and not(../marc:datafield[@tag='740'][@ind2=2][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem>
+                <!-- 1.115 -->
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="constituentOrRelatedType"/>
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'740')][@ind2='2'][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <titleInfo>
+                        <xsl:call-template name="xxx880"/>
+                        <title>
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:value-of select="marc:subfield[@code='a']"/>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </title>
+                        <xsl:call-template name="part"/>
+                    </titleInfo>
+                    <xsl:call-template name="relatedForm"/>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+
+        <!-- 1.120 - @777 @787 and 1.121 -->
+        <xsl:for-each
+            select="marc:datafield[@tag='760'] | marc:datafield[@tag='762'] | marc:datafield[@tag='765'] |
+            marc:datafield[@tag='767'] | marc:datafield[@tag='770'] | marc:datafield[@tag='774'] |
+            marc:datafield[@tag='775'] | marc:datafield[@tag='772'] | marc:datafield[@tag='773'] |
+            marc:datafield[@tag='776'] | marc:datafield[@tag='777'] | marc:datafield[@tag='787'] |
+            marc:datafield[@tag='780'] | marc:datafield[@tag='785'] | marc:datafield[@tag='786'] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'760')] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'762')] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'765')] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'767')] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'770')] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'774')] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'775')] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'772')] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'773')] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'776')] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'777')] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'787')] |
+            marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'780')] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'785')] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'786')]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:variable name="tag" select="@tag"/>
+            <xsl:if test="(@tag = 760 or @tag = 762 or @tag = 765 or @tag = 767 or @tag = 770 or @tag = 774 or
+                @tag = 775 or @tag = 772 or @tag = 773 or @tag = 776 or @tag = 777 or @tag = 787 or
+                @tag = 780 or @tag = 785 or @tag = 786) or
+                (@tag='880' and not(../marc:datafield[@tag = 760 or @tag = 762 or @tag = 765 or
+                @tag = 767 or @tag = 770 or @tag = 774 or @tag = 775 or @tag = 772 or @tag = 773 or
+                @tag = 776 or @tag = 777 or @tag = 787 or @tag = 780 or @tag = 785 or @tag = 786][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem>
+                <!-- selects type attribute -->
+                <xsl:choose>
+                    <!-- 1.120 - @762@type -->
+                    <xsl:when test="@tag='760' or @tag='762'">
+                        <xsl:attribute name="type">series</xsl:attribute>
+                    </xsl:when>
+                    <xsl:when test="@tag='770' or @tag='774'">
+                        <xsl:attribute name="type">constituent</xsl:attribute>
+                    </xsl:when>
+                    <!-- 1.120 - @775@type -->
+                    <xsl:when test="@tag='765' or @tag='767' or (@tag='775' and @ind2=' ')">
+                        <xsl:attribute name="type">otherVersion</xsl:attribute>
+                    </xsl:when>
+                    <xsl:when test="@tag='772' or @tag='773'">
+                        <xsl:attribute name="type">host</xsl:attribute>
+                    </xsl:when>
+                    <xsl:when test="@tag='776'">
+                        <xsl:attribute name="type">otherFormat</xsl:attribute>
+                    </xsl:when>
+                    <xsl:when test="@tag='780'">
+                        <xsl:attribute name="type">preceding</xsl:attribute>
+                    </xsl:when>
+                    <xsl:when test="@tag='785'">
+                        <xsl:attribute name="type">succeeding</xsl:attribute>
+                    </xsl:when>
+                    <xsl:when test="@tag='786'">
+                        <xsl:attribute name="type">original</xsl:attribute>
+                    </xsl:when>
+                </xsl:choose>
+                <!-- selects displayLabel attribute -->
+                <xsl:choose>
+                    <xsl:when test="marc:subfield[@code='i']">
+                        <xsl:attribute name="otherType">
+                            <xsl:value-of select="marc:subfield[@code='i']"/>
+                        </xsl:attribute>
+                        <!-- 1.120 - @76X-78X$i -->
+                        <xsl:attribute name="displayLabel">
+                            <xsl:value-of select="marc:subfield[@code='i']"/>
+                        </xsl:attribute>
+                    </xsl:when>
+                    <xsl:when test="marc:subfield[@code='3']">
+                        <xsl:attribute name="displayLabel">
+                            <xsl:value-of select="marc:subfield[@code='3']"/>
+                        </xsl:attribute>
+                    </xsl:when>
+                </xsl:choose>
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],$tag)][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <!-- title -->
+                    <xsl:for-each select="marc:subfield[@code='t']">
+                        <titleInfo>
+                            <xsl:call-template name="xxs880"/>
+                            <title>
+                                <xsl:call-template name="chopPunctuation">
+                                    <xsl:with-param name="chopString">
+                                        <xsl:value-of select="."/>
+                                    </xsl:with-param>
+                                </xsl:call-template>
+                            </title>
+                            <xsl:if test="parent::*[@tag!=773] and ../marc:subfield[@code='g']">
+                                <xsl:apply-templates select="../marc:subfield[@code='g']" mode="relatedItem"/>
+                            </xsl:if>
+                        </titleInfo>
+                    </xsl:for-each>
+                    <xsl:for-each select="marc:subfield[@code='p']">
+                        <titleInfo type="abbreviated">
+                            <xsl:call-template name="xxs880"/>
+                            <title>
+                                <xsl:call-template name="chopPunctuation">
+                                    <xsl:with-param name="chopString">
+                                        <xsl:value-of select="."/>
+                                    </xsl:with-param>
+                                </xsl:call-template>
+                            </title>
+                            <xsl:if test="parent::*[@tag!=773] and ../marc:subfield[@code='g']">
+                                <xsl:apply-templates select="../marc:subfield[@code='g']" mode="relatedItem"/>
+                            </xsl:if>
+                        </titleInfo>
+                    </xsl:for-each>
+                    <xsl:for-each select="marc:subfield[@code='s']">
+                        <titleInfo type="uniform">
+                            <!-- 1.121 -->
+                            <xsl:call-template name="xxs880"/>
+                            <title>
+                                <xsl:call-template name="chopPunctuation">
+                                    <xsl:with-param name="chopString">
+                                        <xsl:value-of select="."/>
+                                    </xsl:with-param>
+                                </xsl:call-template>
+                            </title>
+                            <!-- 1.120 - @76X-78X$g -->
+                            <xsl:if test="parent::*[@tag!=773] and ../marc:subfield[@code='g']">
+                                <xsl:apply-templates select="../marc:subfield[@code='g']" mode="relatedItem"/>
+                            </xsl:if>
+                        </titleInfo>
+                    </xsl:for-each>
+
+                    <!-- originInfo -->
+                    <xsl:if test="marc:subfield[@code='b' or @code='d'] or marc:subfield[@code='f']">
+                        <originInfo>
+                            <xsl:call-template name="xxx880"/>
+                            <xsl:if test="@tag='775'">
+                                <xsl:for-each select="marc:subfield[@code='f']">
+                                    <place>
+                                        <placeTerm>
+                                            <xsl:attribute name="type">code</xsl:attribute>
+                                            <xsl:attribute name="authority">marcgac</xsl:attribute>
+                                            <xsl:call-template name="chopPunctuation">
+                                                <xsl:with-param name="chopString">
+                                                    <xsl:value-of select="."/>
+                                                </xsl:with-param>
+                                            </xsl:call-template>
+                                        </placeTerm>
+                                    </place>
+                                </xsl:for-each>
+                            </xsl:if>
+                            <xsl:for-each select="marc:subfield[@code='d']">
+                                <publisher>
+                                    <xsl:call-template name="chopPunctuation">
+                                        <xsl:with-param name="chopString">
+                                            <xsl:value-of select="."/>
+                                        </xsl:with-param>
+                                    </xsl:call-template>
+                                </publisher>
+                            </xsl:for-each>
+                            <xsl:for-each select="marc:subfield[@code='b']">
+                                <edition>
+                                    <xsl:apply-templates/>
+                                </edition>
+                            </xsl:for-each>
+                        </originInfo>
+                    </xsl:if>
+                    <!-- language -->
+                    <xsl:if test="@tag='775'">
+                        <xsl:if test="marc:subfield[@code='e']">
+                            <language>
+                                <xsl:call-template name="xxx880"/>
+                                <languageTerm type="code" authority="iso639-2b">
+                                    <xsl:value-of select="marc:subfield[@code='e']"/>
+                                </languageTerm>
+                            </language>
+                        </xsl:if>
+                    </xsl:if>
+                    <!-- physical description -->
+                    <xsl:apply-templates select="marc:subfield[@code='h']" mode="relatedItem"/>
+                    <!-- note -->
+                    <xsl:apply-templates select="marc:subfield[@code='n']" mode="relatedItemNote"/>
+                    <!-- subjects -->
+                    <xsl:apply-templates select="marc:subfield[@code='j']" mode="relatedItem"/>
+                    <!-- identifiers -->
+                    <xsl:apply-templates select="marc:subfield[@code='o']" mode="relatedItem"/>
+                    <xsl:apply-templates select="marc:subfield[@code='x']" mode="relatedItem"/>
+                    <!--  1.120 - @76X-78X$z -->
+                    <xsl:apply-templates select="marc:subfield[@code='z']" mode="relatedItem"/>
+                    <xsl:apply-templates select="marc:subfield[@code='w']" mode="relatedItem"/>
+                    <!-- related part -->
+                    <xsl:if test="@tag='773'">
+                        <xsl:for-each select="marc:subfield[@code='g']">
+                            <part>
+                                <xsl:call-template name="xxs880"/>
+                                <text>
+                                    <xsl:apply-templates/>
+                                </text>
+                            </part>
+                        </xsl:for-each>
+                        <xsl:for-each select="marc:subfield[@code='q']">
+                            <part>
+                                <xsl:call-template name="xxs880"/>
+                                <xsl:call-template name="parsePart"/>
+                            </part>
+                        </xsl:for-each>
+                    </xsl:if>
+                    <!-- Call names -->
+                    <xsl:apply-templates select="marc:subfield[@code='a']" mode="relatedItem"/>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+
+        <!-- @depreciated see 1.121
+        <xsl:for-each select="marc:datafield[@tag=760]">
+            <relatedItem type="series">
+                // 1.115
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="relatedItem76X-78X"/>
+            </relatedItem>
+        </xsl:for-each>
+
+        //AQ1.23 tmee/dlf
+        <xsl:for-each select="marc:datafield[@tag=762]">
+            <relatedItem type="series">
+                // 1.115
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="relatedItem76X-78X"/>
+            </relatedItem>
+        </xsl:for-each>
+
+        // AQ1.5, AQ1.7 deleted tags 777 and 787 from the following select for relatedItem mapping
+        // 1.45 and 1.46 - AQ1.24 and 1.25 tmee
+        <xsl:for-each select="marc:datafield[@tag=765]|marc:datafield[@tag=767]|marc:datafield[@tag=775] | marc:datafield[@tag=777] | marc:datafield[@tag=787]">
+            <relatedItem>
+                <xsl:choose>
+                    <xsl:when test="@tag='765' or @tag='767' or (@tag='775' and @ind2=' ')">
+                        <xsl:attribute name="type">otherVersion</xsl:attribute>
+                    </xsl:when>
+                </xsl:choose>
+                // 1.115
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="relatedItem76X-78X"/>
+            </relatedItem>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=770]|marc:datafield[@tag=774]">
+            <relatedItem type="constituent">
+                // 1.115
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="relatedItem76X-78X"/>
+            </relatedItem>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=772]|marc:datafield[@tag=773]">
+            <relatedItem type="host">
+                // 1.115
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="relatedItem76X-78X"/>
+            </relatedItem>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag=776]">
+            <relatedItem type="otherFormat">
+                // 1.115
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="relatedItem76X-78X"/>
+            </relatedItem>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag=780]">
+            <relatedItem type="preceding">
+                // 1.115
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="relatedItem76X-78X"/>
+            </relatedItem>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag=785]">
+            <relatedItem type="succeeding">
+                // 1.115
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="relatedItem76X-78X"/>
+            </relatedItem>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag=786]">
+            <relatedItem type="original">
+                // 1.115
+                <xsl:if test="marc:subfield[@code='i']">
+                    <xsl:attribute name="otherType"><xsl:value-of select="marc:subfield[@code='i']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="relatedItem76X-78X"/>
+            </relatedItem>
+        </xsl:for-each>
+        -->
+
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=800] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'800')]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=800 or (@tag='880' and not(../marc:datafield[@tag='800'][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem type="series">
+                <!-- 1.122 -->
+                <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'800')][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <titleInfo>
+                        <xsl:call-template name="xxx880"/>
+                        <title>
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="specialSubfieldSelect">
+                                        <xsl:with-param name="anyCodes">tfklmors</xsl:with-param>
+                                        <xsl:with-param name="axis">t</xsl:with-param>
+                                        <xsl:with-param name="afterCodes">g</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </title>
+                        <!-- 1.120 - @800$v -->
+                        <xsl:apply-templates select="marc:subfield[@code='n']" mode="relatedItem"/>
+                        <xsl:apply-templates select="marc:subfield[@code='v']" mode="relatedItem"/>
+                        <xsl:apply-templates select="marc:subfield[@code='p']" mode="relatedItem"/>
+                    </titleInfo>
+                    <name type="personal">
+                        <xsl:call-template name="xxx880"/>
+                        <namePart>
+                            <!-- 1.126 -->
+                                    <xsl:call-template name="specialSubfieldSelect">
+                                        <xsl:with-param name="anyCodes">aq</xsl:with-param>
+                                        <xsl:with-param name="axis">t</xsl:with-param>
+                                        <xsl:with-param name="beforeCodes">g</xsl:with-param>
+                                    </xsl:call-template>
+                        </namePart>
+                        <xsl:call-template name="termsOfAddress"/>
+                        <xsl:call-template name="nameDate"/>
+                        <xsl:call-template name="role"/>
+                    </name>
+                    <xsl:call-template name="relatedForm"/>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=810] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'810')]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=810 or (@tag='880' and not(../marc:datafield[@tag='810'][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem type="series">
+                <!-- 1.122 -->
+                <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'810')][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <titleInfo>
+                        <xsl:call-template name="xxx880"/>
+                        <title>
+                            <!-- 1.120 - @800$v -->
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="specialSubfieldSelect">
+                                        <xsl:with-param name="anyCodes">tfklmors</xsl:with-param>
+                                        <xsl:with-param name="axis">t</xsl:with-param>
+                                        <xsl:with-param name="afterCodes">dg</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </title>
+                        <!-- 1.125 -->
+                        <xsl:variable name="partNumber">
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="specialSubfieldSelect">
+                                        <xsl:with-param name="anyCodes">n</xsl:with-param>
+                                        <xsl:with-param name="axis">t</xsl:with-param>
+                                        <xsl:with-param name="afterCodes">n</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:variable>
+                        <xsl:if test="$partNumber != ''">
+                            <partNumber><xsl:value-of select="$partNumber"/></partNumber>
+                        </xsl:if>
+                        <!-- 1.120 - @800$v -->
+                        <xsl:apply-templates select="marc:subfield[@code='v']" mode="relatedItem"/>
+                        <xsl:apply-templates select="marc:subfield[@code='p']" mode="relatedItem"/>
+                    </titleInfo>
+                    <name type="corporate">
+                        <xsl:call-template name="xxx880"/>
+                        <xsl:for-each select="marc:subfield[@code='a']">
+                            <namePart>
+                                <xsl:value-of select="."/>
+                            </namePart>
+                        </xsl:for-each>
+                        <xsl:for-each select="marc:subfield[@code='b']">
+                            <namePart>
+                                <xsl:value-of select="."/>
+                            </namePart>
+                        </xsl:for-each>
+                        <namePart>
+                            <xsl:call-template name="specialSubfieldSelect">
+                                <xsl:with-param name="anyCodes">c</xsl:with-param>
+                                <xsl:with-param name="axis">t</xsl:with-param>
+                                <xsl:with-param name="beforeCodes">dgn</xsl:with-param>
+                            </xsl:call-template>
+                        </namePart>
+                        <xsl:call-template name="role"/>
+                    </name>
+                    <xsl:call-template name="relatedForm"/>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=811] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'811')]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=811 or (@tag='880' and not(../marc:datafield[@tag='811'][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem type="series">
+                <!-- 1.122 -->
+                <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'811')][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <titleInfo>
+                        <xsl:call-template name="xxx880"/>
+                        <title>
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="specialSubfieldSelect">
+                                        <xsl:with-param name="anyCodes">tfkls</xsl:with-param>
+                                        <xsl:with-param name="axis">t</xsl:with-param>
+                                        <xsl:with-param name="afterCodes">g</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </title>
+                        <!-- 1.125 -->
+                        <xsl:variable name="partNumber">
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="specialSubfieldSelect">
+                                        <xsl:with-param name="anyCodes">n</xsl:with-param>
+                                        <xsl:with-param name="axis">t</xsl:with-param>
+                                        <xsl:with-param name="afterCodes">n</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:variable>
+                        <xsl:if test="$partNumber != ''">
+                            <partNumber><xsl:value-of select="$partNumber"/></partNumber>
+                        </xsl:if>
+                        <!-- 1.120 - @800$v -->
+                        <xsl:apply-templates select="marc:subfield[@code='v']" mode="relatedItem"/>
+                        <xsl:apply-templates select="marc:subfield[@code='p']" mode="relatedItem"/>
+                    </titleInfo>
+                    <name type="conference">
+                        <xsl:call-template name="xxx880"/>
+                        <namePart>
+                            <xsl:call-template name="specialSubfieldSelect">
+                                <xsl:with-param name="anyCodes">aqdc</xsl:with-param>
+                                <xsl:with-param name="axis">t</xsl:with-param>
+                                <xsl:with-param name="beforeCodes">gn</xsl:with-param>
+                            </xsl:call-template>
+                        </namePart>
+                        <xsl:call-template name="role"/>
+                    </name>
+                    <xsl:call-template name="relatedForm"/>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='830'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'830')]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=830 or (@tag='880' and not(../marc:datafield[@tag='830'][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem type="series">
+                <!-- 1.122 -->
+                <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'830')][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <titleInfo>
+                        <xsl:call-template name="xxx880"/>
+                        <title>
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="subfieldSelect">
+                                        <xsl:with-param name="codes">adfgklmors</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </title>
+                        <!-- 1.120 - @830$v -->
+                        <xsl:if test="marc:subfield[@code='v']">
+                            <partNumber>
+                                <xsl:call-template name="chopPunctuation">
+                                    <xsl:with-param name="chopString">
+                                        <xsl:call-template name="subfieldSelect">
+                                            <xsl:with-param name="codes">v</xsl:with-param>
+                                        </xsl:call-template>
+                                    </xsl:with-param>
+                                </xsl:call-template>
+                            </partNumber>
+                        </xsl:if>
+                    </titleInfo>
+                    <xsl:call-template name="relatedForm"/>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag='856'][@ind2='2']/marc:subfield[@code='q'] | marc:datafield[@tag='880'][@ind2='2'][marc:subfield[@code='q']][starts-with(marc:subfield[@code='6'],'856')]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=856 or (@tag='880' and not(../marc:datafield[@tag='856'][@ind2='2'][marc:subfield[@code='q']][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem>
+                <xsl:for-each
+                    select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'856')][@ind2='2'][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                    <!-- 1.120 - @856@ind2=2$q -->
+                    <xsl:if test="marc:subfield[@code='q']">
+                        <physicalDescription>
+                            <xsl:call-template name="xxx880"/>
+                            <internetMediaType>
+                                <xsl:value-of select="marc:subfield[@code='q']"/>
+                            </internetMediaType>
+                        </physicalDescription>
+                    </xsl:if>
+                    <xsl:if test="marc:subfield[@code='u']">
+                        <location>
+                            <xsl:call-template name="xxx880"/>
+                            <url>
+                                <xsl:if test="marc:subfield[@code='y' or @code='3']">
+                                    <xsl:attribute name="displayLabel">
+                                        <xsl:call-template name="subfieldSelect">
+                                            <xsl:with-param name="codes">y3</xsl:with-param>
+                                        </xsl:call-template>
+                                    </xsl:attribute>
+                                </xsl:if>
+                                <xsl:if test="marc:subfield[@code='z']">
+                                    <xsl:attribute name="note">
+                                        <xsl:call-template name="subfieldSelect">
+                                            <xsl:with-param name="codes">z</xsl:with-param>
+                                        </xsl:call-template>
+                                    </xsl:attribute>
+                                </xsl:if>
+                                <xsl:value-of select="marc:subfield[@code='u']"/>
+                            </url>
+                        </location>
+                    </xsl:if>
+                </xsl:for-each>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+
+
+        <!-- @depreciated see 1.121
+        <xsl:for-each select="marc:datafield[@tag='880']">
+            <xsl:apply-templates select="self::*" mode="trans880"/>
+        </xsl:for-each>
+        -->
+
+
+        <!-- 856, 020, 024, 022, 028, 010, 035, 037 -->
+
+        <xsl:for-each select="marc:datafield[@tag='020']">
+            <xsl:if test="marc:subfield[@code='a']">
+                <identifier type="isbn">
+                    <xsl:value-of select="marc:subfield[@code='a']"/>
+                </identifier>
+            </xsl:if>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag='020']">
+            <xsl:if test="marc:subfield[@code='z']">
+                <identifier type="isbn" invalid="yes">
+                    <xsl:value-of select="marc:subfield[@code='z']"/>
+                </identifier>
+            </xsl:if>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag='024'][@ind1='0']">
+            <xsl:if test="marc:subfield[@code='a']">
+                <identifier type="isrc">
+                    <xsl:value-of select="marc:subfield[@code='a']"/>
+                </identifier>
+            </xsl:if>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag='024'][@ind1='2']">
+            <xsl:if test="marc:subfield[@code='a']">
+                <identifier type="ismn">
+                    <xsl:value-of select="marc:subfield[@code='a']"/>
+                </identifier>
+            </xsl:if>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag='024'][@ind1='4']">
+            <identifier type="sici">
+                <xsl:call-template name="subfieldSelect">
+                    <xsl:with-param name="codes">ab</xsl:with-param>
+                </xsl:call-template>
+            </identifier>
+        </xsl:for-each>
+
+        <!-- 1.107 WS -->
+        <xsl:for-each select="marc:datafield[@tag='024'][@ind1='7']">
+            <identifier>
+                <xsl:if test="marc:subfield[@code='2']">
+                    <xsl:attribute name="type">
+                        <xsl:value-of select="marc:subfield[@code='2']"/>
+                    </xsl:attribute>
+                </xsl:if>
+                <xsl:value-of select="marc:subfield[@code='a']"/>
+            </identifier>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag='024'][@ind1='8']">
+            <identifier>
+                <xsl:value-of select="marc:subfield[@code='a']"/>
+            </identifier>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag='022'][marc:subfield[@code='a']]">
+            <xsl:if test="marc:subfield[@code='a']">
+                <identifier type="issn">
+                    <xsl:value-of select="marc:subfield[@code='a']"/>
+                </identifier>
+            </xsl:if>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag='022'][marc:subfield[@code='z']]">
+            <xsl:if test="marc:subfield[@code='z']">
+                <identifier type="issn" invalid="yes">
+                    <xsl:value-of select="marc:subfield[@code='z']"/>
+                </identifier>
+            </xsl:if>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag='022'][marc:subfield[@code='y']]">
+            <xsl:if test="marc:subfield[@code='y']">
+                <identifier type="issn" invalid="yes">
+                    <xsl:value-of select="marc:subfield[@code='y']"/>
+                </identifier>
+            </xsl:if>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag='022'][marc:subfield[@code='l']]">
+            <xsl:if test="marc:subfield[@code='l']">
+                <identifier type="issn-l">
+                    <xsl:value-of select="marc:subfield[@code='l']"/>
+                </identifier>
+            </xsl:if>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag='022'][marc:subfield[@code='m']]">
+            <xsl:if test="marc:subfield[@code='m']">
+                <identifier type="issn-l" invalid="yes">
+                    <xsl:value-of select="marc:subfield[@code='m']"/>
+                </identifier>
+            </xsl:if>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag='010'][marc:subfield[@code='a']]">
+            <identifier type="lccn">
+                <xsl:value-of select="normalize-space(marc:subfield[@code='a'])"/>
+            </identifier>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag='010'][marc:subfield[@code='z']]">
+            <identifier type="lccn" invalid="yes">
+                <xsl:value-of select="normalize-space(marc:subfield[@code='z'])"/>
+            </identifier>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag='028']">
+            <identifier>
+                <xsl:attribute name="type">
+                    <xsl:choose>
+                        <xsl:when test="@ind1='0'">issue number</xsl:when>
+                        <xsl:when test="@ind1='1'">matrix number</xsl:when>
+                        <xsl:when test="@ind1='2'">music plate</xsl:when>
+                        <xsl:when test="@ind1='3'">music publisher</xsl:when>
+                        <xsl:when test="@ind1='4'">videorecording identifier</xsl:when>
+                    </xsl:choose>
+                </xsl:attribute>
+                <xsl:call-template name="subfieldSelect">
+                    <xsl:with-param name="codes">
+                        <xsl:choose>
+                            <xsl:when test="@ind1='0'">ba</xsl:when>
+                            <xsl:otherwise>ab</xsl:otherwise>
+                        </xsl:choose>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </identifier>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag='035'][marc:subfield[@code='a'][contains(text(), '(OCoLC)')]]">
+            <identifier type="oclc">
+                <xsl:value-of select="normalize-space(substring-after(marc:subfield[@code='a'], '(OCoLC)'))"/>
+            </identifier>
+        </xsl:for-each>
+
+
+        <!-- 3.5 1.95 20140421 -->
+        <xsl:for-each select="marc:datafield[@tag='035'][marc:subfield[@code='a'][contains(text(), '(WlCaITV)')]]">
+            <identifier type="WlCaITV">
+                <xsl:value-of select="normalize-space(substring-after(marc:subfield[@code='a'], '(WlCaITV)'))"/>
+            </identifier>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag='037']">
+            <identifier type="stock number">
+                <xsl:if test="marc:subfield[@code='c']">
+                    <xsl:attribute name="displayLabel">
+                        <xsl:call-template name="subfieldSelect">
+                            <xsl:with-param name="codes">c</xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:attribute>
+                </xsl:if>
+                <xsl:call-template name="subfieldSelect">
+                    <xsl:with-param name="codes">ab</xsl:with-param>
+                </xsl:call-template>
+            </identifier>
+        </xsl:for-each>
+
+
+        <!-- 1.51 tmee 20100129-->
+        <xsl:for-each select="marc:datafield[@tag='856'][marc:subfield[@code='u']]">
+            <xsl:if test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl') or starts-with(marc:subfield[@code='u'],'http://hdl.loc.gov') ">
+                <identifier>
+                    <xsl:attribute name="type">
+                        <xsl:if test="starts-with(marc:subfield[@code='u'],'urn:doi') or starts-with(marc:subfield[@code='u'],'doi')">doi</xsl:if>
+                        <xsl:if test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl') or starts-with(marc:subfield[@code='u'],'http://hdl.loc.gov')">hdl</xsl:if>
+                    </xsl:attribute>
+                    <xsl:value-of select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"/>
+                </identifier>
+            </xsl:if>
+            <xsl:if test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl')">
+                <identifier type="hdl">
+                    <xsl:if test="marc:subfield[@code='y' or @code='3' or @code='z']">
+                        <xsl:attribute name="displayLabel">
+                            <xsl:call-template name="subfieldSelect">
+                                <xsl:with-param name="codes">y3z</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:attribute>
+                    </xsl:if>
+                    <xsl:value-of select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"/>
+                </identifier>
+            </xsl:if>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=024][@ind1=1]">
+            <identifier type="upc">
+                <xsl:value-of select="marc:subfield[@code='a']"/>
+            </identifier>
+        </xsl:for-each>
+
+
+        <!-- 1.51 tmee 20100129 removed duplicate code 20131217
+        <xsl:for-each select="marc:datafield[@tag='856'][marc:subfield[@code='u']]">
+            <xsl:if
+                test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl') or starts-with(marc:subfield[@code='u'],'http://hdl.loc.gov') ">
+                <identifier>
+                    <xsl:attribute name="type">
+                        <xsl:if
+                            test="starts-with(marc:subfield[@code='u'],'urn:doi') or starts-with(marc:subfield[@code='u'],'doi')"
+                            >doi</xsl:if>
+                        <xsl:if
+                            test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl') or starts-with(marc:subfield[@code='u'],'http://hdl.loc.gov')"
+                            >hdl</xsl:if>
+                    </xsl:attribute>
+                    <xsl:value-of
+                        select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"
+                    />
+                </identifier>
+            </xsl:if>
+
+            <xsl:if
+                test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl')">
+                <identifier type="hdl">
+                    <xsl:if test="marc:subfield[@code='y' or @code='3' or @code='z']">
+                        <xsl:attribute name="displayLabel">
+                            <xsl:call-template name="subfieldSelect">
+                                <xsl:with-param name="codes">y3z</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:attribute>
+                    </xsl:if>
+                    <xsl:value-of
+                        select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"
+                    />
+                </identifier>
+            </xsl:if>
+        </xsl:for-each>
+        -->
+
+        <!-- 1.121 -->
+        <xsl:for-each select="marc:datafield[@tag=856][@ind2=2][marc:subfield[@code='u']] | marc:datafield[@tag='880'][@ind2=2][marc:subfield[@code='u']][starts-with(marc:subfield[@code='6'],'856')]">
+            <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+            <xsl:if test="@tag=856 or (@tag='880' and not(../marc:datafield[@tag='856'][@ind2=2][marc:subfield[@code='u']][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+            <relatedItem>
+                <location>
+                    <url>
+                        <xsl:if test="marc:subfield[@code='y' or @code='3']">
+                            <xsl:attribute name="displayLabel">
+                                <xsl:call-template name="subfieldSelect">
+                                    <xsl:with-param name="codes">y3</xsl:with-param>
+                                </xsl:call-template>
+                            </xsl:attribute>
+                        </xsl:if>
+                        <xsl:if test="marc:subfield[@code='z']">
+                            <xsl:attribute name="note">
+                                <xsl:call-template name="subfieldSelect">
+                                    <xsl:with-param name="codes">z</xsl:with-param>
+                                </xsl:call-template>
+                            </xsl:attribute>
+                        </xsl:if>
+                        <xsl:value-of select="marc:subfield[@code='u']"/>
+                    </url>
+                </location>
+            </relatedItem>
+            </xsl:if>
+        </xsl:for-each>
+
+        <recordInfo>
+            <xsl:for-each select="marc:leader[substring($leader,19,1)='a']">
+                <descriptionStandard>aacr</descriptionStandard>
+            </xsl:for-each>
+
+            <xsl:for-each select="marc:datafield[@tag=040]">
+                <xsl:if test="marc:subfield[@code='e']">
+                    <descriptionStandard>
+                        <xsl:value-of select="marc:subfield[@code='e']"/>
+                    </descriptionStandard>
+                </xsl:if>
+                <recordContentSource authority="marcorg">
+                    <xsl:value-of select="marc:subfield[@code='a']"/>
+                </recordContentSource>
+            </xsl:for-each>
+            <xsl:for-each select="marc:controlfield[@tag=008]">
+                <recordCreationDate encoding="marc">
+                    <xsl:value-of select="substring(.,1,6)"/>
+                </recordCreationDate>
+            </xsl:for-each>
+
+            <xsl:for-each select="marc:controlfield[@tag=005]">
+                <recordChangeDate encoding="iso8601">
+                    <xsl:value-of select="."/>
+                </recordChangeDate>
+            </xsl:for-each>
+            <xsl:for-each select="marc:controlfield[@tag=001]">
+                <recordIdentifier>
+                    <xsl:if test="../marc:controlfield[@tag=003]">
+                        <xsl:attribute name="source">
+                            <xsl:value-of select="../marc:controlfield[@tag=003]"/>
+                        </xsl:attribute>
+                    </xsl:if>
+                    <xsl:value-of select="."/>
+                </recordIdentifier>
+            </xsl:for-each>
+
+            <recordOrigin>Converted from MARCXML to MODS version 3.6 using MARC21slim2MODS3-6.xsl
+                (Revision 1.138 2020/01/06)</recordOrigin>
+
+            <xsl:for-each select="marc:datafield[@tag=040]/marc:subfield[@code='b']">
+                <languageOfCataloging>
+                    <languageTerm authority="iso639-2b" type="code">
+                        <xsl:value-of select="."/>
+                    </languageTerm>
+                </languageOfCataloging>
+            </xsl:for-each>
+        </recordInfo>
+    </xsl:template>
+
+    <xsl:template name="displayForm">
+        <xsl:for-each select="marc:subfield[@code='c']">
+            <displayForm>
+                <xsl:value-of select="."/>
+            </displayForm>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="affiliation">
+        <xsl:for-each select="marc:subfield[@code='u']">
+            <affiliation>
+                <xsl:value-of select="."/>
+            </affiliation>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="uri">
+        <xsl:for-each select="marc:subfield[@code='u']|marc:subfield[@code='0']">
+            <xsl:attribute name="xlink:href">
+                <xsl:value-of select="."/>
+            </xsl:attribute>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="role">
+        <xsl:for-each select="marc:subfield[@code='e']">
+            <role>
+                <roleTerm type="text">
+                    <!-- 1.126 -->
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString">
+                            <xsl:value-of select="."/>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </roleTerm>
+            </role>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='4']">
+            <role>
+                <roleTerm authority="marcrelator" type="code">
+                    <xsl:value-of select="."/>
+                </roleTerm>
+            </role>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="part">
+        <xsl:variable name="partNumber">
+            <xsl:call-template name="specialSubfieldSelect">
+                <xsl:with-param name="axis">n</xsl:with-param>
+                <xsl:with-param name="anyCodes">n</xsl:with-param>
+                <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
+            </xsl:call-template>
+        </xsl:variable>
+        <xsl:variable name="partName">
+            <xsl:choose>
+                <!-- 1.120 -->
+                <xsl:when test="@tag=700 or @tag=800 or @tag=710 or @tag=810 or @tag=711 or @tag=811 or @tag=730 or @tag=830 or @tag=740 or @tag=440">
+                    <xsl:value-of select="marc:subfield[@code='p']"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:call-template name="specialSubfieldSelect">
+                        <xsl:with-param name="axis">p</xsl:with-param>
+                        <xsl:with-param name="anyCodes">p</xsl:with-param>
+                        <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
+                    </xsl:call-template>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+        <xsl:if test="string-length(normalize-space($partNumber))">
+            <partNumber>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString" select="$partNumber"/>
+                </xsl:call-template>
+            </partNumber>
+        </xsl:if>
+        <xsl:if test="string-length(normalize-space($partName))">
+            <partName>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString" select="$partName"/>
+                </xsl:call-template>
+            </partName>
+        </xsl:if>
+    </xsl:template>
+    <!-- @depreciated see 1.121 -->
+    <xsl:template name="relatedPart">
+        <xsl:if test="@tag=773">
+            <xsl:for-each select="marc:subfield[@code='g']">
+                <part>
+                    <xsl:call-template name="xxs880"/>
+                    <text>
+                        <xsl:value-of select="."/>
+                    </text>
+                </part>
+            </xsl:for-each>
+            <xsl:for-each select="marc:subfield[@code='q']">
+                <part>
+                    <xsl:call-template name="xxs880"/>
+                    <xsl:call-template name="parsePart"/>
+                </part>
+            </xsl:for-each>
+        </xsl:if>
+    </xsl:template>
+    <xsl:template name="relatedPartNumName">
+        <xsl:variable name="partNumber">
+            <xsl:call-template name="specialSubfieldSelect">
+                <xsl:with-param name="axis">g</xsl:with-param>
+                <xsl:with-param name="anyCodes">g</xsl:with-param>
+                <xsl:with-param name="afterCodes">pst</xsl:with-param>
+            </xsl:call-template>
+        </xsl:variable>
+        <xsl:variable name="partName">
+            <xsl:call-template name="specialSubfieldSelect">
+                <xsl:with-param name="axis">p</xsl:with-param>
+                <xsl:with-param name="anyCodes">p</xsl:with-param>
+                <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
+            </xsl:call-template>
+        </xsl:variable>
+        <xsl:if test="string-length(normalize-space($partNumber))">
+            <partNumber>
+                <xsl:value-of select="$partNumber"/>
+            </partNumber>
+        </xsl:if>
+        <xsl:if test="string-length(normalize-space($partName))">
+            <partName>
+                <xsl:value-of select="$partName"/>
+            </partName>
+        </xsl:if>
+    </xsl:template>
+    <!-- 1.120 - @76X-78X$g -->
+    <xsl:template match="marc:subfield[@code='g']" mode="relatedItem">
+            <partNumber>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="."/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </partNumber>
+    </xsl:template>
+    <!-- 1.120 - @800$v -->
+    <xsl:template match="marc:subfield[@code='n'] | marc:subfield[@code='v']" mode="relatedItem">
+        <partNumber>
+            <xsl:call-template name="chopPunctuation">
+                <xsl:with-param name="chopString">
+                    <xsl:value-of select="."/>
+                </xsl:with-param>
+            </xsl:call-template>
+        </partNumber>
+    </xsl:template>
+    <!-- @800$p NOTE: does not output for 800, check mapping-->
+    <!-- Create related item title part name -->
+    <xsl:template match="marc:subfield[@code='p']" mode="relatedItem">
+        <!-- NOTE: old stylesheet outputs code p for 740, mapping does not indicate this -->
+        <!-- @700$t$p partnumber -->
+            <partName>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="."/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </partName>
+    </xsl:template>
+    <!-- 1.122 -->
+    <xsl:template match="marc:subfield[@code='0']" mode="xlink">
+        <xsl:attribute name="xlink:href">
+            <xsl:value-of select="."/>
+        </xsl:attribute>
+    </xsl:template>
+    <xsl:template name="relatedName">
+        <xsl:for-each select="marc:subfield[@code='a']">
+            <name>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxs880"/>
+                <namePart>
+                    <xsl:value-of select="."/>
+                </namePart>
+            </name>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="relatedForm">
+        <xsl:for-each select="marc:subfield[@code='h']">
+            <physicalDescription>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxs880"/>
+                <form>
+                    <xsl:value-of select="."/>
+                </form>
+            </physicalDescription>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="relatedExtent">
+        <xsl:for-each select="marc:subfield[@code='h']">
+            <physicalDescription>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxs880"/>
+                <extent>
+                    <xsl:value-of select="."/>
+                </extent>
+            </physicalDescription>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="relatedNote">
+        <xsl:for-each select="marc:subfield[@code='n']">
+            <!-- 1.121 -->
+            <xsl:call-template name="xxs880"/>
+            <note>
+                <xsl:value-of select="."/>
+            </note>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="relatedSubject">
+        <xsl:for-each select="marc:subfield[@code='j']">
+            <subject>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxs880"/>
+                <temporal encoding="iso8601">
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString" select="."/>
+                    </xsl:call-template>
+                </temporal>
+            </subject>
+        </xsl:for-each>
+    </xsl:template>
+    <!-- @depreciated see  1.120 - @76X-78X$z -->
+    <xsl:template name="relatedIdentifierISSN">
+        <xsl:for-each select="marc:subfield[@code='x']">
+            <identifier type="issn">
+                <xsl:value-of select="."/>
+            </identifier>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="relatedIdentifierLocal">
+        <xsl:for-each select="marc:subfield[@code='w']">
+            <identifier type="local">
+                <xsl:value-of select="."/>
+            </identifier>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="relatedIdentifier">
+        <xsl:for-each select="marc:subfield[@code='o']">
+            <identifier>
+                <xsl:value-of select="."/>
+            </identifier>
+        </xsl:for-each>
+    </xsl:template>
+    <!-- 1.120 - @76X-78X$z and 1.121 -->
+    <!-- Creates related item id -->
+    <xsl:template match="marc:subfield[@code='x']" mode="relatedItem">
+        <identifier type="issn">
+            <!-- 1.121 -->
+            <xsl:call-template name="xxs880"/>
+            <xsl:apply-templates/>
+        </identifier>
+    </xsl:template>
+    <!--  1.120 - @76X-78X$z -->
+    <xsl:template match="marc:subfield[@code='z']" mode="relatedItem">
+        <identifier type="isbn">
+            <!-- 1.121 -->
+            <xsl:call-template name="xxs880"/>
+            <xsl:apply-templates/>
+        </identifier>
+    </xsl:template>
+    <xsl:template match="marc:subfield[@code='w']" mode="relatedItem">
+        <identifier type="local">
+            <!-- 1.121 -->
+            <xsl:call-template name="xxs880"/>
+            <xsl:apply-templates/>
+        </identifier>
+    </xsl:template>
+    <xsl:template match="marc:subfield[@code='o']" mode="relatedItem">
+        <identifier>
+            <!-- 1.121 -->
+            <xsl:call-template name="xxs880"/>
+            <xsl:apply-templates/>
+        </identifier>
+    </xsl:template>
+
+    <!-- 1.121 --><!-- Creates related item notes -->
+    <xsl:template match="marc:subfield[@code='n']" mode="relatedItemNote">
+        <note>
+            <xsl:call-template name="xxs880"/>
+            <xsl:value-of select="."/>
+        </note>
+    </xsl:template>
+    <!-- 1.121 --><!-- Creates related item form -->
+    <xsl:template match="marc:subfield[@code='h']" mode="relatedItem">
+        <physicalDescription>
+            <xsl:call-template name="xxs880"/>
+            <form>
+                <xsl:apply-templates/>
+            </form>
+        </physicalDescription>
+    </xsl:template>
+    <!-- 1.121 --><!-- Creates related item subjects -->
+    <xsl:template match="marc:subfield[@code='j']" mode="relatedItem">
+        <subject>
+            <xsl:call-template name="xxs880"/>
+            <temporal encoding="iso8601">
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString" select="."/>
+                </xsl:call-template>
+            </temporal>
+        </subject>
+    </xsl:template>
+    <!-- 1.121 Creates related item names -->
+    <xsl:template match="marc:subfield[@code='a']" mode="relatedItem">
+        <name>
+            <xsl:call-template name="xxs880"/>
+            <namePart>
+                <!-- 1.126 -->
+                <xsl:value-of select="."/>
+            </namePart>
+        </name>
+    </xsl:template>
+
+    <!--tmee 1.40 510 isReferencedBy -->
+    <!-- @depreciated - no longer used -->
+    <xsl:template name="relatedItem510">
+        <xsl:call-template name="displayLabel"/>
+        <xsl:call-template name="relatedTitle76X-78X"/>
+        <xsl:call-template name="relatedName"/>
+        <xsl:call-template name="relatedOriginInfo510"/>
+        <xsl:call-template name="relatedLanguage"/>
+        <xsl:call-template name="relatedExtent"/>
+        <xsl:call-template name="relatedNote"/>
+        <xsl:call-template name="relatedSubject"/>
+        <xsl:call-template name="relatedIdentifier"/>
+        <xsl:call-template name="relatedIdentifierISSN"/>
+        <xsl:call-template name="relatedIdentifierLocal"/>
+        <xsl:call-template name="relatedPart"/>
+    </xsl:template>
+
+    <!-- @depreciated - no longer used see 1.121-->
+    <xsl:template name="relatedItem76X-78X">
+        <xsl:call-template name="displayLabel"/>
+        <xsl:call-template name="relatedTitle76X-78X"/>
+        <xsl:call-template name="relatedName"/>
+        <xsl:call-template name="relatedOriginInfo"/>
+        <xsl:call-template name="relatedLanguage"/>
+        <xsl:call-template name="relatedExtent"/>
+        <xsl:call-template name="relatedNote"/>
+        <xsl:call-template name="relatedSubject"/>
+        <xsl:call-template name="relatedIdentifier"/>
+        <xsl:call-template name="relatedIdentifierISSN"/>
+        <xsl:call-template name="relatedIdentifierLocal"/>
+        <xsl:call-template name="relatedPart"/>
+    </xsl:template>
+
+    <xsl:template name="subjectGeographicZ">
+        <geographic>
+            <xsl:call-template name="chopPunctuation">
+                <xsl:with-param name="chopString" select="."/>
+            </xsl:call-template>
+        </geographic>
+    </xsl:template>
+    <xsl:template name="subjectTemporalY">
+        <temporal>
+            <xsl:call-template name="chopPunctuation">
+                <xsl:with-param name="chopString" select="."/>
+            </xsl:call-template>
+        </temporal>
+    </xsl:template>
+    <xsl:template name="subjectTopic">
+        <topic>
+            <xsl:call-template name="chopPunctuation">
+                <xsl:with-param name="chopString" select="."/>
+            </xsl:call-template>
+        </topic>
+    </xsl:template>
+    <!-- 3.2 change tmee 6xx $v genre -->
+    <xsl:template name="subjectGenre">
+        <genre>
+            <xsl:call-template name="chopPunctuation">
+                <xsl:with-param name="chopString" select="."/>
+            </xsl:call-template>
+        </genre>
+    </xsl:template>
+
+    <xsl:template name="nameABCDN">
+        <xsl:for-each select="marc:subfield[@code='a']">
+            <namePart>
+                <!-- 1.126 -->
+                <xsl:value-of select="."/>
+            </namePart>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='b']">
+            <namePart>
+                <xsl:value-of select="."/>
+            </namePart>
+        </xsl:for-each>
+        <xsl:if test="marc:subfield[@code='c'] or marc:subfield[@code='d'] or marc:subfield[@code='n']">
+            <namePart>
+                <xsl:call-template name="subfieldSelect">
+                    <xsl:with-param name="codes">cdn</xsl:with-param>
+                </xsl:call-template>
+            </namePart>
+        </xsl:if>
+    </xsl:template>
+    <xsl:template name="nameABCDQ">
+        <namePart>
+            <!-- 1.126 -->
+                    <xsl:call-template name="subfieldSelect">
+                        <xsl:with-param name="codes">aq</xsl:with-param>
+                    </xsl:call-template>
+        </namePart>
+        <xsl:call-template name="termsOfAddress"/>
+        <xsl:call-template name="nameDate"/>
+    </xsl:template>
+    <xsl:template name="nameACDEQ">
+        <namePart>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">acdeq</xsl:with-param>
+            </xsl:call-template>
+        </namePart>
+    </xsl:template>
+
+    <!--1.104 20141104-->
+    <xsl:template name="nameACDENQ">
+        <namePart>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">acdenq</xsl:with-param>
+            </xsl:call-template>
+        </namePart>
+    </xsl:template>
+
+    <!-- 1.116 -->
+    <xsl:template name="nameIdentifier">
+        <xsl:if test="marc:subfield[@code='0']">
+            <nameIdentifier>
+                <xsl:call-template name="subfieldSelect">
+                    <xsl:with-param name="codes">0</xsl:with-param>
+                </xsl:call-template>
+            </nameIdentifier>
+        </xsl:if>
+    </xsl:template>
+
+
+    <xsl:template name="constituentOrRelatedType">
+        <xsl:if test="@ind2=2">
+            <xsl:attribute name="type">constituent</xsl:attribute>
+        </xsl:if>
+    </xsl:template>
+    <xsl:template name="relatedTitle">
+        <xsl:for-each select="marc:subfield[@code='t']">
+            <titleInfo>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxs880"/>
+                <title>
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString">
+                            <xsl:value-of select="."/>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </title>
+            </titleInfo>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="relatedTitle76X-78X">
+        <xsl:for-each select="marc:subfield[@code='t']">
+            <titleInfo>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxs880"/>
+                <title>
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString">
+                            <xsl:value-of select="."/>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </title>
+                <!-- 1.120 - @76X-78X$g -->
+                <xsl:if test="parent::*[@tag!=773] and ../marc:subfield[@code='g']">
+                    <xsl:apply-templates select="../marc:subfield[@code='g']" mode="relatedItem"/>
+                </xsl:if>
+            </titleInfo>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='p']">
+            <titleInfo type="abbreviated">
+                <!-- 1.121 -->
+                <xsl:call-template name="xxs880"/>
+                <title>
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString">
+                            <xsl:value-of select="."/>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </title>
+                <!-- 1.120 - @76X-78X$g -->
+                <xsl:if test="parent::*[@tag!=773] and ../marc:subfield[@code='g']">
+                    <xsl:apply-templates select="../marc:subfield[@code='g']" mode="relatedItem"/>
+                </xsl:if>
+            </titleInfo>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='s']">
+            <titleInfo type="uniform">
+                <xsl:call-template name="xxs880"/>
+                <title>
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString">
+                            <xsl:value-of select="."/>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </title>
+                <!-- 1.120 - @76X-78X$g -->
+                <xsl:if test="parent::*[@tag!=773] and ../marc:subfield[@code='g']">
+                    <xsl:apply-templates select="../marc:subfield[@code='g']" mode="relatedItem"/>
+                </xsl:if>
+            </titleInfo>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="relatedOriginInfo">
+        <xsl:if test="marc:subfield[@code='b' or @code='d'] or marc:subfield[@code='f']">
+            <originInfo>
+                <xsl:if test="@tag=775">
+                    <xsl:for-each select="marc:subfield[@code='f']">
+                        <place>
+                            <placeTerm>
+                                <xsl:attribute name="type">code</xsl:attribute>
+                                <xsl:attribute name="authority">marcgac</xsl:attribute>
+                                <xsl:value-of select="."/>
+                            </placeTerm>
+                        </place>
+                    </xsl:for-each>
+                </xsl:if>
+                <xsl:for-each select="marc:subfield[@code='d']">
+                    <publisher>
+                        <xsl:value-of select="."/>
+                    </publisher>
+                </xsl:for-each>
+                <xsl:for-each select="marc:subfield[@code='b']">
+                    <edition>
+                        <xsl:value-of select="."/>
+                    </edition>
+                </xsl:for-each>
+            </originInfo>
+        </xsl:if>
+    </xsl:template>
+
+    <!-- tmee 1.40 -->
+
+    <xsl:template name="relatedOriginInfo510">
+        <xsl:for-each select="marc:subfield[@code='b']">
+            <originInfo>
+                <dateOther type="coverage">
+                    <xsl:value-of select="."/>
+                </dateOther>
+            </originInfo>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="relatedLanguage">
+        <xsl:for-each select="marc:subfield[@code='e']">
+            <xsl:call-template name="getLanguage">
+                <xsl:with-param name="langString">
+                    <xsl:value-of select="."/>
+                </xsl:with-param>
+            </xsl:call-template>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="nameDate">
+        <xsl:for-each select="marc:subfield[@code='d']">
+            <namePart type="date">
+                <!-- 1.126 -->
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="."/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </namePart>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="subjectAuthority">
+        <xsl:if test="@ind2!=4">
+            <xsl:if test="@ind2!=' '">
+                <xsl:if test="@ind2!=8">
+                    <xsl:if test="@ind2!=9">
+                        <xsl:attribute name="authority">
+                            <xsl:choose>
+                                <xsl:when test="@ind2=0">lcsh</xsl:when>
+                                <xsl:when test="@ind2=1">lcshac</xsl:when>
+                                <xsl:when test="@ind2=2">mesh</xsl:when>
+                                <!-- 1/04 fix -->
+                                <xsl:when test="@ind2=3">nal</xsl:when>
+                                <xsl:when test="@ind2=5">csh</xsl:when>
+                                <xsl:when test="@ind2=6">rvm</xsl:when>
+                                <xsl:when test="@ind2=7">
+                                    <xsl:value-of select="marc:subfield[@code='2']"/>
+                                </xsl:when>
+                            </xsl:choose>
+                        </xsl:attribute>
+                    </xsl:if>
+                </xsl:if>
+            </xsl:if>
+        </xsl:if>
+    </xsl:template>
+    <!-- 1.75
+        fix -->
+    <xsl:template name="subject653Type">
+        <xsl:if test="@ind2!=' '">
+            <xsl:if test="@ind2!='0'">
+                <xsl:if test="@ind2!='4'">
+                    <xsl:if test="@ind2!='5'">
+                        <xsl:if test="@ind2!='6'">
+                            <xsl:if test="@ind2!='7'">
+                                <xsl:if test="@ind2!='8'">
+                                    <xsl:if test="@ind2!='9'">
+                                        <xsl:attribute name="type">
+                                            <xsl:choose>
+                                                <xsl:when test="@ind2=1">personal</xsl:when>
+                                                <xsl:when test="@ind2=2">corporate</xsl:when>
+                                                <xsl:when test="@ind2=3">conference</xsl:when>
+                                            </xsl:choose>
+                                        </xsl:attribute>
+                                    </xsl:if>
+                                </xsl:if>
+                            </xsl:if>
+                        </xsl:if>
+                    </xsl:if>
+                </xsl:if>
+            </xsl:if>
+        </xsl:if>
+
+
+    </xsl:template>
+    <xsl:template name="subjectAnyOrder">
+        <xsl:for-each select="marc:subfield[@code='v' or @code='x' or @code='y' or @code='z']">
+            <xsl:choose>
+                <xsl:when test="@code='v'">
+                    <xsl:call-template name="subjectGenre"/>
+                </xsl:when>
+                <xsl:when test="@code='x'">
+                    <xsl:call-template name="subjectTopic"/>
+                </xsl:when>
+                <xsl:when test="@code='y'">
+                    <xsl:call-template name="subjectTemporalY"/>
+                </xsl:when>
+                <xsl:when test="@code='z'">
+                    <xsl:call-template name="subjectGeographicZ"/>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="specialSubfieldSelect">
+        <xsl:param name="anyCodes"/>
+        <xsl:param name="axis"/>
+        <xsl:param name="beforeCodes"/>
+        <xsl:param name="afterCodes"/>
+        <xsl:variable name="str">
+            <xsl:for-each select="marc:subfield">
+                <xsl:if test="contains($anyCodes, @code) or (contains($beforeCodes,@code) and following-sibling::marc:subfield[@code=$axis])      or (contains($afterCodes,@code) and preceding-sibling::marc:subfield[@code=$axis])">
+                    <xsl:value-of select="text()"/>
+                    <xsl:text> </xsl:text>
+                </xsl:if>
+            </xsl:for-each>
+        </xsl:variable>
+        <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+    </xsl:template>
+
+
+    <xsl:template match="marc:datafield[@tag=656]">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <xsl:if test="marc:subfield[@code=2]">
+                <xsl:attribute name="authority">
+                    <xsl:value-of select="marc:subfield[@code=2]"/>
+                </xsl:attribute>
+            </xsl:if>
+            <occupation>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="marc:subfield[@code='a']"/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </occupation>
+        </subject>
+    </xsl:template>
+    <xsl:template name="termsOfAddress">
+        <xsl:if test="marc:subfield[@code='b' or @code='c']">
+            <namePart type="termsOfAddress">
+                <!-- 1.126 -->
+                        <xsl:call-template name="subfieldSelect">
+                            <xsl:with-param name="codes">bc</xsl:with-param>
+                        </xsl:call-template>
+            </namePart>
+        </xsl:if>
+    </xsl:template>
+    <xsl:template name="displayLabel">
+        <xsl:if test="marc:subfield[@code='i']">
+            <xsl:attribute name="displayLabel">
+                <xsl:value-of select="marc:subfield[@code='i']"/>
+            </xsl:attribute>
+        </xsl:if>
+        <xsl:if test="marc:subfield[@code='3']">
+            <xsl:attribute name="displayLabel">
+                <xsl:value-of select="marc:subfield[@code='3']"/>
+            </xsl:attribute>
+        </xsl:if>
+    </xsl:template>
+
+    <!-- isInvalid
+    <xsl:template name="isInvalid">
+        <xsl:param name="type"/>
+        <xsl:if
+            test="marc:subfield[@code='z'] or marc:subfield[@code='y'] or marc:subfield[@code='m']">
+            <identifier>
+                <xsl:attribute name="type">
+                    <xsl:value-of select="$type"/>
+                </xsl:attribute>
+                <xsl:attribute name="invalid">
+                    <xsl:text>yes</xsl:text>
+                </xsl:attribute>
+                <xsl:if test="marc:subfield[@code='z']">
+                    <xsl:value-of select="marc:subfield[@code='z']"/>
+                </xsl:if>
+                <xsl:if test="marc:subfield[@code='y']">
+                    <xsl:value-of select="marc:subfield[@code='y']"/>
+                </xsl:if>
+                <xsl:if test="marc:subfield[@code='m']">
+                    <xsl:value-of select="marc:subfield[@code='m']"/>
+                </xsl:if>
+            </identifier>
+        </xsl:if>
+    </xsl:template>
+    -->
+    <xsl:template name="subtitle">
+        <xsl:if test="marc:subfield[@code='b']">
+            <subTitle>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="marc:subfield[@code='b']"/>
+                        <!--<xsl:call-template name="subfieldSelect">
+                            <xsl:with-param name="codes">b</xsl:with-param>
+                        </xsl:call-template>-->
+                    </xsl:with-param>
+                </xsl:call-template>
+            </subTitle>
+        </xsl:if>
+    </xsl:template>
+    <xsl:template name="script">
+        <xsl:param name="scriptCode"/>
+        <xsl:attribute name="script">
+            <xsl:choose>
+                <!-- ISO 15924    and CJK is a local code    20101123-->
+                <xsl:when test="$scriptCode='(3'">Arab</xsl:when>
+                <xsl:when test="$scriptCode='(4'">Arab</xsl:when>
+                <xsl:when test="$scriptCode='(B'">Latn</xsl:when>
+                <xsl:when test="$scriptCode='!E'">Latn</xsl:when>
+                <xsl:when test="$scriptCode='$1'">CJK</xsl:when>
+                <xsl:when test="$scriptCode='(N'">Cyrl</xsl:when>
+                <xsl:when test="$scriptCode='(Q'">Cyrl</xsl:when>
+                <xsl:when test="$scriptCode='(2'">Hebr</xsl:when>
+                <xsl:when test="$scriptCode='(S'">Grek</xsl:when>
+            </xsl:choose>
+        </xsl:attribute>
+    </xsl:template>
+    <xsl:template name="parsePart">
+        <!-- assumes 773$q= 1:2:3<4
+             with up to 3 levels and one optional start page
+        -->
+        <xsl:variable name="level1">
+            <xsl:choose>
+                <xsl:when test="contains(text(),':')">
+                    <!-- 1:2 -->
+                    <xsl:value-of select="substring-before(text(),':')"/>
+                </xsl:when>
+                <xsl:when test="not(contains(text(),':'))">
+                    <!-- 1 or 1<3 -->
+                    <xsl:if test="contains(text(),'&lt;')">
+                        <!-- 1<3 -->
+                        <xsl:value-of select="substring-before(text(),'&lt;')"/>
+                    </xsl:if>
+                    <xsl:if test="not(contains(text(),'&lt;'))">
+                        <!-- 1 -->
+                        <xsl:value-of select="text()"/>
+                    </xsl:if>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:variable>
+        <xsl:variable name="sici2">
+            <xsl:choose>
+                <xsl:when test="starts-with(substring-after(text(),$level1),':')">
+                    <xsl:value-of select="substring(substring-after(text(),$level1),2)"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="substring-after(text(),$level1)"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+        <xsl:variable name="level2">
+            <xsl:choose>
+                <xsl:when test="contains($sici2,':')">
+                    <!--  2:3<4  -->
+                    <xsl:value-of select="substring-before($sici2,':')"/>
+                </xsl:when>
+                <xsl:when test="contains($sici2,'&lt;')">
+                    <!-- 1: 2<4 -->
+                    <xsl:value-of select="substring-before($sici2,'&lt;')"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="$sici2"/>
+                    <!-- 1:2 -->
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+        <xsl:variable name="sici3">
+            <xsl:choose>
+                <xsl:when test="starts-with(substring-after($sici2,$level2),':')">
+                    <xsl:value-of select="substring(substring-after($sici2,$level2),2)"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="substring-after($sici2,$level2)"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+        <xsl:variable name="level3">
+            <xsl:choose>
+                <xsl:when test="contains($sici3,'&lt;')">
+                    <!-- 2<4 -->
+                    <xsl:value-of select="substring-before($sici3,'&lt;')"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="$sici3"/>
+                    <!-- 3 -->
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
+        <xsl:variable name="page">
+            <xsl:if test="contains(text(),'&lt;')">
+                <xsl:value-of select="substring-after(text(),'&lt;')"/>
+            </xsl:if>
+        </xsl:variable>
+        <xsl:if test="$level1">
+            <detail level="1">
+                <number>
+                    <xsl:value-of select="$level1"/>
+                </number>
+            </detail>
+        </xsl:if>
+        <xsl:if test="$level2">
+            <detail level="2">
+                <number>
+                    <xsl:value-of select="$level2"/>
+                </number>
+            </detail>
+        </xsl:if>
+        <xsl:if test="$level3">
+            <detail level="3">
+                <number>
+                    <xsl:value-of select="$level3"/>
+                </number>
+            </detail>
+        </xsl:if>
+        <xsl:if test="$page">
+            <extent unit="page">
+                <start>
+                    <xsl:value-of select="$page"/>
+                </start>
+            </extent>
+        </xsl:if>
+    </xsl:template>
+    <xsl:template name="getLanguage">
+        <xsl:param name="langString"/>
+        <xsl:param name="controlField008-35-37"/>
+        <xsl:variable name="length" select="string-length($langString)"/>
+        <xsl:choose>
+            <xsl:when test="$length=0"/>
+            <xsl:when test="$controlField008-35-37=substring($langString,1,3)">
+                <xsl:call-template name="getLanguage">
+                    <xsl:with-param name="langString" select="substring($langString,4,$length)"/>
+                    <xsl:with-param name="controlField008-35-37" select="$controlField008-35-37"/>
+                </xsl:call-template>
+            </xsl:when>
+            <xsl:otherwise>
+                <language>
+                    <languageTerm authority="iso639-2b" type="code">
+                        <xsl:value-of select="substring($langString,1,3)"/>
+                    </languageTerm>
+                </language>
+                <xsl:call-template name="getLanguage">
+                    <xsl:with-param name="langString" select="substring($langString,4,$length)"/>
+                    <xsl:with-param name="controlField008-35-37" select="$controlField008-35-37"/>
+                </xsl:call-template>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+    <xsl:template name="isoLanguage">
+        <xsl:param name="currentLanguage"/>
+        <xsl:param name="usedLanguages"/>
+        <xsl:param name="remainingLanguages"/>
+        <xsl:choose>
+            <xsl:when test="string-length($currentLanguage)=0"/>
+            <xsl:when test="not(contains($usedLanguages, $currentLanguage))">
+                <language>
+                    <xsl:if test="@code!='a'">
+                        <xsl:attribute name="objectPart">
+                            <xsl:choose>
+                                <!-- 1.136 -->
+                                <xsl:when test="@code='b'">summary</xsl:when>
+                                <xsl:when test="@code='d'">sung or spoken text</xsl:when>
+                                <xsl:when test="@code='e'">libretto</xsl:when>
+                                <xsl:when test="@code='f'">table of contents</xsl:when>
+                                <xsl:when test="@code='g'">accompanying material</xsl:when>
+                                <xsl:when test="@code='h'">translation</xsl:when>
+                            </xsl:choose>
+                        </xsl:attribute>
+                    </xsl:if>
+                    <languageTerm authority="iso639-2b" type="code">
+                        <xsl:value-of select="$currentLanguage"/>
+                    </languageTerm>
+                </language>
+                <xsl:call-template name="isoLanguage">
+                    <xsl:with-param name="currentLanguage">
+                        <xsl:value-of select="substring($remainingLanguages,1,3)"/>
+                    </xsl:with-param>
+                    <xsl:with-param name="usedLanguages">
+                        <xsl:value-of select="concat($usedLanguages,$currentLanguage)"/>
+                    </xsl:with-param>
+                    <xsl:with-param name="remainingLanguages">
+                        <xsl:value-of select="substring($remainingLanguages,4,string-length($remainingLanguages))"/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:call-template name="isoLanguage">
+                    <xsl:with-param name="currentLanguage">
+                        <xsl:value-of select="substring($remainingLanguages,1,3)"/>
+                    </xsl:with-param>
+                    <xsl:with-param name="usedLanguages">
+                        <xsl:value-of select="concat($usedLanguages,$currentLanguage)"/>
+                    </xsl:with-param>
+                    <xsl:with-param name="remainingLanguages">
+                        <xsl:value-of select="substring($remainingLanguages,4,string-length($remainingLanguages))"/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+    <xsl:template name="chopBrackets">
+        <xsl:param name="chopString"/>
+        <xsl:variable name="string">
+            <xsl:call-template name="chopPunctuation">
+                <xsl:with-param name="chopString" select="$chopString"/>
+            </xsl:call-template>
+        </xsl:variable>
+        <xsl:if test="substring($string, 1,1)='['">
+            <xsl:value-of select="substring($string,2, string-length($string)-2)"/>
+        </xsl:if>
+        <xsl:if test="substring($string, 1,1)!='['">
+            <xsl:value-of select="$string"/>
+        </xsl:if>
+    </xsl:template>
+    <xsl:template name="rfcLanguages">
+        <xsl:param name="nodeNum"/>
+        <xsl:param name="usedLanguages"/>
+        <xsl:param name="controlField008-35-37"/>
+        <xsl:variable name="currentLanguage" select="."/>
+        <xsl:choose>
+            <xsl:when test="not($currentLanguage)"/>
+            <xsl:when test="$currentLanguage!=$controlField008-35-37 and $currentLanguage!='rfc3066'">
+                <xsl:if test="not(contains($usedLanguages,$currentLanguage))">
+                    <language>
+                        <xsl:if test="@code!='a'">
+                            <xsl:attribute name="objectPart">
+                                <xsl:choose>
+                                    <xsl:when test="@code='b'">summary or subtitle</xsl:when>
+                                    <xsl:when test="@code='d'">sung or spoken text</xsl:when>
+                                    <xsl:when test="@code='e'">libretto</xsl:when>
+                                    <xsl:when test="@code='f'">table of contents</xsl:when>
+                                    <xsl:when test="@code='g'">accompanying material</xsl:when>
+                                    <xsl:when test="@code='h'">translation</xsl:when>
+                                </xsl:choose>
+                            </xsl:attribute>
+                        </xsl:if>
+                        <languageTerm authority="rfc3066" type="code">
+                            <xsl:value-of select="$currentLanguage"/>
+                        </languageTerm>
+                    </language>
+                </xsl:if>
+            </xsl:when>
+            <xsl:otherwise> </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <!-- tmee added 20100106 for 045$b BC and CE date range info -->
+    <xsl:template name="dates045b">
+        <xsl:param name="str"/>
+        <xsl:variable name="first-char" select="substring($str,1,1)"/>
+        <xsl:choose>
+            <xsl:when test="$first-char ='c'">
+                <xsl:value-of select="concat ('-', substring($str, 2))"/>
+            </xsl:when>
+            <xsl:when test="$first-char ='d'">
+                <xsl:value-of select="substring($str, 2)"/>
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:value-of select="$str"/>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="scriptCode">
+        <xsl:variable name="sf06" select="normalize-space(child::marc:subfield[@code='6'])"/>
+        <xsl:variable name="sf06a" select="substring($sf06, 1, 3)"/>
+        <xsl:variable name="sf06b" select="substring($sf06, 5, 2)"/>
+        <xsl:variable name="sf06c" select="substring($sf06, 7)"/>
+        <xsl:variable name="scriptCode" select="substring($sf06, 8, 2)"/>
+        <xsl:if test="//marc:datafield/marc:subfield[@code='6']">
+            <xsl:attribute name="script">
+                <xsl:choose>
+                    <xsl:when test="$scriptCode=''">Latn</xsl:when>
+                    <xsl:when test="$scriptCode='(3'">Arab</xsl:when>
+                    <xsl:when test="$scriptCode='(4'">Arab</xsl:when>
+                    <xsl:when test="$scriptCode='(B'">Latn</xsl:when>
+                    <xsl:when test="$scriptCode='!E'">Latn</xsl:when>
+                    <xsl:when test="$scriptCode='$1'">CJK</xsl:when>
+                    <xsl:when test="$scriptCode='(N'">Cyrl</xsl:when>
+                    <xsl:when test="$scriptCode='(Q'">Cyrl</xsl:when>
+                    <xsl:when test="$scriptCode='(2'">Hebr</xsl:when>
+                    <xsl:when test="$scriptCode='(S'">Grek</xsl:when>
+                </xsl:choose>
+            </xsl:attribute>
+        </xsl:if>
+    </xsl:template>
+
+    <!-- tmee 20100927 for 880s & corresponding fields  20101123 scriptCode -->
+    <!-- 1.121 --><!-- 880 processing -->
+    <xsl:template name="xxx880">
+        <!-- Checks for subfield $6 ands linking data -->
+        <xsl:if test="child::marc:subfield[@code='6']">
+            <xsl:variable name="sf06" select="normalize-space(child::marc:subfield[@code='6'])"/>
+            <xsl:variable name="sf06b" select="substring($sf06, 5, 2)"/>
+            <xsl:variable name="scriptCode" select="substring($sf06, 8, 2)"/>
+            <!-- 1.121 -->
+            <xsl:if test="$sf06b != '00'">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="$sf06b"/>
+                </xsl:attribute>
+            </xsl:if>
+            <xsl:call-template name="scriptCode"/>
+        </xsl:if>
+    </xsl:template>
+    <!--1.121 --><!-- 880 processing when called from subfield -->
+    <xsl:template name="xxs880">
+        <!-- Checks for subfield $6 ands linking data -->
+        <xsl:if test="preceding-sibling::*[@code='6']">
+            <xsl:variable name="sf06" select="normalize-space(preceding-sibling::*[@code='6'])"/>
+            <xsl:variable name="sf06b" select="substring($sf06, 5, 2)"/>
+            <xsl:variable name="scriptCode" select="substring($sf06, 8, 2)"/>
+            <!-- 1.121 -->
+            <xsl:if test="$sf06b != '00'">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="$sf06b"/>
+                </xsl:attribute>
+            </xsl:if>
+            <xsl:attribute name="script">
+                <xsl:choose>
+                    <xsl:when test="$scriptCode=''">Latn</xsl:when>
+                    <xsl:when test="$scriptCode='(3'">Arab</xsl:when>
+                    <xsl:when test="$scriptCode='(4'">Arab</xsl:when>
+                    <xsl:when test="$scriptCode='(B'">Latn</xsl:when>
+                    <xsl:when test="$scriptCode='!E'">Latn</xsl:when>
+                    <xsl:when test="$scriptCode='$1'">CJK</xsl:when>
+                    <xsl:when test="$scriptCode='(N'">Cyrl</xsl:when>
+                    <xsl:when test="$scriptCode='(Q'">Cyrl</xsl:when>
+                    <xsl:when test="$scriptCode='(2'">Hebr</xsl:when>
+                    <xsl:when test="$scriptCode='(S'">Grek</xsl:when>
+                </xsl:choose>
+            </xsl:attribute>
+        </xsl:if>
+    </xsl:template>
+
+    <!-- @depreciated $880$6
+    <xsl:template name="xxx880">
+        <xsl:if test="child::marc:subfield[@code='6']">
+            <xsl:variable name="sf06" select="normalize-space(child::marc:subfield[@code='6'])"/>
+            <xsl:variable name="sf06a" select="substring($sf06, 1, 3)"/>
+            <xsl:variable name="sf06b" select="substring($sf06, 5, 2)"/>
+            <xsl:variable name="sf06c" select="substring($sf06, 7)"/>
+            <xsl:variable name="scriptCode" select="substring($sf06, 8, 2)"/>
+            <xsl:if test="//marc:datafield/marc:subfield[@code='6']">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="$sf06b"/>
+                </xsl:attribute>
+                <xsl:attribute name="script">
+                    <xsl:choose>
+                        <xsl:when test="$scriptCode=''">Latn</xsl:when>
+                        <xsl:when test="$scriptCode='(3'">Arab</xsl:when>
+                        <xsl:when test="$scriptCode='(4'">Arab</xsl:when>
+                        <xsl:when test="$scriptCode='(B'">Latn</xsl:when>
+                        <xsl:when test="$scriptCode='!E'">Latn</xsl:when>
+                        <xsl:when test="$scriptCode='$1'">CJK</xsl:when>
+                        <xsl:when test="$scriptCode='(N'">Cyrl</xsl:when>
+                        <xsl:when test="$scriptCode='(Q'">Cyrl</xsl:when>
+                        <xsl:when test="$scriptCode='(2'">Hebr</xsl:when>
+                        <xsl:when test="$scriptCode='(S'">Grek</xsl:when>
+                    </xsl:choose>
+                </xsl:attribute>
+            </xsl:if>
+        </xsl:if>
+    </xsl:template>
+    -->
+
+    <xsl:template name="yyy880">
+        <xsl:if test="preceding-sibling::marc:subfield[@code='6']">
+            <xsl:variable name="sf06" select="normalize-space(preceding-sibling::marc:subfield[@code='6'])"/>
+            <xsl:variable name="sf06a" select="substring($sf06, 1, 3)"/>
+            <xsl:variable name="sf06b" select="substring($sf06, 5, 2)"/>
+            <xsl:variable name="sf06c" select="substring($sf06, 7)"/>
+            <xsl:if test="//marc:datafield/marc:subfield[@code='6']">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="$sf06b"/>
+                </xsl:attribute>
+            </xsl:if>
+        </xsl:if>
+    </xsl:template>
+
+    <xsl:template name="z2xx880">
+        <!-- Evaluating the 260 field -->
+        <xsl:variable name="x260">
+            <xsl:choose>
+                <xsl:when test="@tag='260' and marc:subfield[@code='6']">
+                    <xsl:variable name="sf06260" select="normalize-space(child::marc:subfield[@code='6'])"/>
+                    <xsl:variable name="sf06260a" select="substring($sf06260, 1, 3)"/>
+                    <xsl:variable name="sf06260b" select="substring($sf06260, 5, 2)"/>
+                    <xsl:variable name="sf06260c" select="substring($sf06260, 7)"/>
+                    <xsl:value-of select="$sf06260b"/>
+                </xsl:when>
+                <xsl:when test="@tag='250' and ../marc:datafield[@tag='260']/marc:subfield[@code='6']">
+                    <xsl:variable name="sf06260" select="normalize-space(../marc:datafield[@tag='260']/marc:subfield[@code='6'])"/>
+                    <xsl:variable name="sf06260a" select="substring($sf06260, 1, 3)"/>
+                    <xsl:variable name="sf06260b" select="substring($sf06260, 5, 2)"/>
+                    <xsl:variable name="sf06260c" select="substring($sf06260, 7)"/>
+                    <xsl:value-of select="$sf06260b"/>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:variable>
+
+        <xsl:variable name="x250">
+            <xsl:choose>
+                <xsl:when test="@tag='250' and marc:subfield[@code='6']">
+                    <xsl:variable name="sf06250" select="normalize-space(../marc:datafield[@tag='250']/marc:subfield[@code='6'])"/>
+                    <xsl:variable name="sf06250a" select="substring($sf06250, 1, 3)"/>
+                    <xsl:variable name="sf06250b" select="substring($sf06250, 5, 2)"/>
+                    <xsl:variable name="sf06250c" select="substring($sf06250, 7)"/>
+                    <xsl:value-of select="$sf06250b"/>
+                </xsl:when>
+                <xsl:when test="@tag='260' and ../marc:datafield[@tag='250']/marc:subfield[@code='6']">
+                    <xsl:variable name="sf06250" select="normalize-space(../marc:datafield[@tag='250']/marc:subfield[@code='6'])"/>
+                    <xsl:variable name="sf06250a" select="substring($sf06250, 1, 3)"/>
+                    <xsl:variable name="sf06250b" select="substring($sf06250, 5, 2)"/>
+                    <xsl:variable name="sf06250c" select="substring($sf06250, 7)"/>
+                    <xsl:value-of select="$sf06250b"/>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:variable>
+
+        <xsl:choose>
+            <xsl:when test="$x250!='' and $x260!=''">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="concat($x250, $x260)"/>
+                </xsl:attribute>
+            </xsl:when>
+            <xsl:when test="$x250!=''">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="$x250"/>
+                </xsl:attribute>
+            </xsl:when>
+            <xsl:when test="$x260!=''">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="$x260"/>
+                </xsl:attribute>
+            </xsl:when>
+        </xsl:choose>
+        <xsl:if test="//marc:datafield/marc:subfield[@code='6']"> </xsl:if>
+    </xsl:template>
+
+    <xsl:template name="z3xx880">
+        <!-- Evaluating the 300 field -->
+        <xsl:variable name="x300">
+            <xsl:choose>
+                <xsl:when test="@tag='300' and marc:subfield[@code='6']">
+                    <xsl:variable name="sf06300" select="normalize-space(child::marc:subfield[@code='6'])"/>
+                    <xsl:variable name="sf06300a" select="substring($sf06300, 1, 3)"/>
+                    <xsl:variable name="sf06300b" select="substring($sf06300, 5, 2)"/>
+                    <xsl:variable name="sf06300c" select="substring($sf06300, 7)"/>
+                    <xsl:value-of select="$sf06300b"/>
+                </xsl:when>
+                <xsl:when test="@tag='351' and ../marc:datafield[@tag='300']/marc:subfield[@code='6']">
+                    <xsl:variable name="sf06300" select="normalize-space(../marc:datafield[@tag='300']/marc:subfield[@code='6'])"/>
+                    <xsl:variable name="sf06300a" select="substring($sf06300, 1, 3)"/>
+                    <xsl:variable name="sf06300b" select="substring($sf06300, 5, 2)"/>
+                    <xsl:variable name="sf06300c" select="substring($sf06300, 7)"/>
+                    <xsl:value-of select="$sf06300b"/>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:variable>
+
+        <xsl:variable name="x351">
+            <xsl:choose>
+                <xsl:when test="@tag='351' and marc:subfield[@code='6']">
+                    <xsl:variable name="sf06351" select="normalize-space(../marc:datafield[@tag='351']/marc:subfield[@code='6'])"/>
+                    <xsl:variable name="sf06351a" select="substring($sf06351, 1, 3)"/>
+                    <xsl:variable name="sf06351b" select="substring($sf06351, 5, 2)"/>
+                    <xsl:variable name="sf06351c" select="substring($sf06351, 7)"/>
+                    <xsl:value-of select="$sf06351b"/>
+                </xsl:when>
+                <xsl:when test="@tag='300' and ../marc:datafield[@tag='351']/marc:subfield[@code='6']">
+                    <xsl:variable name="sf06351" select="normalize-space(../marc:datafield[@tag='351']/marc:subfield[@code='6'])"/>
+                    <xsl:variable name="sf06351a" select="substring($sf06351, 1, 3)"/>
+                    <xsl:variable name="sf06351b" select="substring($sf06351, 5, 2)"/>
+                    <xsl:variable name="sf06351c" select="substring($sf06351, 7)"/>
+                    <xsl:value-of select="$sf06351b"/>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:variable>
+
+        <xsl:variable name="x337">
+            <xsl:if test="@tag='337' and marc:subfield[@code='6']">
+                <xsl:variable name="sf06337" select="normalize-space(child::marc:subfield[@code='6'])"/>
+                <xsl:variable name="sf06337a" select="substring($sf06337, 1, 3)"/>
+                <xsl:variable name="sf06337b" select="substring($sf06337, 5, 2)"/>
+                <xsl:variable name="sf06337c" select="substring($sf06337, 7)"/>
+                <xsl:value-of select="$sf06337b"/>
+            </xsl:if>
+        </xsl:variable>
+        <xsl:variable name="x338">
+            <xsl:if test="@tag='338' and marc:subfield[@code='6']">
+                <xsl:variable name="sf06338" select="normalize-space(child::marc:subfield[@code='6'])"/>
+                <xsl:variable name="sf06338a" select="substring($sf06338, 1, 3)"/>
+                <xsl:variable name="sf06338b" select="substring($sf06338, 5, 2)"/>
+                <xsl:variable name="sf06338c" select="substring($sf06338, 7)"/>
+                <xsl:value-of select="$sf06338b"/>
+            </xsl:if>
+        </xsl:variable>
+
+        <xsl:choose>
+            <xsl:when test="$x351!='' and $x300!=''">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="concat($x351, $x300, $x337, $x338)"/>
+                </xsl:attribute>
+            </xsl:when>
+            <xsl:when test="$x351!=''">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="$x351"/>
+                </xsl:attribute>
+            </xsl:when>
+            <xsl:when test="$x300!=''">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="$x300"/>
+                </xsl:attribute>
+            </xsl:when>
+            <xsl:when test="$x337!=''">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="$x351"/>
+                </xsl:attribute>
+            </xsl:when>
+            <xsl:when test="$x338!=''">
+                <xsl:attribute name="altRepGroup">
+                    <xsl:value-of select="$x300"/>
+                </xsl:attribute>
+            </xsl:when>
+        </xsl:choose>
+        <xsl:if test="//marc:datafield/marc:subfield[@code='6']"> </xsl:if>
+    </xsl:template>
+
+
+
+    <xsl:template name="true880">
+        <xsl:variable name="sf06" select="normalize-space(marc:subfield[@code='6'])"/>
+        <xsl:variable name="sf06a" select="substring($sf06, 1, 3)"/>
+        <xsl:variable name="sf06b" select="substring($sf06, 5, 2)"/>
+        <xsl:variable name="sf06c" select="substring($sf06, 7)"/>
+        <xsl:if test="//marc:datafield/marc:subfield[@code='6']">
+            <xsl:attribute name="altRepGroup">
+                <xsl:value-of select="$sf06b"/>
+            </xsl:attribute>
+        </xsl:if>
+    </xsl:template>
+
+    <xsl:template match="marc:datafield" mode="trans880">
+        <xsl:variable name="dataField880" select="//marc:datafield"/>
+        <xsl:variable name="sf06" select="normalize-space(marc:subfield[@code='6'])"/>
+        <xsl:variable name="sf06a" select="substring($sf06, 1, 3)"/>
+        <xsl:variable name="sf06b" select="substring($sf06, 4)"/>
+        <xsl:choose>
+
+            <!--tranforms 880 equiv-->
+
+            <xsl:when test="$sf06a='047'">
+                <xsl:call-template name="createGenreFrom047"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='336'">
+                <xsl:call-template name="createGenreFrom336"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='655'">
+                <xsl:call-template name="createGenreFrom655"/>
+            </xsl:when>
+
+            <xsl:when test="$sf06a='050'">
+                <xsl:call-template name="createClassificationFrom050"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='060'">
+                <xsl:call-template name="createClassificationFrom060"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='080'">
+                <xsl:call-template name="createClassificationFrom080"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='082'">
+                <xsl:call-template name="createClassificationFrom082"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='084'">
+                <xsl:call-template name="createClassificationFrom080"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='086'">
+                <xsl:call-template name="createClassificationFrom082"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='100'">
+                <xsl:call-template name="createNameFrom100"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='110'">
+                <xsl:call-template name="createNameFrom110"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='111'">
+                <xsl:call-template name="createNameFrom110"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='700'">
+                <xsl:call-template name="createNameFrom700"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='710'">
+                <xsl:call-template name="createNameFrom710"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='711'">
+                <xsl:call-template name="createNameFrom710"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='210'">
+                <xsl:call-template name="createTitleInfoFrom210"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='245'">
+                <xsl:call-template name="createTitleInfoFrom245"/>
+                <xsl:call-template name="createNoteFrom245c"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='246'">
+                <xsl:call-template name="createTitleInfoFrom246"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='240'">
+                <xsl:call-template name="createTitleInfoFrom240"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='740'">
+                <xsl:call-template name="createTitleInfoFrom740"/>
+            </xsl:when>
+
+            <xsl:when test="$sf06a='130'">
+                <xsl:call-template name="createTitleInfoFrom130"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='730'">
+                <xsl:call-template name="createTitleInfoFrom730"/>
+            </xsl:when>
+
+            <xsl:when test="$sf06a='505'">
+                <xsl:call-template name="createTOCFrom505"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='520'">
+                <xsl:call-template name="createAbstractFrom520"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='521'">
+                <xsl:call-template name="createTargetAudienceFrom521"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='506'">
+                <xsl:call-template name="createAccessConditionFrom506"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='540'">
+                <xsl:call-template name="createAccessConditionFrom540"/>
+            </xsl:when>
+
+            <!-- note 245 362 etc    -->
+
+            <xsl:when test="$sf06a='245'">
+                <xsl:call-template name="createNoteFrom245c"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='362'">
+                <xsl:call-template name="createNoteFrom362"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='502'">
+                <xsl:call-template name="createNoteFrom502"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='504'">
+                <xsl:call-template name="createNoteFrom504"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='508'">
+                <xsl:call-template name="createNoteFrom508"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='511'">
+                <xsl:call-template name="createNoteFrom511"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='515'">
+                <xsl:call-template name="createNoteFrom515"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='518'">
+                <xsl:call-template name="createNoteFrom518"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='524'">
+                <xsl:call-template name="createNoteFrom524"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='530'">
+                <xsl:call-template name="createNoteFrom530"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='533'">
+                <xsl:call-template name="createNoteFrom533"/>
+            </xsl:when>
+            <!--
+            <xsl:when test="$sf06a='534'">
+                <xsl:call-template name="createNoteFrom534"/>
+            </xsl:when>
+-->
+            <xsl:when test="$sf06a='535'">
+                <xsl:call-template name="createNoteFrom535"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='536'">
+                <xsl:call-template name="createNoteFrom536"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='538'">
+                <xsl:call-template name="createNoteFrom538"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='541'">
+                <xsl:call-template name="createNoteFrom541"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='545'">
+                <xsl:call-template name="createNoteFrom545"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='546'">
+                <xsl:call-template name="createNoteFrom546"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='561'">
+                <xsl:call-template name="createNoteFrom561"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='562'">
+                <xsl:call-template name="createNoteFrom562"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='581'">
+                <xsl:call-template name="createNoteFrom581"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='583'">
+                <xsl:call-template name="createNoteFrom583"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='585'">
+                <xsl:call-template name="createNoteFrom585"/>
+            </xsl:when>
+
+            <!--    note 5XX    -->
+
+            <xsl:when test="$sf06a='501'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='507'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='513'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='514'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='516'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='522'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='525'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='526'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='544'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='552'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='555'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='556'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='565'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='567'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='580'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='584'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='586'">
+                <xsl:call-template name="createNoteFrom5XX"/>
+            </xsl:when>
+
+            <!--  subject 034 043 045 255 656 662 752     -->
+
+            <xsl:when test="$sf06a='034'">
+                <xsl:call-template name="createSubGeoFrom034"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='043'">
+                <xsl:call-template name="createSubGeoFrom043"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='045'">
+                <xsl:call-template name="createSubTemFrom045"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='255'">
+                <xsl:call-template name="createSubGeoFrom255"/>
+            </xsl:when>
+
+            <xsl:when test="$sf06a='600'">
+                <xsl:call-template name="createSubNameFrom600"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='610'">
+                <xsl:call-template name="createSubNameFrom610"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='611'">
+                <xsl:call-template name="createSubNameFrom611"/>
+            </xsl:when>
+
+            <xsl:when test="$sf06a='630'">
+                <xsl:call-template name="createSubTitleFrom630"/>
+            </xsl:when>
+
+            <xsl:when test="$sf06a='648'">
+                <xsl:call-template name="createSubChronFrom648"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='650'">
+                <xsl:call-template name="createSubTopFrom650"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='651'">
+                <xsl:call-template name="createSubGeoFrom651"/>
+            </xsl:when>
+
+
+            <xsl:when test="$sf06a='653'">
+                <xsl:call-template name="createSubFrom653"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='656'">
+                <xsl:call-template name="createSubFrom656"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='662'">
+                <xsl:call-template name="createSubGeoFrom662752"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='752'">
+                <xsl:call-template name="createSubGeoFrom662752"/>
+            </xsl:when>
+
+            <!--  location  852 856 -->
+
+            <xsl:when test="$sf06a='852'">
+                <xsl:call-template name="createLocationFrom852"/>
+            </xsl:when>
+            <xsl:when test="$sf06a='856'">
+                <xsl:call-template name="createLocationFrom856"/>
+            </xsl:when>
+
+            <xsl:when test="$sf06a='490'">
+                <xsl:call-template name="createRelatedItemFrom490"/>
+            </xsl:when>
+        </xsl:choose>
+    </xsl:template>
+
+    <!-- titleInfo 130 730 245 246 240 740 210 -->
+
+    <!-- 130 tmee 1.101 20140806-->
+    <xsl:template name="createTitleInfoFrom130">
+            <titleInfo type="uniform">
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <!-- 1.122 -->
+                <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+                <title>
+                    <xsl:variable name="str">
+                        <xsl:for-each select="marc:subfield">
+                            <xsl:if test="(contains('s',@code))">
+                                <xsl:value-of select="text()"/>
+                                <xsl:text> </xsl:text>
+                            </xsl:if>
+                            <xsl:if test="(contains('adfklmors',@code) and (not(../marc:subfield[@code='n' or @code='p']) or (following-sibling::marc:subfield[@code='n' or @code='p'])))">
+                                <xsl:value-of select="text()"/>
+                                <xsl:text> </xsl:text>
+                            </xsl:if>
+                        </xsl:for-each>
+                    </xsl:variable>
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString">
+                            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </title>
+                <xsl:call-template name="part"/>
+            </titleInfo>
+    </xsl:template>
+    <xsl:template name="createTitleInfoFrom730">
+        <titleInfo type="uniform">
+            <!-- 1.121 -->
+            <xsl:call-template name="xxx880"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+            <title>
+                <xsl:variable name="str">
+                    <xsl:for-each select="marc:subfield">
+                        <xsl:if test="(contains('s',@code))">
+                            <xsl:value-of select="text()"/>
+                            <xsl:text> </xsl:text>
+                        </xsl:if>
+                        <xsl:if test="(contains('adfklmors',@code) and (not(../marc:subfield[@code='n' or @code='p']) or (following-sibling::marc:subfield[@code='n' or @code='p'])))">
+                            <xsl:value-of select="text()"/>
+                            <xsl:text> </xsl:text>
+                        </xsl:if>
+                    </xsl:for-each>
+                </xsl:variable>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </title>
+            <xsl:call-template name="part"/>
+        </titleInfo>
+    </xsl:template>
+
+    <xsl:template name="createTitleInfoFrom210">
+        <titleInfo type="abbreviated">
+            <xsl:if test="marc:datafield[@tag='210'][@ind2='2']">
+                <xsl:attribute name="authority">
+                    <xsl:value-of select="marc:subfield[@code='2']"/>
+                </xsl:attribute>
+            </xsl:if>
+            <xsl:call-template name="xxx880"/>
+            <title>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:call-template name="subfieldSelect">
+                            <xsl:with-param name="codes">a</xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </title>
+            <xsl:call-template name="subtitle"/>
+        </titleInfo>
+    </xsl:template>
+    <!-- 1.79 -->
+    <xsl:template name="createTitleInfoFrom245">
+        <titleInfo>
+            <xsl:call-template name="xxx880"/>
+            <xsl:variable name="title">
+                <xsl:choose>
+                    <xsl:when test="marc:subfield[@code='b']">
+                        <xsl:call-template name="specialSubfieldSelect">
+                            <xsl:with-param name="axis">b</xsl:with-param>
+                            <xsl:with-param name="beforeCodes">afgks</xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:call-template name="subfieldSelect">
+                            <xsl:with-param name="codes">abfgks</xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:otherwise>
+                </xsl:choose>
+            </xsl:variable>
+            <xsl:variable name="titleChop">
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="$title"/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </xsl:variable>
+            <xsl:choose>
+                <!-- 1.120 - @245/@880$ind2-->
+                <xsl:when test="@ind2 != ' ' and @ind2&gt;0">
+                    <!-- 1.112 -->
+                    <nonSort xml:space="preserve"><xsl:value-of select="substring($titleChop,1,@ind2)"/> </nonSort>
+                    <title>
+                        <xsl:value-of select="substring($titleChop,@ind2+1)"/>
+                    </title>
+                </xsl:when>
+                <xsl:otherwise>
+                    <title>
+                        <xsl:value-of select="$titleChop"/>
+                    </title>
+                </xsl:otherwise>
+            </xsl:choose>
+            <xsl:if test="marc:subfield[@code='b']">
+                <subTitle>
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString">
+                            <xsl:call-template name="specialSubfieldSelect">
+                                <xsl:with-param name="axis">b</xsl:with-param>
+                                <xsl:with-param name="anyCodes">b</xsl:with-param>
+                                <xsl:with-param name="afterCodes">afgks</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </subTitle>
+            </xsl:if>
+            <xsl:call-template name="part"/>
+        </titleInfo>
+    </xsl:template>
+
+    <xsl:template name="createTitleInfoFrom246">
+        <titleInfo>
+            <!-- 1.120 - @246/ind2=1 -->
+            <xsl:choose>
+                <xsl:when test="@ind2='1'">
+                    <xsl:attribute name="type">translated</xsl:attribute>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:attribute name="type">alternative</xsl:attribute>
+                </xsl:otherwise>
+            </xsl:choose>
+            <xsl:call-template name="xxx880"/>
+            <xsl:for-each select="marc:subfield[@code='i']">
+                <xsl:attribute name="displayLabel">
+                    <xsl:value-of select="text()"/>
+                </xsl:attribute>
+            </xsl:for-each>
+            <title>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:call-template name="subfieldSelect">
+                            <!-- 1/04 removed $h, $b -->
+                            <xsl:with-param name="codes">af</xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </title>
+            <xsl:call-template name="subtitle"/>
+            <xsl:call-template name="part"/>
+        </titleInfo>
+    </xsl:template>
+
+    <!-- 240 nameTitleGroup-->
+    <!-- 1.102 -->
+
+    <xsl:template name="createTitleInfoFrom240">
+        <titleInfo type="uniform">
+            <!-- 1.123 Add nameTitleGroup attribute if necessary -->
+            <xsl:call-template name="nameTitleGroup"/>
+            <xsl:call-template name="xxx880"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+            <title>
+                <xsl:variable name="str">
+                    <xsl:for-each select="marc:subfield">
+                        <xsl:if test="(contains('adfklmors',@code) and (not(../marc:subfield[@code='n' or @code='p']) or (following-sibling::marc:subfield[@code='n' or @code='p'])))">
+                            <xsl:value-of select="text()"/>
+                            <xsl:text> </xsl:text>
+                        </xsl:if>
+                    </xsl:for-each>
+                </xsl:variable>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </title>
+            <xsl:call-template name="part"/>
+        </titleInfo>
+    </xsl:template>
+
+    <xsl:template name="createTitleInfoFrom740">
+        <titleInfo type="alternative">
+            <xsl:call-template name="xxx880"/>
+            <title>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:call-template name="subfieldSelect">
+                            <xsl:with-param name="codes">ah</xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </title>
+            <xsl:call-template name="part"/>
+        </titleInfo>
+    </xsl:template>
+
+    <!-- name 100 110 111 1.93      -->
+
+    <xsl:template name="createNameFrom100">
+        <xsl:if test="@ind1='0' or @ind1='1'">
+            <name type="personal">
+                <xsl:attribute name="usage">
+                    <xsl:text>primary</xsl:text>
+                </xsl:attribute>
+                <xsl:call-template name="xxx880"/>
+                <!-- 1.123 Add nameTitleGroup attribute if necessary -->
+                <xsl:call-template name="nameTitleGroup"/>
+                <!-- 1.122 -->
+                <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+                <xsl:call-template name="nameABCDQ"/>
+                <xsl:call-template name="affiliation"/>
+                <xsl:call-template name="role"/>
+                <!-- 1.116 -->
+                <xsl:call-template name="nameIdentifier"/>
+            </name>
+        </xsl:if>
+        <!-- 1.99 240 fix 20140804 -->
+        <xsl:if test="@ind1='3'">
+            <name type="family">
+                <xsl:attribute name="usage">
+                    <xsl:text>primary</xsl:text>
+                </xsl:attribute>
+                <xsl:call-template name="xxx880"/>
+
+                <!-- 1.123 Add nameTitleGroup attribute if necessary -->
+                <xsl:call-template name="nameTitleGroup"/>
+                <xsl:call-template name="nameABCDQ"/>
+                <xsl:call-template name="affiliation"/>
+                <xsl:call-template name="role"/>
+                <!-- 1.116 -->
+                <xsl:call-template name="nameIdentifier"/>
+            </name>
+        </xsl:if>
+    </xsl:template>
+
+    <xsl:template name="createNameFrom110">
+        <name type="corporate">
+            <xsl:call-template name="xxx880"/>
+            <!-- 1.123 Add nameTitleGroup attribute if necessary -->
+            <xsl:call-template name="nameTitleGroup"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+            <xsl:call-template name="nameABCDN"/>
+            <xsl:call-template name="role"/>
+            <!-- 1.116 -->
+            <xsl:call-template name="nameIdentifier"/>
+        </name>
+    </xsl:template>
+
+
+    <!-- 111 1.104 20141104 -->
+
+    <xsl:template name="createNameFrom111">
+        <name type="conference">
+            <xsl:call-template name="xxx880"/>
+            <!-- 1.123 Add nameTitleGroup attribute if necessary -->
+            <xsl:call-template name="nameTitleGroup"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+            <xsl:call-template name="nameACDENQ"/>
+            <xsl:call-template name="role"/>
+            <!-- 1.116 -->
+            <xsl:call-template name="nameIdentifier"/>
+        </name>
+    </xsl:template>
+
+
+
+    <!-- name 700 710 711 720 -->
+
+    <xsl:template name="createNameFrom700">
+        <xsl:if test="@ind1='0'or @ind1='1'">
+            <name type="personal">
+                <xsl:call-template name="xxx880"/>
+                <!-- 1.123 Add nameTitleGroup attribute if necessary -->
+                <xsl:call-template name="nameTitleGroup"/>
+                <!-- 1.122 -->
+                <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+                <xsl:call-template name="nameABCDQ"/>
+                <xsl:call-template name="affiliation"/>
+                <xsl:call-template name="role"/>
+                <!-- 1.116 -->
+                <xsl:call-template name="nameIdentifier"/>
+            </name>
+        </xsl:if>
+        <xsl:if test="@ind1='3'">
+            <name type="family">
+                <xsl:call-template name="xxx880"/>
+                <xsl:call-template name="nameABCDQ"/>
+                <xsl:call-template name="affiliation"/>
+                <xsl:call-template name="role"/>
+                <!-- 1.116 -->
+                <xsl:call-template name="nameIdentifier"/>
+            </name>
+        </xsl:if>
+    </xsl:template>
+
+    <xsl:template name="createNameFrom710">
+        <name type="corporate">
+            <xsl:call-template name="xxx880"/>
+            <!-- 1.123 Add nameTitleGroup attribute if necessary -->
+            <xsl:call-template name="nameTitleGroup"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+            <xsl:call-template name="nameABCDN"/>
+            <xsl:call-template name="role"/>
+            <!-- 1.116 -->
+            <xsl:call-template name="nameIdentifier"/>
+        </name>
+    </xsl:template>
+
+<!-- 111 1.104 20141104 -->
+    <xsl:template name="createNameFrom711">
+        <name type="conference">
+            <xsl:call-template name="xxx880"/>
+            <!-- 1.123 Add nameTitleGroup attribute if necessary -->
+            <xsl:call-template name="nameTitleGroup"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>
+            <xsl:call-template name="nameACDENQ"/>
+            <xsl:call-template name="role"/>
+            <!-- 1.116 -->
+            <xsl:call-template name="nameIdentifier"/>
+        </name>
+    </xsl:template>
+
+
+    <xsl:template name="createNameFrom720">
+        <!-- 1.91 FLVC correction: the original if test will fail because of xpath: the current node (from the for-each above) is already the 720 datafield -->
+        <!-- <xsl:if test="marc:datafield[@tag='720'][not(marc:subfield[@code='t'])]"> -->
+        <xsl:if test="not(marc:subfield[@code='t'])">
+            <name>
+                <xsl:if test="@ind1=1">
+                    <xsl:attribute name="type">
+                        <xsl:text>personal</xsl:text>
+                    </xsl:attribute>
+                </xsl:if>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <namePart>
+                    <xsl:value-of select="marc:subfield[@code='a']"/>
+                </namePart>
+                <xsl:call-template name="role"/>
+            </name>
+        </xsl:if>
+    </xsl:template>
+
+
+
+    <!-- replced by above 1.91
+    <xsl:template name="createNameFrom720">
+        <xsl:if test="marc:datafield[@tag='720'][not(marc:subfield[@code='t'])]">
+            <name>
+                <xsl:if test="@ind1=1">
+                    <xsl:attribute name="type">
+                        <xsl:text>personal</xsl:text>
+                    </xsl:attribute>
+                </xsl:if>
+                <namePart>
+                    <xsl:value-of select="marc:subfield[@code='a']"/>
+                </namePart>
+                <xsl:call-template name="role"/>
+            </name>
+        </xsl:if>
+    </xsl:template>
+    -->
+
+
+    <!-- genre 047 336 655    -->
+
+    <xsl:template name="createGenreFrom047">
+        <genre authority="marcgt">
+            <!-- 1.111 -->
+            <xsl:choose>
+                <xsl:when test="@ind2 = ' '">
+                    <xsl:attribute name="authority"><xsl:text>marcmuscomp</xsl:text></xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind2 = '7'">
+                    <xsl:if test="marc:subfield[@code='2']">
+                        <xsl:attribute name="authority">
+                            <xsl:value-of select="marc:subfield[@code='2']"/>
+                        </xsl:attribute>
+                    </xsl:if>
+                </xsl:when>
+            </xsl:choose>
+            <xsl:attribute name="type">
+                <xsl:text>musical composition</xsl:text>
+            </xsl:attribute>
+            <!-- Template checks for altRepGroup - 880 $6 -->
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">abcdef</xsl:with-param>
+                <xsl:with-param name="delimeter">-</xsl:with-param>
+            </xsl:call-template>
+        </genre>
+    </xsl:template>
+
+    <xsl:template name="createGenreFrom336">
+        <genre>
+            <!-- 1.110 -->
+            <xsl:if test="marc:subfield[@code='2']">
+                <xsl:attribute name="authority">
+                    <xsl:value-of select="marc:subfield[@code='2']"/>
+                </xsl:attribute>
+            </xsl:if>
+            <!-- Template checks for altRepGroup - 880 $6 -->
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">a</xsl:with-param>
+                <xsl:with-param name="delimeter">-</xsl:with-param>
+            </xsl:call-template>
+        </genre>
+
+    </xsl:template>
+
+    <xsl:template name="createGenreFrom655">
+        <genre authority="marcgt">
+            <!-- 1.109 -->
+            <xsl:choose>
+                <xsl:when test="marc:subfield[@code='2']">
+                    <xsl:attribute name="authority">
+                        <xsl:value-of select="marc:subfield[@code='2']"/>
+                    </xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind2 != ' '">
+                    <xsl:attribute name="authority">
+                        <xsl:value-of select="@ind2"/>
+                    </xsl:attribute>
+                </xsl:when>
+            </xsl:choose>
+            <!-- Template checks for altRepGroup - 880 $6 -->
+            <xsl:call-template name="xxx880"/>
+            <!-- 1.132 <xsl:apply-templates select="marc:subfield[@code='0'][. != '']" mode="xlink"/>-->
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">abvxyz</xsl:with-param>
+                <xsl:with-param name="delimeter">-</xsl:with-param>
+            </xsl:call-template>
+        </genre>
+    </xsl:template>
+
+    <!-- tOC 505 -->
+
+    <xsl:template name="createTOCFrom505">
+        <tableOfContents>
+            <!-- 1.137 -->
+            <xsl:choose>
+                <xsl:when test="@ind1='0'">
+                    <xsl:attribute name="displayLabel">Contents</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1='1'">
+                    <xsl:attribute name="displayLabel">Incomplete contents</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1='2'">
+                    <xsl:attribute name="displayLabel">Partial contents</xsl:attribute>
+                </xsl:when>
+                <xsl:otherwise/>
+            </xsl:choose>
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">agrt</xsl:with-param>
+            </xsl:call-template>
+        </tableOfContents>
+    </xsl:template>
+
+    <!-- abstract 520 -->
+
+    <xsl:template name="createAbstractFrom520">
+        <abstract>
+            <!-- 1.124 -->
+            <xsl:choose>
+                <xsl:when test="@ind1='0'">
+                    <xsl:attribute name="displayLabel">Subject</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1='1'">
+                    <xsl:attribute name="displayLabel">Review</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1='2'">
+                    <xsl:attribute name="displayLabel">Scope and content</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1='3'">
+                    <xsl:attribute name="displayLabel">Abstract</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1='4'">
+                    <xsl:attribute name="displayLabel">Content advice</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1='8'"/>
+                <xsl:otherwise>
+                    <xsl:attribute name="displayLabel">Summary</xsl:attribute>
+                </xsl:otherwise>
+            </xsl:choose>
+
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">ab</xsl:with-param>
+            </xsl:call-template>
+
+        </abstract>
+    </xsl:template>
+
+    <!-- targetAudience 521 -->
+
+    <xsl:template name="createTargetAudienceFrom521">
+        <targetAudience>
+            <xsl:call-template name="xxx880"/>
+            <!-- 1.127 Add displayLabel attribute -->
+            <xsl:choose>
+                <xsl:when test="@ind1='0'">
+                    <xsl:attribute name="displayLabel">Reading grade level</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1='1'">
+                    <xsl:attribute name="displayLabel">Interest age level</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1='2'">
+                    <xsl:attribute name="displayLabel">Interest grade level</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1='3'">
+                    <xsl:attribute name="displayLabel">Special audience characteristics</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1='4'">
+                    <xsl:attribute name="displayLabel">Motivation or interest level</xsl:attribute>
+                </xsl:when>
+                <xsl:when test="@ind1 = ' '"><xsl:attribute name="displayLabel">Audience</xsl:attribute></xsl:when>
+                <xsl:when test="@ind1='8'"/>
+            </xsl:choose>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">ab</xsl:with-param>
+            </xsl:call-template>
+        </targetAudience>
+    </xsl:template>
+
+    <!-- note 245c thru 585 -->
+
+
+    <!-- 1.100 245c 20140804 -->
+    <xsl:template name="createNoteFrom245c">
+        <xsl:if test="marc:subfield[@code='c']">
+                <note type="statement of responsibility">
+                    <!-- 1.121 -->
+                    <xsl:call-template name="xxx880"/>
+                    <xsl:call-template name="subfieldSelect">
+                        <xsl:with-param name="codes">c</xsl:with-param>
+                    </xsl:call-template>
+                </note>
+        </xsl:if>
+
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom362">
+        <note type="date/sequential designation">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom500">
+        <note>
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <!-- 1.138 -->
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom502">
+        <note type="thesis">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom504">
+        <note type="bibliography">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom508">
+        <note type="creation/production credits">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='u' and @code!='3' and @code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom511">
+        <note type="performers">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom515">
+        <note type="numbering">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom518">
+        <note type="venue">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='3' and @code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom524">
+        <note type="preferred citation">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom530">
+        <note type="additional physical form">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='u' and @code!='3' and @code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom533">
+        <note type="reproduction">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <!-- tmee
+    <xsl:template name="createNoteFrom534">
+        <note type="original version">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+-->
+
+    <xsl:template name="createNoteFrom535">
+        <note type="original location">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom536">
+        <note type="funding">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom538">
+        <note type="system details">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom541">
+        <note type="acquisition">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom545">
+        <note type="biographical/historical">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom546">
+        <note type="language">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom561">
+        <note type="ownership">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom562">
+        <note type="version identification">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom581">
+        <note type="publications">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom583">
+        <note type="action">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom585">
+        <note type="exhibitions">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <xsl:template name="createNoteFrom5XX">
+        <note>
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="uri"/>
+            <xsl:variable name="str">
+                <xsl:for-each select="marc:subfield[@code!='6' and @code!='8']">
+                    <xsl:value-of select="."/>
+                    <xsl:text> </xsl:text>
+                </xsl:for-each>
+            </xsl:variable>
+            <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+        </note>
+    </xsl:template>
+
+    <!-- subject Geo 034 043 045 255 656 662 752 -->
+
+    <xsl:template name="createSubGeoFrom034">
+        <xsl:if test="marc:datafield[@tag=034][marc:subfield[@code='d' or @code='e' or @code='f' or @code='g']]">
+            <subject>
+                <xsl:call-template name="xxx880"/>
+                <cartographics>
+                    <coordinates>
+                        <xsl:call-template name="subfieldSelect">
+                            <xsl:with-param name="codes">defg</xsl:with-param>
+                        </xsl:call-template>
+                    </coordinates>
+                </cartographics>
+            </subject>
+        </xsl:if>
+    </xsl:template>
+
+    <xsl:template name="createSubGeoFrom043">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
+                <geographicCode>
+                    <xsl:attribute name="authority">
+                        <xsl:if test="@code='a'">
+                            <xsl:text>marcgac</xsl:text>
+                        </xsl:if>
+                        <xsl:if test="@code='b'">
+                            <xsl:value-of select="following-sibling::marc:subfield[@code=2]"/>
+                        </xsl:if>
+                        <xsl:if test="@code='c'">
+                            <xsl:text>iso3166</xsl:text>
+                        </xsl:if>
+                    </xsl:attribute>
+                    <xsl:value-of select="self::marc:subfield"/>
+                </geographicCode>
+            </xsl:for-each>
+        </subject>
+    </xsl:template>
+
+    <xsl:template name="createSubGeoFrom255">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <cartographics>
+            <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
+                    <xsl:if test="@code='a'">
+                        <scale>
+                            <xsl:value-of select="."/>
+                        </scale>
+                    </xsl:if>
+                    <xsl:if test="@code='b'">
+                        <projection>
+                            <xsl:value-of select="."/>
+                        </projection>
+                    </xsl:if>
+                    <xsl:if test="@code='c'">
+                        <coordinates>
+                            <xsl:value-of select="."/>
+                        </coordinates>
+                    </xsl:if>
+            </xsl:for-each>
+            </cartographics>
+        </subject>
+    </xsl:template>
+
+    <xsl:template name="createSubNameFrom600">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subjectAuthority"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0']" mode="xlink"/>
+            <name type="personal">
+                <namePart>
+                    <!-- 1.126 -->
+                            <xsl:call-template name="subfieldSelect">
+                                <xsl:with-param name="codes">aq</xsl:with-param>
+                            </xsl:call-template>
+                </namePart>
+                <xsl:call-template name="termsOfAddress"/>
+                <xsl:call-template name="nameDate"/>
+                <xsl:call-template name="affiliation"/>
+                <xsl:call-template name="role"/>
+            </name>
+            <xsl:if test="marc:subfield[@code='t']">
+                <titleInfo>
+                    <title>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="chopString">
+                                <xsl:call-template name="subfieldSelect">
+                                    <xsl:with-param name="codes">t</xsl:with-param>
+                                </xsl:call-template>
+                            </xsl:with-param>
+                        </xsl:call-template>
+                    </title>
+                    <xsl:call-template name="part"/>
+                </titleInfo>
+            </xsl:if>
+            <xsl:call-template name="subjectAnyOrder"/>
+        </subject>
+    </xsl:template>
+
+    <xsl:template name="createSubNameFrom610">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subjectAuthority"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0']" mode="xlink"/>
+            <name type="corporate">
+                <xsl:for-each select="marc:subfield[@code='a']">
+                    <namePart>
+                        <xsl:value-of select="."/>
+                    </namePart>
+                </xsl:for-each>
+                <xsl:for-each select="marc:subfield[@code='b']">
+                    <namePart>
+                        <xsl:value-of select="."/>
+                    </namePart>
+                </xsl:for-each>
+                <xsl:if test="marc:subfield[@code='c' or @code='d' or @code='n' or @code='p']">
+                    <namePart>
+                        <xsl:call-template name="subfieldSelect">
+                            <xsl:with-param name="codes">cdnp</xsl:with-param>
+                        </xsl:call-template>
+                    </namePart>
+                </xsl:if>
+                <xsl:call-template name="role"/>
+            </name>
+            <xsl:if test="marc:subfield[@code='t']">
+                <titleInfo>
+                    <title>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="chopString">
+                                <xsl:call-template name="subfieldSelect">
+                                    <xsl:with-param name="codes">t</xsl:with-param>
+                                </xsl:call-template>
+                            </xsl:with-param>
+                        </xsl:call-template>
+                    </title>
+                    <xsl:call-template name="part"/>
+                </titleInfo>
+            </xsl:if>
+            <xsl:call-template name="subjectAnyOrder"/>
+        </subject>
+    </xsl:template>
+
+    <xsl:template name="createSubNameFrom611">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subjectAuthority"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0']" mode="xlink"/>
+            <name type="conference">
+                <namePart>
+                    <xsl:call-template name="subfieldSelect">
+                        <xsl:with-param name="codes">abcdeqnp</xsl:with-param>
+                    </xsl:call-template>
+                </namePart>
+                <xsl:for-each select="marc:subfield[@code='4']">
+                    <role>
+                        <roleTerm authority="marcrelator" type="code">
+                            <xsl:value-of select="."/>
+                        </roleTerm>
+                    </role>
+                </xsl:for-each>
+            </name>
+            <xsl:if test="marc:subfield[@code='t']">
+                <titleInfo>
+                    <title>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="chopString">
+                                <xsl:call-template name="subfieldSelect">
+                                    <xsl:with-param name="codes">tpn</xsl:with-param>
+                                </xsl:call-template>
+                            </xsl:with-param>
+                        </xsl:call-template>
+                    </title>
+                    <xsl:call-template name="part"/>
+                </titleInfo>
+            </xsl:if>
+            <xsl:call-template name="subjectAnyOrder"/>
+        </subject>
+    </xsl:template>
+
+    <xsl:template name="createSubTitleFrom630">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subjectAuthority"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0']" mode="xlink"/>
+            <titleInfo>
+                <title>
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString">
+                            <xsl:call-template name="subfieldSelect">
+                                <xsl:with-param name="codes">adfhklor</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </title>
+                <xsl:call-template name="part"/>
+            </titleInfo>
+            <xsl:call-template name="subjectAnyOrder"/>
+        </subject>
+    </xsl:template>
+
+    <xsl:template name="createSubChronFrom648">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <xsl:if test="marc:subfield[@code=2]">
+                <xsl:attribute name="authority">
+                    <xsl:value-of select="marc:subfield[@code=2]"/>
+                </xsl:attribute>
+            </xsl:if>
+            <xsl:call-template name="uri"/>
+            <xsl:call-template name="subjectAuthority"/>
+            <temporal>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:call-template name="subfieldSelect">
+                            <xsl:with-param name="codes">abcd</xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </temporal>
+            <xsl:call-template name="subjectAnyOrder"/>
+        </subject>
+    </xsl:template>
+
+    <xsl:template name="createSubTopFrom650">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subjectAuthority"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0']" mode="xlink"/>
+            <topic>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:call-template name="subfieldSelect">
+                            <xsl:with-param name="codes">abcd</xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </topic>
+            <xsl:call-template name="subjectAnyOrder"/>
+        </subject>
+    </xsl:template>
+
+    <xsl:template name="createSubGeoFrom651">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subjectAuthority"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0']" mode="xlink"/>
+            <xsl:for-each select="marc:subfield[@code='a']">
+                <geographic>
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString" select="."/>
+                    </xsl:call-template>
+                </geographic>
+            </xsl:for-each>
+            <xsl:call-template name="subjectAnyOrder"/>
+        </subject>
+    </xsl:template>
+
+    <xsl:template name="createSubFrom653">
+
+        <xsl:if test="@ind2=' '">
+            <subject>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <topic>
+                    <xsl:value-of select="."/>
+                </topic>
+            </subject>
+        </xsl:if>
+        <xsl:if test="@ind2='0'">
+            <subject>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <topic>
+                    <xsl:value-of select="."/>
+                </topic>
+            </subject>
+        </xsl:if>
+<!-- tmee 1.93 20140130 -->
+        <xsl:if test="@ind=' ' or @ind1='0' or @ind1='1'">
+            <subject>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <name type="personal">
+                    <namePart>
+                        <xsl:value-of select="."/>
+                    </namePart>
+                </name>
+            </subject>
+        </xsl:if>
+        <xsl:if test="@ind1='3'">
+            <subject>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <name type="family">
+                    <namePart>
+                        <xsl:value-of select="."/>
+                    </namePart>
+                </name>
+            </subject>
+        </xsl:if>
+        <xsl:if test="@ind2='2'">
+            <subject>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <name type="corporate">
+                    <namePart>
+                        <xsl:value-of select="."/>
+                    </namePart>
+                </name>
+            </subject>
+        </xsl:if>
+        <xsl:if test="@ind2='3'">
+            <subject>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <name type="conference">
+                    <namePart>
+                        <xsl:value-of select="."/>
+                    </namePart>
+                </name>
+            </subject>
+        </xsl:if>
+        <xsl:if test="@ind2=4">
+            <subject>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <temporal>
+                    <xsl:value-of select="."/>
+                </temporal>
+            </subject>
+        </xsl:if>
+        <xsl:if test="@ind2=5">
+            <subject>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <geographic>
+                    <xsl:value-of select="."/>
+                </geographic>
+            </subject>
+        </xsl:if>
+
+        <xsl:if test="@ind2=6">
+            <subject>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <genre>
+                    <xsl:value-of select="."/>
+                </genre>
+            </subject>
+        </xsl:if>
+    </xsl:template>
+
+    <xsl:template name="createSubFrom656">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0']" mode="xlink"/>
+            <xsl:if test="marc:subfield[@code=2]">
+                <xsl:attribute name="authority">
+                    <xsl:value-of select="marc:subfield[@code=2]"/>
+                </xsl:attribute>
+            </xsl:if>
+            <occupation>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="marc:subfield[@code='a']"/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </occupation>
+        </subject>
+    </xsl:template>
+
+    <xsl:template name="createSubGeoFrom662752">
+        <subject>
+            <xsl:call-template name="xxx880"/>
+            <!-- 1.122 -->
+            <xsl:apply-templates select="marc:subfield[@code='0']" mode="xlink"/>
+            <hierarchicalGeographic>
+                <!-- 1.113 -->
+                <xsl:if test="marc:subfield[@code='0']">
+                    <xsl:attribute name="valueURI"><xsl:value-of select="marc:subfield[@code='0']"/></xsl:attribute>
+                </xsl:if>
+                <xsl:for-each select="marc:subfield[@code='a']">
+                    <country>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="chopString" select="."/>
+                        </xsl:call-template>
+                    </country>
+                </xsl:for-each>
+                <xsl:for-each select="marc:subfield[@code='b']">
+                    <state>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="chopString" select="."/>
+                        </xsl:call-template>
+                    </state>
+                </xsl:for-each>
+                <xsl:for-each select="marc:subfield[@code='c']">
+                    <county>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="chopString" select="."/>
+                        </xsl:call-template>
+                    </county>
+                </xsl:for-each>
+                <xsl:for-each select="marc:subfield[@code='d']">
+                    <city>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="chopString" select="."/>
+                        </xsl:call-template>
+                    </city>
+                </xsl:for-each>
+                <xsl:for-each select="marc:subfield[@code='e']">
+                    <citySection>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="chopString" select="."/>
+                        </xsl:call-template>
+                    </citySection>
+                </xsl:for-each>
+                <xsl:for-each select="marc:subfield[@code='g']">
+                    <area>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="chopString" select="."/>
+                        </xsl:call-template>
+                    </area>
+                </xsl:for-each>
+                <xsl:for-each select="marc:subfield[@code='h']">
+                    <extraterrestrialArea>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="chopString" select="."/>
+                        </xsl:call-template>
+                    </extraterrestrialArea>
+                </xsl:for-each>
+            </hierarchicalGeographic>
+        </subject>
+    </xsl:template>
+
+    <xsl:template name="createSubTemFrom045">
+        <xsl:if test="//marc:datafield[@tag=045 and @ind1='2'][marc:subfield[@code='b' or @code='c']]">
+            <subject>
+                <xsl:call-template name="xxx880"/>
+                <temporal encoding="iso8601" point="start">
+                    <xsl:call-template name="dates045b">
+                        <xsl:with-param name="str" select="marc:subfield[@code='b' or @code='c'][1]"/>
+                    </xsl:call-template>
+                </temporal>
+                <temporal encoding="iso8601" point="end">
+                    <xsl:call-template name="dates045b">
+                        <xsl:with-param name="str" select="marc:subfield[@code='b' or @code='c'][2]"/>
+                    </xsl:call-template>
+                </temporal>
+            </subject>
+        </xsl:if>
+    </xsl:template>
+
+    <!-- classification 050 060 080 082 084 086 -->
+
+    <xsl:template name="createClassificationFrom050">
+        <xsl:for-each select="marc:subfield[@code='b']">
+            <classification authority="lcc">
+                <xsl:call-template name="xxx880"/>
+                <xsl:if test="../marc:subfield[@code='3']">
+                    <xsl:attribute name="displayLabel">
+                        <xsl:value-of select="../marc:subfield[@code='3']"/>
+                    </xsl:attribute>
+                </xsl:if>
+                <xsl:value-of select="preceding-sibling::marc:subfield[@code='a'][1]"/>
+                <xsl:text> </xsl:text>
+                <xsl:value-of select="text()"/>
+            </classification>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='a'][not(following-sibling::marc:subfield[@code='b'])]">
+            <classification authority="lcc">
+                <xsl:call-template name="xxx880"/>
+                <xsl:if test="../marc:subfield[@code='3']">
+                    <xsl:attribute name="displayLabel">
+                        <xsl:value-of select="../marc:subfield[@code='3']"/>
+                    </xsl:attribute>
+                </xsl:if>
+                <xsl:value-of select="text()"/>
+            </classification>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="createClassificationFrom060">
+        <classification authority="nlm">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">ab</xsl:with-param>
+            </xsl:call-template>
+        </classification>
+    </xsl:template>
+    <xsl:template name="createClassificationFrom080">
+        <classification authority="udc">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">abx</xsl:with-param>
+            </xsl:call-template>
+        </classification>
+    </xsl:template>
+    <xsl:template name="createClassificationFrom082">
+        <classification authority="ddc">
+            <xsl:call-template name="xxx880"/>
+            <xsl:if test="marc:subfield[@code='2']">
+                <xsl:attribute name="edition">
+                    <xsl:value-of select="marc:subfield[@code='2']"/>
+                </xsl:attribute>
+            </xsl:if>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">ab</xsl:with-param>
+            </xsl:call-template>
+        </classification>
+    </xsl:template>
+    <xsl:template name="createClassificationFrom084">
+        <classification>
+            <xsl:attribute name="authority">
+                <xsl:value-of select="marc:subfield[@code='2']"/>
+            </xsl:attribute>
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">ab</xsl:with-param>
+            </xsl:call-template>
+        </classification>
+    </xsl:template>
+    <xsl:template name="createClassificationFrom086">
+        <xsl:for-each select="marc:datafield[@tag=086][@ind1=0]">
+            <classification authority="sudocs">
+                <xsl:call-template name="xxx880"/>
+                <xsl:value-of select="marc:subfield[@code='a']"/>
+            </classification>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag=086][@ind1=1]">
+            <classification authority="candoc">
+                <xsl:call-template name="xxx880"/>
+                <xsl:value-of select="marc:subfield[@code='a']"/>
+            </classification>
+        </xsl:for-each>
+        <xsl:for-each select="marc:datafield[@tag=086][@ind1!=1 and @ind1!=0]">
+            <classification>
+                <xsl:call-template name="xxx880"/>
+                <xsl:attribute name="authority">
+                    <xsl:value-of select="marc:subfield[@code='2']"/>
+                </xsl:attribute>
+                <xsl:value-of select="marc:subfield[@code='a']"/>
+            </classification>
+        </xsl:for-each>
+    </xsl:template>
+
+    <!-- identifier 020 024 022 028 010 037 UNDO Nov 23 2010 RG SM-->
+
+    <!-- createRelatedItemFrom490 <xsl:for-each select="marc:datafield[@tag=490][@ind1=0]"> -->
+
+    <xsl:template name="createRelatedItemFrom490">
+        <xsl:variable name="s6" select="substring(normalize-space(marc:subfield[@code='6']), 5, 2)"/>
+        <!-- 1.121 -->
+        <xsl:if test="@tag=490 or (@tag='880' and not(../marc:datafield[@tag='490'][@ind1='0' or @ind1=' '][substring(marc:subfield[@code='6'],5,2) = $s6]))">
+        <relatedItem type="series">
+            <xsl:for-each
+                select=". | ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'490')][substring(marc:subfield[@code='6'],5,2) = $s6]">
+                <titleInfo>
+                    <xsl:call-template name="xxx880"/>
+                    <title>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="chopString">
+                                <xsl:call-template name="subfieldSelect">
+                                    <xsl:with-param name="codes">a</xsl:with-param>
+                                </xsl:call-template>
+                            </xsl:with-param>
+                        </xsl:call-template>
+                    </title>
+                    <!-- 1.120 - @490$v -->
+                    <xsl:if test="marc:subfield[@code='v']">
+                        <partNumber>
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString">
+                                    <xsl:call-template name="subfieldSelect">
+                                        <xsl:with-param name="codes">v</xsl:with-param>
+                                    </xsl:call-template>
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </partNumber>
+                    </xsl:if>
+                </titleInfo>
+            </xsl:for-each>
+        </relatedItem>
+        </xsl:if>
+    </xsl:template>
+
+
+    <!-- location 852 856 -->
+
+    <xsl:template name="createLocationFrom852">
+        <location>
+            <!-- 1.121 -->
+            <xsl:call-template name="xxx880"/>
+            <xsl:if test="marc:subfield[@code='a' or @code='b' or @code='e']">
+                <physicalLocation>
+                    <xsl:call-template name="subfieldSelect">
+                        <xsl:with-param name="codes">abe</xsl:with-param>
+                    </xsl:call-template>
+                </physicalLocation>
+            </xsl:if>
+            <xsl:if test="marc:subfield[@code='u']">
+                <physicalLocation>
+                    <xsl:call-template name="uri"/>
+                    <xsl:call-template name="subfieldSelect">
+                        <xsl:with-param name="codes">u</xsl:with-param>
+                    </xsl:call-template>
+                </physicalLocation>
+            </xsl:if>
+            <!-- 1.78 -->
+            <xsl:if test="marc:subfield[@code='h' or @code='i' or @code='j' or @code='k' or @code='l' or @code='m' or @code='t']">
+                <shelfLocator>
+                    <xsl:call-template name="subfieldSelect">
+                        <xsl:with-param name="codes">hijklmt</xsl:with-param>
+                    </xsl:call-template>
+                </shelfLocator>
+            </xsl:if>
+            <!-- 1.114 -->
+            <xsl:if test="marc:subfield[@code='p' or @code='t']">
+                <holdingSimple>
+                    <copyInformation>
+                        <xsl:for-each select="marc:subfield[@code='p']|marc:subfield[@code='t']">
+                            <itemIdentifier>
+                                <xsl:if test="@code='t'">
+                                    <xsl:attribute name="type"><xsl:text>copy number</xsl:text></xsl:attribute>
+                                </xsl:if>
+                                <xsl:apply-templates select="."/>
+                            </itemIdentifier>
+                        </xsl:for-each>
+                    </copyInformation>
+                </holdingSimple>
+            </xsl:if>
+        </location>
+    </xsl:template>
+
+    <xsl:template name="createLocationFrom856">
+        <xsl:if test="//marc:datafield[@tag=856][@ind2!=2][marc:subfield[@code='u']]">
+            <location>
+                <!-- 1.121 -->
+                <xsl:call-template name="xxx880"/>
+                <url displayLabel="electronic resource">
+                    <!-- 1.41 tmee AQ1.9 added choice protocol for @usage="primary display" -->
+                    <xsl:variable name="primary">
+                        <xsl:choose>
+                            <xsl:when test="@ind2=0 and count(preceding-sibling::marc:datafield[@tag=856] [@ind2=0])=0">true</xsl:when>
+
+                            <xsl:when test="@ind2=1 and count(ancestor::marc:record//marc:datafield[@tag=856][@ind2=0])=0 and         count(preceding-sibling::marc:datafield[@tag=856][@ind2=1])=0">true</xsl:when>
+
+                            <xsl:when test="@ind2!=1 and @ind2!=0 and         @ind2!=2 and count(ancestor::marc:record//marc:datafield[@tag=856 and         @ind2=0])=0 and count(ancestor::marc:record//marc:datafield[@tag=856 and         @ind2=1])=0 and         count(preceding-sibling::marc:datafield[@tag=856][@ind2])=0">true</xsl:when>
+                            <xsl:otherwise>false</xsl:otherwise>
+                        </xsl:choose>
+                    </xsl:variable>
+                    <xsl:if test="$primary='true'">
+                        <xsl:attribute name="usage">primary display</xsl:attribute>
+                    </xsl:if>
+
+                    <xsl:if test="marc:subfield[@code='y' or @code='3']">
+                        <xsl:attribute name="displayLabel">
+                            <xsl:call-template name="subfieldSelect">
+                                <xsl:with-param name="codes">y3</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:attribute>
+                    </xsl:if>
+                    <xsl:if test="marc:subfield[@code='z']">
+                        <xsl:attribute name="note">
+                            <xsl:call-template name="subfieldSelect">
+                                <xsl:with-param name="codes">z</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:attribute>
+                    </xsl:if>
+                    <xsl:value-of select="marc:subfield[@code='u']"/>
+                </url>
+            </location>
+        </xsl:if>
+    </xsl:template>
+
+    <!-- accessCondition 506 540 1.87 20130829-->
+
+    <xsl:template name="createAccessConditionFrom506">
+        <accessCondition type="restriction on access">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">abcd35</xsl:with-param>
+            </xsl:call-template>
+        </accessCondition>
+    </xsl:template>
+
+    <xsl:template name="createAccessConditionFrom540">
+        <accessCondition type="use and reproduction">
+            <xsl:call-template name="xxx880"/>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">abcde35</xsl:with-param>
+            </xsl:call-template>
+        </accessCondition>
+    </xsl:template>
+
+    <!-- recordInfo 040 005 001 003 -->
+
+    <!-- 880 global copy template -->
+    <xsl:template match="* | @*" mode="global_copy">
+        <xsl:copy>
+            <xsl:apply-templates select="* | @* | text()" mode="global_copy"/>
+        </xsl:copy>
+    </xsl:template>
+
+    <!-- 1.24 rules for applying nameTitleGroup attribute -->
+    <xsl:template name="nameTitleGroup">
+        <xsl:choose>
+            <xsl:when test="self::marc:datafield[@tag='240']">
+                <xsl:choose>
+                    <xsl:when test="../marc:datafield[@tag='100' or @tag='110' or @tag='111']">
+                        <xsl:attribute name="nameTitleGroup">1</xsl:attribute>
+                    </xsl:when>
+                    <xsl:otherwise/>
+                </xsl:choose>
+            </xsl:when>
+            <xsl:when
+                test="self::marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'240')]">
+                <xsl:choose>
+                    <xsl:when
+                        test="../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'100')] or
+                        ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'110')] or
+                        ../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'111')]">
+                        <xsl:attribute name="nameTitleGroup">
+                            <xsl:value-of
+                                select="count(preceding-sibling::marc:datafield[@tag='700' or @tag='710' or @tag='711' or @tag='880']) + 2"
+                            />
+                        </xsl:attribute>
+                    </xsl:when>
+                    <xsl:otherwise/>
+                </xsl:choose>
+            </xsl:when>
+            <xsl:when test="self::marc:datafield[@tag='100' or @tag='110' or @tag='111']">
+                <xsl:choose>
+                    <xsl:when test="../marc:datafield[@tag='240']">
+                        <xsl:attribute name="nameTitleGroup">1</xsl:attribute>
+                    </xsl:when>
+                    <xsl:otherwise/>
+                </xsl:choose>
+            </xsl:when>
+            <xsl:when
+                test="(self::marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'100')]
+                or self::marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'110')]
+                or self::marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'111')])">
+                <xsl:choose>
+                    <xsl:when
+                        test="../marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'240')]">
+                        <xsl:attribute name="nameTitleGroup">
+                            <xsl:value-of
+                                select="count(preceding-sibling::marc:datafield[@tag='700' or @tag='710' or @tag='711' or @tag='880']) + 2"
+                            />
+                        </xsl:attribute>
+                    </xsl:when>
+                    <xsl:otherwise/>
+                </xsl:choose>
+            </xsl:when>
+            <xsl:when test="self::marc:datafield[@tag='700' or @tag='710' or @tag='711']">
+                <xsl:choose>
+                    <xsl:when test="child::marc:subfield[@code='t']">
+                        <xsl:attribute name="nameTitleGroup">
+                            <xsl:value-of
+                                select="count(preceding-sibling::marc:datafield[@tag='700' or @tag='710' or @tag='711' or @tag='880']) + 2"
+                            />
+                        </xsl:attribute>
+                    </xsl:when>
+                    <xsl:otherwise/>
+                </xsl:choose>
+            </xsl:when>
+            <xsl:when
+                test="self::marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'100')]
+                | self::marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'110')]
+                | self::marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'111')] "/>
+            <xsl:when
+                test="self::marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'700')][not(marc:subfield[@code='t'])]"/>
+            <xsl:when
+                test="self::marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'710')][not(marc:subfield[@code='t'])]"/>
+            <xsl:when
+                test="self::marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'711')][not(marc:subfield[@code='t'])]"/>
+            <xsl:otherwise>
+                <xsl:attribute name="nameTitleGroup">
+                    <xsl:value-of
+                        select="count(preceding-sibling::marc:datafield[@tag='700' or @tag='710' or @tag='711' or @tag='880']) + 2"
+                    />
+                </xsl:attribute>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <!-- 1.129 add physicalDescription templates-->
+    <!-- Templates used to build physicalDescription element -->
+    <!-- 300 extent -->
+    <xsl:template
+        match="marc:datafield[@tag='300'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'300')]"
+        mode="physDesc">
+        <extent>
+            <!-- 3.5 2.18 20142011 -->
+            <xsl:if test="marc:subfield[@code='f']"><xsl:attribute name="unit">
+                <xsl:call-template name="subfieldSelect">
+                    <xsl:with-param name="codes">f</xsl:with-param>
+                </xsl:call-template>
+            </xsl:attribute></xsl:if>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">abce3g</xsl:with-param>
+            </xsl:call-template>
+        </extent>
+    </xsl:template>
+    <!-- 351 note-->
+    <xsl:template match="marc:datafield[@tag='351']" mode="physDesc">
+        <note type="arrangement">
+            <xsl:for-each select="marc:subfield[@code='3']">
+                <xsl:apply-templates/>
+                <xsl:text>: </xsl:text>
+            </xsl:for-each>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">abc</xsl:with-param>
+            </xsl:call-template>
+        </note>
+    </xsl:template>
+    <!-- 856 internetMediaType -->
+    <xsl:template
+        match="marc:datafield[@tag='856']/marc:subfield[@code='q'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'856')]/child::*[code='q']"
+        mode="physDesc">
+        <xsl:if test="string-length(.)&gt;1">
+            <internetMediaType>
+                <xsl:apply-templates/>
+            </internetMediaType>
+        </xsl:if>
+    </xsl:template>
+
+    <xsl:template name="reformattingQuality">
+        <xsl:for-each select="marc:controlfield[@tag='007'][substring(text(),1,1)='c']">
+            <xsl:choose>
+                <xsl:when test="substring(text(),14,1)='a'">
+                    <reformattingQuality>access</reformattingQuality>
+                </xsl:when>
+                <xsl:when test="substring(text(),14,1)='p'">
+                    <reformattingQuality>preservation</reformattingQuality>
+                </xsl:when>
+                <xsl:when test="substring(text(),14,1)='r'">
+                    <reformattingQuality>replacement</reformattingQuality>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template name="digitalOrigin">
+        <xsl:param name="typeOf008"/>
+        <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag='007'][substring(.,12,1)='a']">
+            <digitalOrigin>reformatted digital</digitalOrigin>
+        </xsl:if>
+        <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag='007'][substring(.,12,1)='b']">
+            <digitalOrigin>digitized microfilm</digitalOrigin>
+        </xsl:if>
+        <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag='007'][substring(.,12,1)='d']">
+            <digitalOrigin>digitized other analog</digitalOrigin>
+        </xsl:if>
+    </xsl:template>
+    <xsl:template name="form">
+        <xsl:param name="controlField008"/>
+        <xsl:param name="typeOf008"/>
+        <xsl:param name="leader6"/>
+        <!-- Variables used for caculating form element from controlfields -->
+        <xsl:variable name="controlField008-23" select="substring($controlField008,24,1)"/>
+        <xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"/>
+        <xsl:variable name="check008-23">
+            <xsl:if test="$typeOf008='BK' or $typeOf008='MU' or $typeOf008='SE' or $typeOf008='MM'">
+                <xsl:value-of select="true()"/>
+            </xsl:if>
+        </xsl:variable>
+        <xsl:variable name="check008-29">
+            <xsl:if test="$typeOf008='MP' or $typeOf008='VM'">
+                <xsl:value-of select="true()"/>
+            </xsl:if>
+        </xsl:variable>
+        <xsl:choose>
+            <xsl:when
+                test="($check008-23 and $controlField008-23='f') or ($check008-29 and $controlField008-29='f')">
+                <form authority="marcform">braille</form>
+            </xsl:when>
+            <xsl:when
+                test="($controlField008-23=' ' and ($leader6='c' or $leader6='d')) or (($typeOf008='BK' or $typeOf008='SE') and ($controlField008-23=' ' or $controlField008='r'))">
+                <form authority="marcform">print</form>
+            </xsl:when>
+            <xsl:when
+                test="$leader6 = 'm' or ($check008-23 and $controlField008-23='s') or ($check008-29 and $controlField008-29='s')">
+                <form authority="marcform">electronic</form>
+            </xsl:when>
+            <xsl:when test="$leader6 = 'o'">
+                <form authority="marcform">kit</form>
+            </xsl:when>
+            <xsl:when
+                test="($check008-23 and $controlField008-23='b') or ($check008-29 and $controlField008-29='b')">
+                <form authority="marcform">microfiche</form>
+            </xsl:when>
+            <xsl:when
+                test="($check008-23 and $controlField008-23='a') or ($check008-29 and $controlField008-29='a')">
+                <form authority="marcform">microfilm</form>
+            </xsl:when>
+        </xsl:choose>
+
+        <!-- Form element generated from controlfield 007 -->
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='c']">
+            <form authority="marccategory">electronic resource</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='c'][substring(text(),2,1)='b']">
+            <form authority="marcsmd">chip cartridge</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='c'][substring(text(),2,1)='c']">
+            <form authority="marcsmd">computer optical disc cartridge</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='c'][substring(text(),2,1)='j']">
+            <form authority="marcsmd">magnetic disc</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='c'][substring(text(),2,1)='m']">
+            <form authority="marcsmd">magneto-optical disc</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='c'][substring(text(),2,1)='o']">
+            <form authority="marcsmd">optical disc</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='c'][substring(text(),2,1)='r']">
+            <form authority="marcsmd">remote</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='c'][substring(text(),2,1)='a']">
+            <form authority="marcsmd">tape cartridge</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='c'][substring(text(),2,1)='f']">
+            <form authority="marcsmd">tape cassette</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='c'][substring(text(),2,1)='h']">
+            <form authority="marcsmd">tape reel</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='d']">
+            <form authority="marccategory">globe</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='d'][substring(text(),2,1)='a']">
+            <form authority="marcsmd">celestial globe</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='d'][substring(text(),2,1)='e']">
+            <form authority="marcsmd">earth moon globe</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='d'][substring(text(),2,1)='b']">
+            <form authority="marcsmd">planetary or lunar globe</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='d'][substring(text(),2,1)='c']">
+            <form authority="marcsmd">terrestrial globe</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='o']">
+            <form authority="marccategory">kit</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='o'][substring(text(),2,1)='o']">
+            <form authority="marcsmd">kit</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='a']">
+            <form authority="marccategory">map</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
+            <form authority="marcsmd">atlas</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='g']">
+            <form authority="marcsmd">diagram</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='j']">
+            <form authority="marcsmd">map</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
+            <form authority="marcsmd">model</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='k']">
+            <form authority="marcsmd">profile</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
+            <form authority="marcsmd">remote-sensing image</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='s']">
+            <form authority="marcsmd">section</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='y']">
+            <form authority="marcsmd">view</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='h']">
+            <form authority="marccategory">microform</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='h'][substring(text(),2,1)='a']">
+            <form authority="marcsmd">aperture card</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='h'][substring(text(),2,1)='e']">
+            <form authority="marcsmd">microfiche</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='h'][substring(text(),2,1)='f']">
+            <form authority="marcsmd">microfiche cassette</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='h'][substring(text(),2,1)='b']">
+            <form authority="marcsmd">microfilm cartridge</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='h'][substring(text(),2,1)='c']">
+            <form authority="marcsmd">microfilm cassette</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='h'][substring(text(),2,1)='d']">
+            <form authority="marcsmd">microfilm reel</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='h'][substring(text(),2,1)='g']">
+            <form authority="marcsmd">microopaque</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='m']">
+            <form authority="marccategory">motion picture</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='m'][substring(text(),2,1)='c']">
+            <form authority="marcsmd">film cartridge</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='m'][substring(text(),2,1)='f']">
+            <form authority="marcsmd">film cassette</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='m'][substring(text(),2,1)='r']">
+            <form authority="marcsmd">film reel</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='k']">
+            <form authority="marccategory">nonprojected graphic</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='k'][substring(text(),2,1)='n']">
+            <form authority="marcsmd">chart</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='k'][substring(text(),2,1)='c']">
+            <form authority="marcsmd">collage</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='k'][substring(text(),2,1)='d']">
+            <form authority="marcsmd">drawing</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='k'][substring(text(),2,1)='o']">
+            <form authority="marcsmd">flash card</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='k'][substring(text(),2,1)='e']">
+            <form authority="marcsmd">painting</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='k'][substring(text(),2,1)='f']">
+            <form authority="marcsmd">photomechanical print</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='k'][substring(text(),2,1)='g']">
+            <form authority="marcsmd">photonegative</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='k'][substring(text(),2,1)='h']">
+            <form authority="marcsmd">photoprint</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='k'][substring(text(),2,1)='i']">
+            <form authority="marcsmd">picture</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='k'][substring(text(),2,1)='j']">
+            <form authority="marcsmd">print</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='k'][substring(text(),2,1)='l']">
+            <form authority="marcsmd">technical drawing</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='q']">
+            <form authority="marccategory">notated music</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='q'][substring(text(),2,1)='q']">
+            <form authority="marcsmd">notated music</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='g']">
+            <form authority="marccategory">projected graphic</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='g'][substring(text(),2,1)='d']">
+            <form authority="marcsmd">filmslip</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='g'][substring(text(),2,1)='c']">
+            <form authority="marcsmd">filmstrip cartridge</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='g'][substring(text(),2,1)='o']">
+            <form authority="marcsmd">filmstrip roll</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='g'][substring(text(),2,1)='f']">
+            <form authority="marcsmd">other filmstrip type</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='g'][substring(text(),2,1)='s']">
+            <form authority="marcsmd">slide</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='g'][substring(text(),2,1)='t']">
+            <form authority="marcsmd">transparency</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='r']">
+            <form authority="marccategory">remote-sensing image</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='r'][substring(text(),2,1)='r']">
+            <form authority="marcsmd">remote-sensing image</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='s']">
+            <form authority="marccategory">sound recording</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='s'][substring(text(),2,1)='e']">
+            <form authority="marcsmd">cylinder</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='s'][substring(text(),2,1)='q']">
+            <form authority="marcsmd">roll</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='s'][substring(text(),2,1)='g']">
+            <form authority="marcsmd">sound cartridge</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='s'][substring(text(),2,1)='s']">
+            <form authority="marcsmd">sound cassette</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='s'][substring(text(),2,1)='d']">
+            <form authority="marcsmd">sound disc</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='s'][substring(text(),2,1)='t']">
+            <form authority="marcsmd">sound-tape reel</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='s'][substring(text(),2,1)='i']">
+            <form authority="marcsmd">sound-track film</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='s'][substring(text(),2,1)='w']">
+            <form authority="marcsmd">wire recording</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='f']">
+            <form authority="marccategory">tactile material</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='f'][substring(text(),2,1)='c']">
+            <form authority="marcsmd">braille</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='f'][substring(text(),2,1)='b']">
+            <form authority="marcsmd">combination</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='f'][substring(text(),2,1)='a']">
+            <form authority="marcsmd">moon</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='f'][substring(text(),2,1)='d']">
+            <form authority="marcsmd">tactile, with no writing system</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='t']">
+            <form authority="marccategory">text</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='t'][substring(text(),2,1)='c']">
+            <form authority="marcsmd">braille</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='t'][substring(text(),2,1)='b']">
+            <form authority="marcsmd">large print</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='t'][substring(text(),2,1)='a']">
+            <form authority="marcsmd">regular print</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='t'][substring(text(),2,1)='d']">
+            <form authority="marcsmd">text in looseleaf binder</form>
+        </xsl:if>
+        <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='v']">
+            <form authority="marccategory">videorecording</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='v'][substring(text(),2,1)='c']">
+            <form authority="marcsmd">videocartridge</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='v'][substring(text(),2,1)='f']">
+            <form authority="marcsmd">videocassette</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='v'][substring(text(),2,1)='d']">
+            <form authority="marcsmd">videodisc</form>
+        </xsl:if>
+        <xsl:if
+            test="marc:controlfield[@tag='007'][substring(text(),1,1)='v'][substring(text(),2,1)='r']">
+            <form authority="marcsmd">videoreel</form>
+        </xsl:if>
+    </xsl:template>
+    <!-- 130, 240, 242, 245, 246, 256 246, 730 form elements for physical description -->
+    <!-- Form element generated from 130, 240, 242, 245, 246,730 and 256 datafields -->
+    <xsl:template
+        match="marc:datafield[@tag='130']/marc:subfield[@code='h']
+        | marc:datafield[@tag='240']/marc:subfield[@code='h'] | marc:datafield[@tag='242']/marc:subfield[@code='h']
+        | marc:datafield[@tag='245']/marc:subfield[@code='h'] | marc:datafield[@tag='246']/marc:subfield[@code='h']
+        | marc:datafield[@tag='730']/marc:subfield[@code='h'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'130')]/marc:subfield[@code='h']
+        | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'240')]/marc:subfield[@code='h']
+        | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'242')]/marc:subfield[@code='h']
+        | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'245')]/marc:subfield[@code='h']
+        | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'246')]/marc:subfield[@code='h']
+        | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'730')]/marc:subfield[@code='h']"
+        mode="physDesc">
+        <form authority="gmd">
+            <xsl:variable name="str">
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="."/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </xsl:variable>
+            <xsl:call-template name="chopBrackets">
+                <xsl:with-param name="chopString">
+                    <xsl:value-of select="$str"/>
+                </xsl:with-param>
+            </xsl:call-template>
+        </form>
+    </xsl:template>
+    <xsl:template
+        match="marc:datafield[@tag='337']/marc:subfield[@code='a'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'337')]/marc:subfield[@code='a']"
+        mode="physDesc">
+        <form>
+            <xsl:attribute name="type">
+                <xsl:text>media</xsl:text>
+            </xsl:attribute>
+            <xsl:attribute name="authority">
+                <xsl:value-of select="../marc:subfield[@code='2']"/>
+            </xsl:attribute>
+            <xsl:apply-templates/>
+        </form>
+    </xsl:template>
+    <xsl:template
+        match="marc:datafield[@tag='338']/marc:subfield[@code='a'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'338')]/marc:subfield[@code='a']"
+        mode="physDesc">
+        <form>
+            <xsl:attribute name="type">
+                <xsl:text>carrier</xsl:text>
+            </xsl:attribute>
+            <xsl:attribute name="authority">
+                <xsl:value-of select="../marc:subfield[@code='2']"/>
+            </xsl:attribute>
+            <xsl:apply-templates/>
+        </form>
+    </xsl:template>
+    <xsl:template
+        match="marc:datafield[@tag='256']/marc:subfield[@code='a'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'256')]/marc:subfield[@code='a']"
+        mode="physDesc">
+        <form>
+            <xsl:apply-templates/>
+        </form>
+    </xsl:template>
+
+    <xsl:template name="originInfo">
+        <!-- Leader and control field parameters passed from record template -->
+        <xsl:param name="leader6"/>
+        <xsl:param name="leader7"/>
+        <xsl:param name="leader19"/>
+        <xsl:param name="controlField008"/>
+        <xsl:param name="typeOf008"/>
+        <xsl:variable name="dataField260c">
+            <xsl:call-template name="chopPunctuation">
+                <xsl:with-param name="chopString" select="marc:datafield[@tag=260]/marc:subfield[@code='c']"/>
+            </xsl:call-template>
+        </xsl:variable>
+        <xsl:variable name="originInfoShared">
+            <xsl:variable name="MARCpublicationCode" select="normalize-space(substring($controlField008,16,3))"/>
+            <xsl:if test="translate($MARCpublicationCode,'|','')">
+                <place>
+                    <placeTerm>
+                        <xsl:attribute name="type">code</xsl:attribute>
+                        <xsl:attribute name="authority">marccountry</xsl:attribute>
+                        <xsl:value-of select="$MARCpublicationCode"/>
+                    </placeTerm>
+                </place>
+            </xsl:if>
+            <xsl:variable name="controlField008-7-10" select="normalize-space(substring($controlField008, 8, 4))"/>
+            <xsl:variable name="controlField008-11-14" select="normalize-space(substring($controlField008, 12, 4))"/>
+            <xsl:variable name="controlField008-6" select="normalize-space(substring($controlField008, 7, 1))"/>
+            <xsl:if test="($controlField008-6='e' or $controlField008-6='p' or $controlField008-6='r' or $controlField008-6='s' or $controlField008-6='t') and ($leader6='d' or $leader6='f' or $leader6='p' or $leader6='t')">
+                <xsl:if test="$controlField008-7-10 and ($controlField008-7-10 != $dataField260c)">
+                    <dateCreated encoding="marc">
+                        <xsl:value-of select="$controlField008-7-10"/>
+                    </dateCreated>
+                </xsl:if>
+            </xsl:if>
+            <xsl:if test="($controlField008-6='e' or $controlField008-6='p' or $controlField008-6='r' or $controlField008-6='s' or $controlField008-6='t') and not($leader6='d' or $leader6='f' or $leader6='p' or $leader6='t')">
+                <xsl:if test="$controlField008-7-10 and ($controlField008-7-10 != $dataField260c)">
+                    <dateIssued encoding="marc">
+                        <xsl:value-of select="$controlField008-7-10"/></dateIssued>
+                </xsl:if>
+            </xsl:if>
+            <xsl:if test="$controlField008-6='c' or $controlField008-6='d' or $controlField008-6='i' or $controlField008-6='k' or $controlField008-6='m' or $controlField008-6='u'">
+                <xsl:if test="$controlField008-7-10">
+                    <dateIssued encoding="marc" point="start">
+                        <xsl:value-of select="$controlField008-7-10"/>
+                    </dateIssued>
+                </xsl:if>
+            </xsl:if>
+            <xsl:if test="$controlField008-6='c' or $controlField008-6='d' or $controlField008-6='i' or $controlField008-6='k' or $controlField008-6='m' or $controlField008-6='u'">
+                <xsl:if test="$controlField008-11-14">
+                    <dateIssued encoding="marc" point="end">
+                        <xsl:value-of select="$controlField008-11-14"/>
+                    </dateIssued>
+                </xsl:if>
+            </xsl:if>
+            <xsl:if test="$controlField008-6='q'">
+                <xsl:if test="$controlField008-7-10">
+                    <dateIssued encoding="marc" point="start" qualifier="questionable">
+                        <xsl:value-of select="$controlField008-7-10"/>
+                    </dateIssued>
+                </xsl:if>
+            </xsl:if>
+            <xsl:if test="$controlField008-6='q'">
+                <xsl:if test="$controlField008-11-14">
+                    <dateIssued encoding="marc" point="end" qualifier="questionable">
+                        <xsl:value-of select="$controlField008-11-14"/>
+                    </dateIssued>
+                </xsl:if>
+            </xsl:if>
+            <xsl:if test="$controlField008-6='t'">
+                <xsl:if test="$controlField008-11-14">
+                    <copyrightDate encoding="marc">
+                        <xsl:value-of select="$controlField008-11-14"/>
+                    </copyrightDate>
+                </xsl:if>
+            </xsl:if>
+            <xsl:for-each select="marc:leader">
+                <!-- 1.120 - @260$issuance -->
+                <xsl:if test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m' or $leader7='b'
+                    or ($leader7='m' and ($leader19='a' or $leader19='b' or $leader19='c'))
+                    or ($leader7='m' and ($leader19=' ')) or $leader7='m' and ($leader19='#') or $leader7='i' or $leader7='s'">
+                    <issuance>
+                        <xsl:choose>
+                            <xsl:when test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'">monographic</xsl:when>
+                            <xsl:when test="$leader7='m' and ($leader19='a' or $leader19='b' or $leader19='c')">multipart monograph</xsl:when>
+                            <!-- 1.106 20141218 -->
+                            <xsl:when test="$leader7='m' and ($leader19=' ')">single unit</xsl:when>
+                            <xsl:when test="$leader7='m' and ($leader19='#')">single unit</xsl:when>
+                            <xsl:when test="$leader7='i'">integrating resource</xsl:when>
+                            <xsl:when test="$leader7='b' or $leader7='s'">serial</xsl:when>
+                        </xsl:choose>
+                    </issuance>
+                </xsl:if>
+            </xsl:for-each>
+            <xsl:if test="$typeOf008='SE'">
+                <xsl:for-each select="marc:controlfield[@tag=008]">
+                    <xsl:variable name="controlField008-18" select="substring($controlField008,19,1)"/>
+                    <xsl:variable name="frequency">
+                        <frequency>
+                            <xsl:choose>
+                                <xsl:when test="$controlField008-18='a'">Annual</xsl:when>
+                                <xsl:when test="$controlField008-18='b'">Bimonthly</xsl:when>
+                                <xsl:when test="$controlField008-18='c'">Semiweekly</xsl:when>
+                                <xsl:when test="$controlField008-18='d'">Daily</xsl:when>
+                                <xsl:when test="$controlField008-18='e'">Biweekly</xsl:when>
+                                <xsl:when test="$controlField008-18='f'">Semiannual</xsl:when>
+                                <xsl:when test="$controlField008-18='g'">Biennial</xsl:when>
+                                <xsl:when test="$controlField008-18='h'">Triennial</xsl:when>
+                                <xsl:when test="$controlField008-18='i'">Three times a week</xsl:when>
+                                <xsl:when test="$controlField008-18='j'">Three times a month</xsl:when>
+                                <xsl:when test="$controlField008-18='k'">Continuously updated</xsl:when>
+                                <xsl:when test="$controlField008-18='m'">Monthly</xsl:when>
+                                <xsl:when test="$controlField008-18='q'">Quarterly</xsl:when>
+                                <xsl:when test="$controlField008-18='s'">Semimonthly</xsl:when>
+                                <xsl:when test="$controlField008-18='t'">Three times a year</xsl:when>
+                                <xsl:when test="$controlField008-18='u'">Unknown</xsl:when>
+                                <xsl:when test="$controlField008-18='w'">Weekly</xsl:when>
+                                <!-- 1.106 20141218 -->
+                                <xsl:when test="$controlField008-18=' '">Completely irregular</xsl:when>
+                                <xsl:when test="$controlField008-18='#'">Completely irregular</xsl:when>
+                                <xsl:otherwise/>
+                            </xsl:choose>
+                        </frequency>
+                    </xsl:variable>
+                    <xsl:if test="$frequency!=''">
+                        <frequency authority="marcfrequency">
+                            <xsl:value-of select="$frequency"/>
+                        </frequency>
+                    </xsl:if>
+                </xsl:for-each>
+            </xsl:if>
+        </xsl:variable>
+        <!-- Build main originInfo element -->
+        <xsl:choose>
+            <xsl:when test="marc:datafield[@tag='044' or @tag='260' or @tag='046' or @tag='033' or @tag='250' or @tag='310' or @tag='321'][marc:subfield[@code='6']]">
+                <xsl:for-each select="marc:datafield[@tag='044' or @tag='260' or @tag='046' or @tag='033' or @tag='250' or @tag='310' or @tag='321'][marc:subfield[@code='6']]">
+                    <originInfo>
+                        <xsl:choose>
+                            <xsl:when test="self::marc:subfield"><xsl:call-template name="xxs880"/></xsl:when>
+                            <xsl:when test="self::marc:datafield"><xsl:call-template name="xxx880"/></xsl:when>
+                        </xsl:choose>
+                        <xsl:copy-of select="$originInfoShared"/>
+                        <xsl:choose>
+                            <xsl:when test="@tag='260'">
+                                <xsl:apply-templates select="." mode="originInfo">
+                                    <xsl:with-param name="leader6" select="$leader6"/>
+                                </xsl:apply-templates>
+                            </xsl:when>
+                            <xsl:when test="@tag='033'">
+                                <xsl:apply-templates select="." mode="originInfo">
+                                    <xsl:with-param name="leader6" select="$leader6"/>
+                                </xsl:apply-templates>
+                            </xsl:when>
+                            <xsl:otherwise><xsl:apply-templates select="." mode="originInfo"/></xsl:otherwise>
+                        </xsl:choose>
+                    </originInfo>
+                </xsl:for-each>
+                <xsl:if
+                    test="marc:datafield[@tag='044' or @tag='260' or @tag='046' or @tag='033' or @tag='250' or @tag='310' or @tag='321'][not(marc:subfield[@code='6'])]">
+                    <originInfo>
+                        <xsl:copy-of select="$originInfoShared"/>
+                        <xsl:for-each select="marc:datafield[@tag='044' or @tag='260' or @tag='046' or @tag='033' or @tag='250' or @tag='310' or @tag='321'][not(marc:subfield[@code='6'])]">
+                            <xsl:choose>
+                                <xsl:when test="@tag='260'">
+                                    <xsl:apply-templates select="." mode="originInfo">
+                                        <xsl:with-param name="leader6" select="$leader6"/>
+                                    </xsl:apply-templates>
+                                </xsl:when>
+                                <xsl:when test="@tag='033'">
+                                    <xsl:apply-templates select="." mode="originInfo">
+                                        <xsl:with-param name="leader6" select="$leader6"/>
+                                    </xsl:apply-templates>
+                                </xsl:when>
+                                <xsl:otherwise><xsl:apply-templates select="." mode="originInfo"/></xsl:otherwise>
+                            </xsl:choose>
+                        </xsl:for-each>
+                    </originInfo>
+                </xsl:if>
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:if
+                    test="marc:datafield[@tag='044' or @tag='260' or @tag='046' or @tag='033' or @tag='250' or @tag='310' or @tag='321'] or marc:controlfield[@tag='008']">
+                    <originInfo>
+                        <xsl:call-template name="z2xx880"/>
+                        <xsl:copy-of select="$originInfoShared"/>
+                        <xsl:apply-templates select="marc:datafield[@tag='044']/marc:subfield[@code='c']" mode="originInfo"/>
+                        <xsl:apply-templates select="marc:datafield[@tag='260']" mode="originInfo">
+                            <xsl:with-param name="leader6" select="$leader6"/>
+                        </xsl:apply-templates>
+                        <!-- Build date elements -->
+                        <xsl:apply-templates select="marc:datafield[@tag='046']" mode="originInfo"/>
+                        <xsl:apply-templates select="marc:datafield[@tag='033']" mode="originInfo">
+                            <xsl:with-param name="leader6" select="$leader6"/>
+                        </xsl:apply-templates>
+                        <!-- Build edition element -->
+                        <xsl:apply-templates select="marc:datafield[@tag='250']" mode="originInfo"/>
+                        <!-- Build frequency element -->
+                        <xsl:apply-templates select="marc:datafield[@tag='310']|marc:datafield[@tag='321']"
+                            mode="originInfo"/>
+                    </originInfo>
+                </xsl:if>
+            </xsl:otherwise>
+        </xsl:choose>
+        <!-- if linking fields add an additional originInfo field -->
+        <xsl:for-each
+            select="marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'260')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'250')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'044')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'046')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'033')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'310')]
+            | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'321')]">
+            <originInfo>
+                <xsl:choose>
+                    <xsl:when test="self::marc:subfield"><xsl:call-template name="xxs880"/></xsl:when>
+                    <xsl:when test="self::marc:datafield"><xsl:call-template name="xxx880"/></xsl:when>
+                </xsl:choose>
+                <xsl:copy-of select="$originInfoShared"/>
+                <xsl:choose>
+                    <xsl:when test="@tag='260'">
+                        <xsl:apply-templates select="." mode="originInfo">
+                            <xsl:with-param name="leader6" select="$leader6"/>
+                        </xsl:apply-templates>
+                    </xsl:when>
+                    <xsl:when test="@tag='033'">
+                        <xsl:apply-templates select="." mode="originInfo">
+                            <xsl:with-param name="leader6" select="$leader6"/>
+                        </xsl:apply-templates>
+                    </xsl:when>
+                    <xsl:otherwise><xsl:apply-templates select="." mode="originInfo"/></xsl:otherwise>
+                </xsl:choose>
+            </originInfo>
+        </xsl:for-each>
+    </xsl:template>
+    <!-- 1.130 originInfo subfields-->
+    <!-- @880$6 -->
+    <xsl:template match="marc:subfield[@code='6']" mode="originInfo"/>
+    <!-- originInfo place 044 -->
+    <xsl:template
+        match="marc:datafield[@tag='044'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'044')]"
+        mode="originInfo">
+        <xsl:for-each select="marc:subfield[@code='c']">
+            <place>
+                <placeTerm>
+                    <xsl:attribute name="type">code</xsl:attribute>
+                    <xsl:attribute name="authority">iso3166</xsl:attribute>
+                    <xsl:call-template name="chopPunctuationFront">
+                        <xsl:with-param name="chopString">
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString" select="."/>
+                            </xsl:call-template>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </placeTerm>
+            </place>
+        </xsl:for-each>
+    </xsl:template>
+    <!-- originInfo place and date 260 -->
+    <xsl:template
+        match="marc:datafield[@tag='260'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'260')]"
+        mode="originInfo">
+        <xsl:param name="leader6"/>
+        <xsl:for-each select="marc:subfield[@code='a']">
+            <place>
+                <placeTerm>
+                    <xsl:attribute name="type">text</xsl:attribute>
+                    <xsl:call-template name="chopPunctuationFront">
+                        <xsl:with-param name="chopString">
+                            <xsl:call-template name="chopPunctuation">
+                                <xsl:with-param name="chopString" select="."/>
+                            </xsl:call-template>
+                        </xsl:with-param>
+                    </xsl:call-template>
+                </placeTerm>
+            </place>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='b']">
+            <publisher>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString" select="."/>
+                    <xsl:with-param name="punctuation">
+                        <xsl:text>:,;/ </xsl:text>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </publisher>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='c']">
+            <xsl:if test="$leader6='d' or $leader6='f' or $leader6='p' or $leader6='t'">
+                <dateCreated>
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString" select="."/>
+                    </xsl:call-template>
+                </dateCreated>
+            </xsl:if>
+            <xsl:if test="not($leader6='d' or $leader6='f' or $leader6='p' or $leader6='t')">
+                <dateIssued>
+                    <xsl:call-template name="chopPunctuation">
+                        <xsl:with-param name="chopString" select="."/>
+                    </xsl:call-template>
+                </dateIssued>
+            </xsl:if>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='g']">
+            <xsl:if test="$leader6='d' or $leader6='f' or $leader6='p' or $leader6='t'">
+                <dateCreated>
+                    <xsl:value-of select="."/>
+                </dateCreated>
+            </xsl:if>
+            <xsl:if test="not($leader6='d' or $leader6='f' or $leader6='p' or $leader6='t')">
+                <dateCreated>
+                    <xsl:value-of select="."/>
+                </dateCreated>
+            </xsl:if>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template
+        match="marc:datafield[@tag='046'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'046')]"
+        mode="originInfo">
+        <xsl:for-each select="marc:subfield[@code='m']">
+            <dateValid point="start">
+                <xsl:value-of select="."/>
+            </dateValid>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='n']">
+            <dateValid point="end">
+                <xsl:value-of select="."/>
+            </dateValid>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='j']">
+            <dateModified>
+                <xsl:value-of select="."/>
+            </dateModified>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='c']">
+            <dateIssued encoding="marc" point="start">
+                <xsl:value-of select="."/>
+            </dateIssued>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='e']">
+            <dateIssued encoding="marc" point="end">
+                <xsl:value-of select="."/>
+            </dateIssued>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='k']">
+            <dateCreated encoding="marc" point="start">
+                <xsl:value-of select="."/>
+            </dateCreated>
+        </xsl:for-each>
+        <xsl:for-each select="marc:subfield[@code='l']">
+            <dateCreated encoding="marc" point="end">
+                <xsl:value-of select="."/>
+            </dateCreated>
+        </xsl:for-each>
+    </xsl:template>
+    <xsl:template
+        match="marc:datafield[@tag='033'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'033')]"
+        mode="originInfo">
+        <xsl:for-each select="self::*[@ind1=0 or @ind1=1]/marc:subfield[@code='a']">
+            <dateCaptured encoding="iso8601">
+                <xsl:value-of select="."/>
+            </dateCaptured>
+        </xsl:for-each>
+        <xsl:for-each select="self::*[@ind1=2]/marc:subfield[@code='a'][1]">
+            <dateCaptured encoding="iso8601" point="start">
+                <xsl:value-of select="."/>
+            </dateCaptured>
+        </xsl:for-each>
+        <xsl:for-each select="self::*[@ind1=2]/marc:subfield[@code='a'][2]">
+            <dateCaptured encoding="iso8601" point="end">
+                <xsl:value-of select="."/>
+            </dateCaptured>
+        </xsl:for-each>
+    </xsl:template>
+    <!-- originInfo edition -->
+    <xsl:template
+        match="marc:datafield[@tag='250'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'250')]"
+        mode="originInfo">
+        <xsl:for-each select="marc:subfield[@code='a']">
+            <edition>
+                <xsl:apply-templates/>
+            </edition>
+        </xsl:for-each>
+    </xsl:template>
+    <!-- originInfo frequency -->
+    <xsl:template
+        match="marc:datafield[@tag='310']|marc:datafield[@tag='321'] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'310')] | marc:datafield[@tag='880'][starts-with(marc:subfield[@code='6'],'321')]"
+        mode="originInfo">
+        <frequency>
+            <xsl:call-template name="subfieldSelect">
+                <xsl:with-param name="codes">ab</xsl:with-param>
+            </xsl:call-template>
+        </frequency>
+    </xsl:template>
+
+
+</xsl:stylesheet>
+MARC21SLIM2MODS36
+            }
+            write_file($marc_mods_path, $xsl);
+            my $xsl_modified = $xsl;
+            my $marc_utils_path = check_marc21_utility($xsl_dir, $ua);
+            $xsl_modified =~ s#$marc_utils_url#$marc_utils_path#g;
+            say "Saving MARC21->MODS xsl to file '$marc_mods_path'";
+            write_file($marc_mods_patched_path, $xsl_modified);
+        }
+        return $marc_mods_patched_path;
+    }
+
+    sub patch_marc_response($){
+        if(! defined $_[0]) { croak "marcobject not defined!"; }
+        if($_[0] eq ""){ die "invalid parameters."; }
+
+        my $marcobj           = shift; # marcobj expected as XML Parser object
+        my $xslt_patch_string = <<'PATCH2';
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.loc.gov/MARC21/slim" xmlns:srw="http://www.loc.gov/zing/srw/"
+    exclude-result-prefixes="srw" version="1.0">
+    <xsl:template match="/record">
+        <xsl:element name="collection">
+            <xsl:element name="record" namespace="http://www.loc.gov/MARC21/slim">
+                <xsl:apply-templates select="@*"/>
+                <xsl:apply-templates select="node()"/>
+            </xsl:element>
+        </xsl:element>
+    </xsl:template>
+    <xsl:template match="*">
+        <xsl:element name="{local-name()}" namespace="http://www.loc.gov/MARC21/slim">
+            <xsl:apply-templates select="node() | @*"/>
+        </xsl:element>
+    </xsl:template>
+    <xsl:template match="@*">
+        <xsl:attribute name="{local-name()}">
+            <xsl:value-of select="."/>
+        </xsl:attribute>
+    </xsl:template>
+</xsl:stylesheet>
+PATCH2
+        my $xslt       = XML::LibXSLT->new();
+        my $xslt_patch = XML::LibXML->load_xml(string => $xslt_patch_string, no_cdata => 1);
+        my $stylesheet = $xslt->parse_stylesheet($xslt_patch);
+        my $result     = $stylesheet->transform($marcobj);
+
+        return $result;
+    }
+
+    sub patch_mods($){
+        # this will patch the mods-xml as a workaround for bugs in LOCs xslt files
+        if(! defined $_[0]) { croak "modsobject not defined!"; }
+        if($_[0] eq ""){ die "invalid parameters."; }
+
+        my $modsobj = shift; # mods expected as XML Parser object
+        # TODO: Bugfix for /mets:mets/mets:dmdSec[1]/mets:mdWrap[1]/mets:xmlData[1]/mods:modsCollection[1]/mods:mods[1]/mods:relatedItem[2]/mods:internetMediaType[1]
+        my $xslt_patch_string = <<'PATCH';
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xmlns:mods="http://www.loc.gov/mods/v3"
+    xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd"
+    exclude-result-prefixes="xs"
+    version="1.0">
+    <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
+    <xsl:strip-space elements="*"/>
+    <xsl:template match="//mods:mods/mods:relatedItem[mods:internetMediaType]">
+        <xsl:comment>patched wrong //mods:mods/mods:relatedItem[mods:internetMediaType]</xsl:comment>
+    </xsl:template>
+    <xsl:template match="@* | node()">
+        <xsl:copy>
+            <xsl:apply-templates select="@* | node()"/>
+        </xsl:copy>
+    </xsl:template>
+</xsl:stylesheet>
+PATCH
+        my $xslt       = XML::LibXSLT->new();
+        my $xslt_patch = XML::LibXML->load_xml(string => $xslt_patch_string, no_cdata => 1);
+        my $stylesheet = $xslt->parse_stylesheet($xslt_patch);
+        my $result     = $stylesheet->transform($modsobj);
+
+        return $result;
+    }
+
+    # new functions
+    sub create_slub_bagit($$){
+        if(! defined $_[0]) { croak "ie_path is not defined!"; }
+        if(! defined $_[1]) { croak "array of hashes not defined for bag-info.txt!"; }
+        if(! -d $_[0]) { croak "path is not directory!" }
+
+        my $ie_path       = $_[0];
+        my $refAddBagInfo = $_[1];    # ref to array of hashes
+
+        #p($refAddBagInfo);
+
+        # construct bag
+        my $oArchiveBagIt = Archive::BagIt::Base->make_bag($ie_path);    # returns object->bag_info(arrayOfHashes); object->store
+        $oArchiveBagIt->bag_info($refAddBagInfo);
+        $oArchiveBagIt->store();
+        my $res = $oArchiveBagIt->verify_bag();
+        return $res;
+    }
+
+    sub print_scalar_data($$$$){
+        my $priority = 0;
+        my $header   = $_[0];
+        my $p        = $_[1];
+        my $arrRef   = $_[2];
+        my $pColor   = $_[3];
+
+        # header
+        if($header ne ""){
+            print "----------------------------------------------------------------------------------\n" if $priority >= $VERBOSE;
+            printf "%" . length($header) . "s\n", colored($header, 'bold green') if $priority >= $VERBOSE;
+            print "----------------------------------------------------------------------------------\n" if $priority >= $VERBOSE;
+        }
+        # paragraph
+        if(($p ne "") && ($arrRef eq "")){
+            printf "%" . length($p) . "s\n", colored($p, "bold $pColor") if $priority >= $VERBOSE;
+        }
+
+        # paragraph with converted array
+        if(($p ne "") && ($arrRef ne "")){
+            my $string = "";
+            for my $i (0 .. $#$arrRef){
+                if($i eq $#$arrRef){
+                    $string .= " $$arrRef[$i]";
+                } else {
+                    $string .= " $$arrRef[$i],";
+                }
+            }
+            my $body = $p . $string;
+            printf "%" . length($body) . "s\n", colored($body, "bold $pColor") if $priority >= $VERBOSE;
+        }
+        return;
+    }
+
+    sub getBagItName($){
+        if(! defined $_[0]) { croak "path for getting bagit name is not defined!"; }
+        if(! -d $_[0]) { croak "path is not directory!" }
+        my $bagit_name = $_[0];
+
+        # grep last directory from a path
+        if ($bagit_name =~ m/([^\/]+)$/){
+            $bagit_name = $1;
+        }
+        return $bagit_name;
+    }
+
+    sub getFileName($){
+        if(! defined $_[0]) { croak "path with file name is not defined!"; }
+        if($_[0] eq ""){ croak "invalid parameters!"; }
+        my $file_name = $_[0];
+
+        # grep last directory from a path
+        if ($file_name =~ m/([^\/]+)$/){
+            $file_name = $1;
+        }
+
+        return $file_name;
+    }
+
+    sub save_option($$$$){
+        if(! defined $_[0]) { croak "save option not defined!"; }
+        if(! defined $_[1]) { croak "IE directory path not defined!"; }
+        if(! defined $_[2] && $_[0] eq "copy") { croak "output path not defined!"; }
+        if(! defined $_[2] && $_[0] eq "move") { croak "output path not defined!"; }
+        if(! defined $_[3]) { croak "sip root dir is not defined!"; }
+
+        my $save      = $_[0];
+        my $directory = path($_[1]);
+        my $output    = path($_[2]);
+        my $bagNewDir = $_[3];
+
+        if($save eq "replace"){
+            # bag created on the same place where IE_directory under new name
+            my $bagNewPath = $directory->parent;
+            my $newdirectory = $bagNewPath->child($bagNewDir);
+            return $directory->move( $newdirectory );
+        } elsif($save eq "copy"){
+            my $newdirectory = $output->child($bagNewDir);
+            dircopy ($directory, $newdirectory); # Path::Tiny->copy() does not support dircopy recursively
+            return $newdirectory;
+        } elsif($save eq "move"){
+            my $newdirectory = $output->child($bagNewDir);
+            return $directory->move($newdirectory);
+        }
+        return;
+    }
+
+    sub getPayloadFiles($){
+        if(! defined $_[0]) { croak "path is not defined!"; }
+        my $import_dir = $_[0];
+        my @dirs;
+        # check if dir exists
+        if(! -d $import_dir) {
+            confess "ERROR: $import_dir does not exist!";
+        } else {
+            opendir(my $DIR, $import_dir) or die $!;
+            while (my $dir_name = readdir($DIR)) {
+                # A file test to check that it is a directory
+                #next unless (-d $import_dir);
+                next if $dir_name eq '.';
+                next if $dir_name eq '..';
+                # fill array with directory names
+                push @dirs, $dir_name;
+            }
+            closedir($DIR);
+        }
+        return @dirs;
+    }
+
+    sub validateRightsXML($$){
+        if(! defined $_[0]) { croak "ie_path to rights.xsd not defined!"; }
+        if(! defined $_[1]) { croak "file name not defined!"; }
+
+        my $ie_path    = $_[0];
+        my $rightsName = $_[1];
+
+        my $xsd_file = path(__FILE__)->parent->realpath->parent->child("xsd")->child("rights1.xsd");    # absolute path
+        my $xml_file = $ie_path . '/meta/' . $rightsName;
+
+        my $schema = XML::LibXML::Schema->new(location => $xsd_file);
+        my $parser = XML::LibXML->new;
+        my $doc    = $parser->parse_file($xml_file);
+
+        my $success = try { $schema->validate($doc); 1 } catch {};
+        if ($success) {
+            return 1;
+        } else {
+            die "File rights.xml failed validation: $@";
+        };
+        return;
+    }
+
+
+    # end package
+
+package main;
+#===============================================================================
+
+BEGIN{
+    ## no critic
+    $INC{'SLUB/LZA/SIPBuilderBagIt.pm'} = 1; # needed because inlined module
+    ## use critic
+}
+return 1 if caller;         # avoids main code running if module stuff is needed
+
+use SLUB::LZA::SIPBuilderBagIt;
+use DateTime::Format::ISO8601;
+use Getopt::Long;
+use Path::Tiny;
+use Carp;                     # confess()
+use Data::Printer;              # p()
+use Term::ANSIColor;         # colored print
+use Pod::Usage;                 # pod2usage()
+use File::Copy;
+use File::Copy::Recursive;      # for dirmove()
+
+my $save;
+my $ieDirectory;
+my $outputPath;
+#
+my $ppn;
+my $noppn;
+# bag-info data
+my $sipVersion;
+my $externalWorkflow;
+my $externalId;
+my $externalIsilId = "";
+my $exportToArchiveDate = DateTime->now(time_zone=>'local')->iso8601();
+my $hasConservationReason;
+my $archivalValueDescription;
+my $rightsVersion;
+my @addKeyValue;
+#
+my @addBagInfo;    # array of hashes
+# not payload files
+my $rightsFilePath;
+my @addMetaFile;
+# extra
+my $help;
+my $man;
+
+GetOptions(
+    "save_option:s"                 => \$save,                                       # required
+    "IE_directory:s"                => \$ieDirectory,                              # required
+    "SIP_output_path:s"             => \$outputPath,                             # required, but by save=replace can be ignored
+    "ppn:s"                         => \$ppn,                                    # semi-optional (choice 1 of 2)
+    "noppn:s"                       => \$noppn,                                  # semi-optional (choice 2 of 2)
+    # bag-info data
+    "SIP_version:s"                 => \$sipVersion,                             # required
+    "external_workflow:s"           => \$externalWorkflow,                           # required
+    "external_id:s"                 => \$externalId,                                # required
+    "external_ISIL:s"               => \$externalIsilId,                          # optional, default: no ISIL
+    "external_conservation_flag"    => \$hasConservationReason,                     # optional, default: no special conservation
+    "external_value_descr:s"        => \$archivalValueDescription,               # required
+    "rights_version:s"                => \$rightsVersion,                               # required
+    # not payload files
+    "rights_xml:s"                    => \$rightsFilePath,                           # required
+    "add_meta_file:s"               => \@addMetaFile,                             # optional
+    "add_key_value:s"               => \@addKeyValue,                             # optional
+    # extra
+    "debug"                         => \$SLUB::LZA::SIPBuilderBagIt::with_debug, # optional
+    "help|?"                        => \$help,                                   # optional
+    "man"                           => \$man,                                    # optional
+) or pod2usage(2);
+
+# help
+if ($help)                                  { pod2usage(1); }
+#man
+if ($man)                                   { pod2usage(-exitval => 0, -verbose => 2); }
+# save
+if (!defined $save || $save eq "") { confess("you need to specify a --save_option, available <replace> or <copy> or <move>"); }
+# ieDirectory
+if (!defined $ieDirectory || $ieDirectory eq "") { confess("you need to specify an --IE_directory, which needs to be archived"); }
+if (! -d $ieDirectory)                           { confess("you need to specify a valid --IE_directory, status: is not a directory"); }
+# outputPath
+if (!defined $outputPath && ($save eq "copy" || $save eq "move")) {
+    confess("you need to specify an --SIP_output_path, where the SIP will be stored");
+}
+if (defined $outputPath && $outputPath eq "" && ($save eq "copy" || $save eq "move")) {
+    confess("you need to specify an --SIP_output_path, where the SIP will be stored");
+}
+# ppn, noppn
+if (defined $ppn && defined $noppn)   { confess("you can only specify either --ppn or --noppn"); }
+if ((!defined $ppn && !defined $noppn) || (!defined $ppn && $noppn eq "") || (!defined $noppn && $ppn eq "")) { confess("you need to specify a PPN with --ppn or use --noppn"); }
+#########################################################>  bag-info.txt  <###############################################################################
+# sipversion
+if (!defined $sipVersion || $sipVersion eq "") {
+    confess("you need to specify --SIP_version, current tool supports <v2020.1>");
+} else {
+    if ($sipVersion ne "v2020.1") { confess("not valid --SIP_version, current tool supports <v2020.1>"); }
+    utf8::decode($sipVersion);
+    push @addBagInfo, {'SLUBArchiv-sipVersion' => $sipVersion};
+}
+# externalWorkflow
+if (!defined $externalWorkflow || $externalWorkflow eq "") {
+    confess("you need to specify external workflow");
+} else {
+    if ($externalWorkflow !~ m#^[a-z0-9_-]+$#) { confess("you need to specify a valid --external_workflow (^[a-z0-9_-]+\$)"); }
+    utf8::decode($externalWorkflow);
+    push @addBagInfo, {'SLUBArchiv-externalWorkflow' => $externalWorkflow};
+}
+# externalId
+if (!defined $externalId || $externalId eq "") {
+    confess("you need to specify external ID");
+} else {
+    if ($externalId !~ m#^[a-z0-9_-]+$#) { confess("you need to specify a valid --external_id (^[a-z0-9_-]+\$)"); }
+    utf8::decode($externalId);
+    push @addBagInfo, {'SLUBArchiv-externalId' => $externalId};
+}
+# externalIsilId
+if (defined $externalIsilId && $externalIsilId ne "") {
+    utf8::decode($externalIsilId);
+    push @addBagInfo, {'SLUBArchiv-externalIsilId' => $externalIsilId};
+}
+# exportToArchiveDate
+utf8::decode($exportToArchiveDate);
+push @addBagInfo, {'SLUBArchiv-exportToArchiveDate' => $exportToArchiveDate};
+# hasConservationReason
+if (!defined $hasConservationReason) {
+    $hasConservationReason = "false";
+} else {
+    $hasConservationReason = "true";
+}
+utf8::decode($hasConservationReason);
+push @addBagInfo, {'SLUBArchiv-hasConservationReason' => $hasConservationReason};
+# archivalValueDescription
+if (!defined $archivalValueDescription || $archivalValueDescription eq "") {
+    confess("you need to specify an --external_value_descr (reason for archiving)");
+} else {
+    utf8::decode($archivalValueDescription);
+    push @addBagInfo, {'SLUBArchiv-archivalValueDescription' => $archivalValueDescription};
+}
+# rightsVersion
+if (!defined $rightsVersion || $rightsVersion eq "") {
+    confess("you need to specify --rights_version");
+} else {
+    if($rightsVersion ne "1.0") { confess("invalid --rights_version, supported version <1.0>"); }
+    utf8::decode($rightsVersion);
+    push @addBagInfo, {'SLUBArchiv-rightsVersion' => $rightsVersion};
+}
+# addKeyValue
+if (@addKeyValue) {
+    foreach my $zeile(@addKeyValue){
+        if($zeile !~ m#^.*:.*$#){ # : must be minimum once present
+            confess('wrong construct in --add_key_value="' . $zeile . '", expected --add_key_value="key:value", regexp to match is (^[^:]+:[^:]+$)');
+        } else {
+            utf8::decode($zeile);
+            my @keyvalue = split(/:/, $zeile, 2);    # split on first :
+            my $key = $keyvalue[0];
+            my $value = $keyvalue[1];
+            if($key eq 'SLUBArchiv-sipVersion' ||
+               $key eq 'SLUBArchiv-externalWorkflow' ||
+               $key eq 'SLUBArchiv-externalId' ||
+               $key eq 'SLUBArchiv-externalIsilId' ||
+               $key eq 'SLUBArchiv-exportToArchiveDate' ||
+               $key eq 'SLUBArchiv-hasConservationReason' ||
+               $key eq 'SLUBArchiv-archivalValueDescription' ||
+               $key eq 'SLUBArchiv-rightsVersion'){
+                confess("Duplicate key $key present at --add_key_value. Notice: $key is reserved by SLUB Dresden.");
+                print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white");
+            }
+            if($key eq 'Bag-Count'){
+                confess("$key present at --add_key_value. This key is not available due to SLUB spesification.");
+                print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white");
+            }
+            if($key eq 'Bag-Group-Identifier'){
+                confess("$key present at --add_key_value. This key is not available due to SLUB spesification.");
+                print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white");
+            }
+            push @addBagInfo, {$key => $value};
+        }
+    }
+}
+#p(@addKeyValue);
+#p(@addBagInfo); # print data from array of hashes https://docstore.mik.ua/orelly/perl/prog3/ch09_03.htm
+###########################################################################################################################################################
+# rightsFilePath
+if (!defined $rightsFilePath || $rightsFilePath eq "") { confess("you need to specify --rights_xml file, which needs to be added"); }
+if (! -f $rightsFilePath)     { confess("you need to specify --rights_xml file, status: is not a file"); }
+# addMetaFile
+if (@addMetaFile){ foreach my $file(@addMetaFile){ if(! -f $file){ confess("file $file at --add_meta_file, is not a file or could not be found"); } } }
+
+$ieDirectory = path($ieDirectory)->realpath->stringify;
+if($save ne "replace") {
+    path($outputPath)->mkpath;
+    $outputPath = path($outputPath)->realpath->stringify;
+}
+
+#===============================================================================
+
+sub main{
+    # prepare dirs
+    my $file_date = $exportToArchiveDate;
+    $file_date =~ s/T/_/g; # replace 'T' with '_'
+    $file_date =~ s/:/-/g; # replace ':' with '-'
+    my $sipRootDir = (defined $ppn)? "PPN-${ppn}_${file_date}" : "ID-${noppn}_${file_date}";    # Bag output dir name
+    my $ie_path = SLUB::LZA::SIPBuilderBagIt::save_option($save, $ieDirectory, $outputPath, $sipRootDir);
+    # data directory
+    if(! -d "$ie_path/data"){
+        my @payload_files = SLUB::LZA::SIPBuilderBagIt::getPayloadFiles($ie_path);
+        mkdir("$ie_path/data") or die "Could not mkdir $ie_path/data: $!";
+        foreach my $file(@payload_files){
+            if(-f "$ie_path/$file") { move("$ie_path/$file", "$ie_path/data/$file") or die "Could not move $file payload files to $ie_path/data: $!"; }
+            if(-d "$ie_path/$file") { File::Copy::Recursive::dirmove("$ie_path/$file", "$ie_path/data/$file") or die "Could not move $file payload files to $ie_path/data: $!"; }
+        }
+    }
+    # meta directory
+    if(! -d "$ie_path/meta"){
+        mkdir("$ie_path/meta") or die "Could not mkdir $ie_path/meta: $!";
+    }
+    # meta files
+    if(@addMetaFile){
+        foreach my $file(@addMetaFile){
+            my $i = 1;
+            my $meta_file_name = SLUB::LZA::SIPBuilderBagIt::getFileName($file);
+            if($meta_file_name eq "rights.xml" || $meta_file_name eq "mods.xml"){
+                foreach my $f(@addMetaFile){
+                    my $f_name = SLUB::LZA::SIPBuilderBagIt::getFileName($f);
+                    while($f_name eq "$i.xml"){
+                        $i++;
+                    }
+                }
+                SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "WARNING: Renaming " . $meta_file_name . " to $i.xml, because meta filename <rights.xml> or <mods.xml> is reserved.", "", "yellow");
+                SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white");
+                copy($file, "$ie_path/meta") or die "Copy failed: $!";
+                rename("$ie_path/meta/$meta_file_name", "$ie_path/meta/$i.xml");
+            }else{
+                copy($file, "$ie_path/meta") or die "Copy failed: $!";
+            }
+        }
+    }
+    # mods.xml
+    my $mods = (defined $ppn)? SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_ppn($ppn) : SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_noppn($noppn);     # prepare mods-sec
+    SLUB::LZA::SIPBuilderBagIt::write_file("$ie_path/meta/mods.xml", $mods);
+    # rights.xml
+    if(SLUB::LZA::SIPBuilderBagIt::getFileName($rightsFilePath) ne "rights.xml"){
+        my $rights_name = SLUB::LZA::SIPBuilderBagIt::getFileName($rightsFilePath);
+        SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "WARNING: Renaming " . $rights_name . " to rights.xml, because meta filename <rights.xml> is required.", "", "yellow");
+        SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white");
+        copy($rightsFilePath, "$ie_path/meta") or die "Copy failed: $!";
+        rename("$ie_path/meta/$rights_name", "$ie_path/meta/rights.xml");
+    }else{
+        copy($rightsFilePath, "$ie_path/meta") or die "Copy failed: $!";
+    }
+    SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_path, "rights.xml");
+    # create slub bagit
+    SLUB::LZA::SIPBuilderBagIt::create_slub_bagit($ie_path, \@addBagInfo);
+    SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "SUCCESS: SLUB Bag at $ie_path build successfully!", "", "green");
+
+    return;
+}
+
+#===============================================================================
+
+main();
+
+#===============================================================================
+
+__END__
+
+=pod
+
+=head1 NAME
+
+preingest tool "SLUB SIP Builder BagIt" script to create Bags for SLUBArchive
+
+=head1 SYNOPSIS
+
+slubsipbuilderbagit.pl  [options]
+
+Options:
+        -help                           brief help message
+        -man                            full documentation
+
+        -save_option=<option>           save as <copy>, <move>, <replace>, the <copy> option should be prefered
+        -IE_directory=<IE dir>          existing IE directory (absolute path!)
+        -SIP_output_path=<target dir>   where to put the SIP dir (absolute path!)
+        -ppn=<ppn>|-noppn=<noppn>       SWB-PPN or any identifier (uses minimalistic MODS)
+
+        -SIP_version=<version>          mandatory, needs for identification of SIP format, supported <v2020.1>
+        -external_workflow=<workflow>   mandatory, should be uniqe workflow name
+        -external_id=<id>               mandatory, should be uniqe ID (i.e. a catalog ID), reuse an ID only when updating existing AIP
+        -external_ISIL=<isil>           optional, ISIL number of library
+        -external_conservation_flag     optional, if set no other "original" still exists
+        -external_value_descr=<text>    mandatory, the reason why to archive
+        -rights_version=<version>       mandatory, SLUB law managment specification, supported <1.0>
+
+        -rights_xml=<file>              mandatory, path to SLUB rights xml file(absolute path!)
+        -add_meta_file=<file>           optional, can be repeated, additional meta files(absolute path!)
+        -add_key_value=<"key:value">    optional, can be repeated, additional key value pairs for bag-info.txt
+
+=head1 EXAMPLES
+
+=head2 Copy    (minimalistic)
+
+perl -I lib/ bin/slubsipbuilderbagit.pl
+     --save_option=copy
+     --IE_directory=/IE/git/SLUB_SIP_Builder/export_dir_kitodo/bagit/test2
+     --SIP_output_path=/output_sips
+     --ppn=457035137
+     --SIP_version=v2020.1
+     --external_id=10008
+     --external_workflow=kitodo
+     --external_ISIL=DE-14
+     --external_value_descr="Gesetzlicher Auftrag"
+     --rights_version=1.0
+     --rights_xml=/metadata/rights/Fallbeispiel-02.xml
+
+=head2 Copy
+
+perl -I lib/ bin/slubsipbuilderbagit.pl
+     --save_option=copy
+     --IE_directory=/IE/git/SLUB_SIP_Builder/export_dir_kitodo/bagit/test2
+     --SIP_output_path=/output_sips
+     --ppn=457035137
+     --SIP_version=v2020.1
+     --external_id=10008
+     --external_workflow=kitodo
+     --external_ISIL=DE-14
+     --external_value_descr="Gesetzlicher Auftrag"
+     --rights_version=1.0
+     --rights_xml=/metadata/rights/Fallbeispiel-01.xml
+     --add_meta_file=/metadata/lido.xml
+     --add_meta_file=/metadata/mods.xml
+     --add_key_value="Author:Lew Nikolajewitsch Tolstoi"
+     --add_key_value="Titel:Krieg und Frieden"
+     --add_key_value="Genre:Roman"
+
+=head2 Replace (minimalistic)
+
+NOT RECOMMENDED! IF FAILS, "IE" MUST BE MANUAL RESTORED TO THE PREVIOUS STATE!!!
+
+perl -I lib/ bin/slubsipbuilderbagit.pl
+     --save_option=replace
+     --IE_directory=/IE/SLUB_SIP_Builder/export_dir_kitodo/bagit/test2
+     --ppn=457035137
+     --SIP_version=v2020.1
+     --external_id=10008
+     --external_workflow=kitodo
+     --external_ISIL=DE-14
+     --external_value_descr="Gesetzlicher Auftrag"
+     --rights_version=1.0
+     --rights_xml=/metadata/rights/Fallbeispiel-01.xml
+
+=head2 Move    (minimalistic)
+
+NOT RECOMMENDED! IF FAILS, "IE" MUST BE MANUAL RESTORED TO THE PREVIOUS STATE!!!
+
+perl -I lib/ bin/slubsipbuilderbagit.pl
+     --save_option=move
+     --IE_directory=/IE/git/SLUB_SIP_Builder/export_dir_kitodo/bagit/test2
+     --SIP_output_path=/output_sips
+     --ppn=457035137
+     --SIP_version=v2020.1
+     --external_id=10008
+     --external_workflow=kitodo
+     --external_ISIL=DE-14
+     --external_value_descr="Gesetzlicher Auftrag"
+     --rights_version=1.0
+     --rights_xml=/metadata/rights/Fallbeispiel-03.xml
+
+
+=head1 OPTIONS
+
+=over 8
+
+=item B<-help>
+
+Print a brief help message and exits.
+
+=back
+
+=head1 DESCRIPTION
+
+B<This program> will process the given IE directory, add bibliographic metadata from catalogue with
+given PICA number and check and create a BagIt directory ready for SLUBarchiv
+
+=cut
diff --git a/export_dir_kitodo/bagit/meta/bubble.xml b/export_dir_kitodo/bagit/meta/bubble.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3713df5e6c931dce354bb643d687460931e91de9
--- /dev/null
+++ b/export_dir_kitodo/bagit/meta/bubble.xml
@@ -0,0 +1 @@
+this is my rights.xml
\ No newline at end of file
diff --git a/export_dir_kitodo/bagit/meta/lido.xml b/export_dir_kitodo/bagit/meta/lido.xml
new file mode 100644
index 0000000000000000000000000000000000000000..19b16cc72c67d3a63e9545d4ad01635e85e4c8d9
--- /dev/null
+++ b/export_dir_kitodo/bagit/meta/lido.xml
@@ -0,0 +1 @@
+<xml></xml>
\ No newline at end of file
diff --git a/export_dir_kitodo/bagit/meta/mods.xml b/export_dir_kitodo/bagit/meta/mods.xml
new file mode 100644
index 0000000000000000000000000000000000000000..ab512e26c7d17e941357c4e439a6fd31d85dc568
--- /dev/null
+++ b/export_dir_kitodo/bagit/meta/mods.xml
@@ -0,0 +1,38 @@
+<mods:mods xmlns:mods="http://www.loc.gov/mods/v3">
+<mods:location>
+<mods:physicalLocation authority="marcorg" displayLabel="Saxon State Library, Dresden,
+Germany">DE-14</mods:physicalLocation>
+<mods:shelfLocator>Hist.Sax.M.37.t,120</mods:shelfLocator>
+</mods:location>
+<mods:relatedItem type="series">
+<mods:titleInfo>
+<mods:title>Saxonica</mods:title>
+</mods:titleInfo>
+</mods:relatedItem>
+<mods:recordInfo>
+<mods:recordIdentifier source="http://digital.slub-dresden.de/oai/">oai:de:slub-dresden:db:id-
+319037843</mods:recordIdentifier>
+</mods:recordInfo>
+<mods:physicalDescription>
+<mods:digitalOrigin>reformatted digital</mods:digitalOrigin>
+<mods:extent>[1] Bl.</mods:extent>
+</mods:physicalDescription>
+<mods:identifier type="urn">urn:nbn:de:bsz:14-db-id3190378431</mods:identifier>
+<mods:titleInfo>
+<mods:title>Eingabe der Handelskammer zu Leipzig den Entwurf eines Tabak-Steuer-Gesetzes
+betr.</mods:title>
+<mods:subTitle>an den Reichstag zu Berlin</mods:subTitle>
+</mods:titleInfo>
+<mods:language>
+<mods:languageTerm authority="rfc3066" type="code">de</mods:languageTerm>
+</mods:language>
+<mods:originInfo>
+<mods:place>
+<mods:placeTerm type="text">[Leipzig]</mods:placeTerm>
+</mods:place>
+<mods:dateIssued keyDate="yes">1893</mods:dateIssued>
+</mods:originInfo>
+<mods:subject authority="slub">
+<mods:topic>eingdehaz</mods:topic>
+</mods:subject>
+</mods:mods>
diff --git a/export_dir_kitodo/bagit/meta/rights.xml b/export_dir_kitodo/bagit/meta/rights.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3201b82290c78afdb5e85650061cae25fe930e26
--- /dev/null
+++ b/export_dir_kitodo/bagit/meta/rights.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/slub-rr-v09-1.xsd">
+    <slubarchiv:copyrightStatus>publicdomain</slubarchiv:copyrightStatus>
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+</slubarchiv:rightsRecord>
\ No newline at end of file
diff --git a/export_dir_kitodo/bagit/meta2/1.xml b/export_dir_kitodo/bagit/meta2/1.xml
new file mode 100644
index 0000000000000000000000000000000000000000..58b432bed14e24d243c846656fdddd4d05a4d3ce
--- /dev/null
+++ b/export_dir_kitodo/bagit/meta2/1.xml
@@ -0,0 +1 @@
+this is real 1.xml
diff --git a/export_dir_kitodo/bagit/meta2/2.xml b/export_dir_kitodo/bagit/meta2/2.xml
new file mode 100644
index 0000000000000000000000000000000000000000..db92e8151d5a028638b2d0160652fab9e2d77f38
--- /dev/null
+++ b/export_dir_kitodo/bagit/meta2/2.xml
@@ -0,0 +1 @@
+this is 2.xml
\ No newline at end of file
diff --git a/export_dir_kitodo/bagit/meta2/invalid_rights.xml b/export_dir_kitodo/bagit/meta2/invalid_rights.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c43a85cc9b8fd04afc7782f1b9af35e6ceb0cee4
--- /dev/null
+++ b/export_dir_kitodo/bagit/meta2/invalid_rights.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    copyrighted
+</slubarchiv:rightsRecord>
\ No newline at end of file
diff --git a/export_dir_kitodo/bagit/meta2/rights.xml b/export_dir_kitodo/bagit/meta2/rights.xml
new file mode 100644
index 0000000000000000000000000000000000000000..cad6ed7c4d0bd07bcdcd604d077f7caeef87c3a9
--- /dev/null
+++ b/export_dir_kitodo/bagit/meta2/rights.xml
@@ -0,0 +1 @@
+this is meta2/rights.xml
\ No newline at end of file
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-01.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-01.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3df70f4b2ef3b228720d678dda06c6c07ce06f04
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-01.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>publicdomain</slubarchiv:copyrightStatus>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-02.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-02.xml
new file mode 100644
index 0000000000000000000000000000000000000000..9b98ec18328811d8761649d0b6fec80a9c7e995f
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-02.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2017-10-10">Vertrag zw. Herrn Mustermann und SLUB</slubarchiv:contract>
+    </slubarchiv:permissions>
+    <slubarchiv:legalRestrictions>
+        <slubarchiv:personalRight>Gerichtsurteil Amtsgericht Dresden, AZ: 1 O 12345/17</slubarchiv:personalRight>
+    </slubarchiv:legalRestrictions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-03.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-03.xml
new file mode 100644
index 0000000000000000000000000000000000000000..55e8d829ed82040511b3b0e0cc03daf697faac88
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-03.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:license url="https://creativecommons.org/publicdomain/zero/1.0/">CC0 1.0</slubarchiv:license>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-04.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-04.xml
new file mode 100644
index 0000000000000000000000000000000000000000..06426c34e0195e768b3c803d83f03e27100cb977
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-04.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2017-01-01">Vereinbarung zur Digitalisierung und zur digitalen Präsentation von Beständen im Rahmen des Landesdigitalisierungsprogramms für Wissenschaft und Kultur zwischen Einrichtung XY und der Sächsische Landesbibliothek – Staats- und Universitätsbibliothek Dresden (SLUB)</slubarchiv:contract>
+        <slubarchiv:license url="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</slubarchiv:license>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-05.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-05.xml
new file mode 100644
index 0000000000000000000000000000000000000000..1c85151e519576ca92d7c852720f3b86d9686196
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-05.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:orphanedWork/>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-06.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-06.xml
new file mode 100644
index 0000000000000000000000000000000000000000..bb921f00ecd9142f30c95369aa8fa94f98528799
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-06.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2015-01-01">Rahmenvertrag zur Nutzung von vergriffenen Werken in Büchern zwischen Bund, Ländern, Verwertungsgesellschaft WORT und Verwertungsgesellschaft Bild-Kunst</slubarchiv:contract>
+        <slubarchiv:outOfPrintWork/>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-07.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-07.xml
new file mode 100644
index 0000000000000000000000000000000000000000..d8080ea508f0a3bab57f3463c9c681b67a732fb8
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-07.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2019-01-31">Vertrag zur Digitalisierung der XY-Tagebücher zwischen dem Verlag Z und der SLUB Dresden</slubarchiv:contract>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-08a-undef.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-08a-undef.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3922d3c13cd40a45e9f6e38bca3e022afa75ce5c
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-08a-undef.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>undefined</slubarchiv:copyrightStatus>
+    <slubarchiv:legalRestrictions>
+        <slubarchiv:childProtection>Nationalsozialistischer Inhalt</slubarchiv:childProtection>
+    </slubarchiv:legalRestrictions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-09.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-09.xml
new file mode 100644
index 0000000000000000000000000000000000000000..7cd9bac20f2487a826facee9edb51e0524e9da2d
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-09.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2016-12-09">Kooperationsvereinbarung zwischen dem Freistaat Sachsen, vertreten durch die Landesbehörde XY und der Sächsischen Landesbibliothek - Staats- und Universitätsbibliothek Dresden (SLUB)</slubarchiv:contract>
+    </slubarchiv:permissions>
+    <slubarchiv:legalRestrictions>
+        <slubarchiv:confidentialContent>Dieses Dokument enthält Betriebs- und Geschäftsgeheimnisse.</slubarchiv:confidentialContent>
+    </slubarchiv:legalRestrictions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-10.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-10.xml
new file mode 100644
index 0000000000000000000000000000000000000000..37c861c074c83e2b77bd1792411df9b9cf8afac0
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-10.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2016-12-09">Kooperationsvereinbarung zwischen dem Freistaat Sachsen, vertreten durch die Landesbehörde XY und der Sächsischen Landesbibliothek - Staats- und Universitätsbibliothek Dresden (SLUB)</slubarchiv:contract>
+    </slubarchiv:permissions>
+    <slubarchiv:legalRestrictions>
+        <slubarchiv:confidentialContent>Dieses Dokument enthält Daten über sensible Einrichtungen.</slubarchiv:confidentialContent>
+    </slubarchiv:legalRestrictions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-11.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-11.xml
new file mode 100644
index 0000000000000000000000000000000000000000..ca53766ebe8b4539d3d0d964154fac8e600d65b7
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-11.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2016-12-09">Kooperationsvereinbarung zwischen dem Freistaat Sachsen, vertreten durch die Landesbehörde XY und der Sächsischen Landesbibliothek - Staats- und Universitätsbibliothek Dresden (SLUB)</slubarchiv:contract>
+    </slubarchiv:permissions>
+    <slubarchiv:legalRestrictions>
+        <slubarchiv:personalRight>Das Dokument enthält persönliche Daten, präzise Wohnorte oder andere Informationen mit Personenbezug.</slubarchiv:personalRight>
+    </slubarchiv:legalRestrictions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-12.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-12.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b333e2f6c4787e10b7890ea85df6674c86c35426
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-12.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2016-12-09">Kooperationsvereinbarung zwischen dem Freistaat Sachsen, vertreten durch die Landesbehörde XY und der Sächsischen Landesbibliothek - Staats- und Universitätsbibliothek Dresden (SLUB)</slubarchiv:contract>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-13.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-13.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3df70f4b2ef3b228720d678dda06c6c07ce06f04
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-13.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>publicdomain</slubarchiv:copyrightStatus>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-14.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-14.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3f20f4a7c6c382549caad59590c74834b65d92d1
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-14.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2012-03-13">Lizenzvertrag zwischen der Sächsischen Landesbibliothek - Staats- und Universitätsbibliothek Dresden (SLUB) und dem die Landesbehörde Verein XY</slubarchiv:contract>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-15.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-15.xml
new file mode 100644
index 0000000000000000000000000000000000000000..d31e356b7a35586004dda3a097969d4385c303ce
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-15.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2017-07-18">Einverständniserklärung für das elektronische Publizieren in den Digitalen Sammlungen der SLUB. Autor oder sonstige Rechteinhaber: XY</slubarchiv:contract>
+        <slubarchiv:license url="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</slubarchiv:license>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/rights/Fallbeispiel-16.xml b/export_dir_kitodo/bagit/rights/Fallbeispiel-16.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c77761ff99372661d4f7610f18f6e32b8ec0e6f7
--- /dev/null
+++ b/export_dir_kitodo/bagit/rights/Fallbeispiel-16.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:license url="https://www.govdata.de/dl-de/by-2-0">DL-DE BY 2.0</slubarchiv:license>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/data/test.txt b/export_dir_kitodo/bagit/test/data/test.txt
new file mode 100644
index 0000000000000000000000000000000000000000..6f3f31b13b1726146f8777621ec363583bbea240
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/data/test.txt
@@ -0,0 +1 @@
+test file for payload.
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-01.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-01.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3df70f4b2ef3b228720d678dda06c6c07ce06f04
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-01.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>publicdomain</slubarchiv:copyrightStatus>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-02.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-02.xml
new file mode 100644
index 0000000000000000000000000000000000000000..9b98ec18328811d8761649d0b6fec80a9c7e995f
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-02.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2017-10-10">Vertrag zw. Herrn Mustermann und SLUB</slubarchiv:contract>
+    </slubarchiv:permissions>
+    <slubarchiv:legalRestrictions>
+        <slubarchiv:personalRight>Gerichtsurteil Amtsgericht Dresden, AZ: 1 O 12345/17</slubarchiv:personalRight>
+    </slubarchiv:legalRestrictions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-03.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-03.xml
new file mode 100644
index 0000000000000000000000000000000000000000..55e8d829ed82040511b3b0e0cc03daf697faac88
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-03.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:license url="https://creativecommons.org/publicdomain/zero/1.0/">CC0 1.0</slubarchiv:license>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-04.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-04.xml
new file mode 100644
index 0000000000000000000000000000000000000000..06426c34e0195e768b3c803d83f03e27100cb977
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-04.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2017-01-01">Vereinbarung zur Digitalisierung und zur digitalen Präsentation von Beständen im Rahmen des Landesdigitalisierungsprogramms für Wissenschaft und Kultur zwischen Einrichtung XY und der Sächsische Landesbibliothek – Staats- und Universitätsbibliothek Dresden (SLUB)</slubarchiv:contract>
+        <slubarchiv:license url="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</slubarchiv:license>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-05.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-05.xml
new file mode 100644
index 0000000000000000000000000000000000000000..1c85151e519576ca92d7c852720f3b86d9686196
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-05.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:orphanedWork/>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-06.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-06.xml
new file mode 100644
index 0000000000000000000000000000000000000000..bb921f00ecd9142f30c95369aa8fa94f98528799
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-06.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2015-01-01">Rahmenvertrag zur Nutzung von vergriffenen Werken in Büchern zwischen Bund, Ländern, Verwertungsgesellschaft WORT und Verwertungsgesellschaft Bild-Kunst</slubarchiv:contract>
+        <slubarchiv:outOfPrintWork/>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-07.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-07.xml
new file mode 100644
index 0000000000000000000000000000000000000000..d8080ea508f0a3bab57f3463c9c681b67a732fb8
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-07.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2019-01-31">Vertrag zur Digitalisierung der XY-Tagebücher zwischen dem Verlag Z und der SLUB Dresden</slubarchiv:contract>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-08a-undef.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-08a-undef.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3922d3c13cd40a45e9f6e38bca3e022afa75ce5c
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-08a-undef.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>undefined</slubarchiv:copyrightStatus>
+    <slubarchiv:legalRestrictions>
+        <slubarchiv:childProtection>Nationalsozialistischer Inhalt</slubarchiv:childProtection>
+    </slubarchiv:legalRestrictions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-09.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-09.xml
new file mode 100644
index 0000000000000000000000000000000000000000..7cd9bac20f2487a826facee9edb51e0524e9da2d
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-09.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2016-12-09">Kooperationsvereinbarung zwischen dem Freistaat Sachsen, vertreten durch die Landesbehörde XY und der Sächsischen Landesbibliothek - Staats- und Universitätsbibliothek Dresden (SLUB)</slubarchiv:contract>
+    </slubarchiv:permissions>
+    <slubarchiv:legalRestrictions>
+        <slubarchiv:confidentialContent>Dieses Dokument enthält Betriebs- und Geschäftsgeheimnisse.</slubarchiv:confidentialContent>
+    </slubarchiv:legalRestrictions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-10.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-10.xml
new file mode 100644
index 0000000000000000000000000000000000000000..37c861c074c83e2b77bd1792411df9b9cf8afac0
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-10.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2016-12-09">Kooperationsvereinbarung zwischen dem Freistaat Sachsen, vertreten durch die Landesbehörde XY und der Sächsischen Landesbibliothek - Staats- und Universitätsbibliothek Dresden (SLUB)</slubarchiv:contract>
+    </slubarchiv:permissions>
+    <slubarchiv:legalRestrictions>
+        <slubarchiv:confidentialContent>Dieses Dokument enthält Daten über sensible Einrichtungen.</slubarchiv:confidentialContent>
+    </slubarchiv:legalRestrictions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-11.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-11.xml
new file mode 100644
index 0000000000000000000000000000000000000000..ca53766ebe8b4539d3d0d964154fac8e600d65b7
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-11.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2016-12-09">Kooperationsvereinbarung zwischen dem Freistaat Sachsen, vertreten durch die Landesbehörde XY und der Sächsischen Landesbibliothek - Staats- und Universitätsbibliothek Dresden (SLUB)</slubarchiv:contract>
+    </slubarchiv:permissions>
+    <slubarchiv:legalRestrictions>
+        <slubarchiv:personalRight>Das Dokument enthält persönliche Daten, präzise Wohnorte oder andere Informationen mit Personenbezug.</slubarchiv:personalRight>
+    </slubarchiv:legalRestrictions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-12.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-12.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b333e2f6c4787e10b7890ea85df6674c86c35426
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-12.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2016-12-09">Kooperationsvereinbarung zwischen dem Freistaat Sachsen, vertreten durch die Landesbehörde XY und der Sächsischen Landesbibliothek - Staats- und Universitätsbibliothek Dresden (SLUB)</slubarchiv:contract>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-13.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-13.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3df70f4b2ef3b228720d678dda06c6c07ce06f04
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-13.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>publicdomain</slubarchiv:copyrightStatus>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-14.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-14.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3f20f4a7c6c382549caad59590c74834b65d92d1
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-14.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2012-03-13">Lizenzvertrag zwischen der Sächsischen Landesbibliothek - Staats- und Universitätsbibliothek Dresden (SLUB) und dem die Landesbehörde Verein XY</slubarchiv:contract>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-15.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-15.xml
new file mode 100644
index 0000000000000000000000000000000000000000..d31e356b7a35586004dda3a097969d4385c303ce
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-15.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:contract date="2017-07-18">Einverständniserklärung für das elektronische Publizieren in den Digitalen Sammlungen der SLUB. Autor oder sonstige Rechteinhaber: XY</slubarchiv:contract>
+        <slubarchiv:license url="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</slubarchiv:license>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/Fallbeispiel-16.xml b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-16.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c77761ff99372661d4f7610f18f6e32b8ec0e6f7
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/Fallbeispiel-16.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/rights1.xsd">
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+    <slubarchiv:permissions>
+        <slubarchiv:license url="https://www.govdata.de/dl-de/by-2-0">DL-DE BY 2.0</slubarchiv:license>
+    </slubarchiv:permissions>
+</slubarchiv:rightsRecord>
diff --git a/export_dir_kitodo/bagit/test/meta/bubble.xml b/export_dir_kitodo/bagit/test/meta/bubble.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3713df5e6c931dce354bb643d687460931e91de9
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/bubble.xml
@@ -0,0 +1 @@
+this is my rights.xml
\ No newline at end of file
diff --git a/export_dir_kitodo/bagit/test/meta/lido.xml b/export_dir_kitodo/bagit/test/meta/lido.xml
new file mode 100644
index 0000000000000000000000000000000000000000..19b16cc72c67d3a63e9545d4ad01635e85e4c8d9
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/lido.xml
@@ -0,0 +1 @@
+<xml></xml>
\ No newline at end of file
diff --git a/export_dir_kitodo/bagit/test/meta/mods.xml b/export_dir_kitodo/bagit/test/meta/mods.xml
new file mode 100644
index 0000000000000000000000000000000000000000..ab512e26c7d17e941357c4e439a6fd31d85dc568
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/mods.xml
@@ -0,0 +1,38 @@
+<mods:mods xmlns:mods="http://www.loc.gov/mods/v3">
+<mods:location>
+<mods:physicalLocation authority="marcorg" displayLabel="Saxon State Library, Dresden,
+Germany">DE-14</mods:physicalLocation>
+<mods:shelfLocator>Hist.Sax.M.37.t,120</mods:shelfLocator>
+</mods:location>
+<mods:relatedItem type="series">
+<mods:titleInfo>
+<mods:title>Saxonica</mods:title>
+</mods:titleInfo>
+</mods:relatedItem>
+<mods:recordInfo>
+<mods:recordIdentifier source="http://digital.slub-dresden.de/oai/">oai:de:slub-dresden:db:id-
+319037843</mods:recordIdentifier>
+</mods:recordInfo>
+<mods:physicalDescription>
+<mods:digitalOrigin>reformatted digital</mods:digitalOrigin>
+<mods:extent>[1] Bl.</mods:extent>
+</mods:physicalDescription>
+<mods:identifier type="urn">urn:nbn:de:bsz:14-db-id3190378431</mods:identifier>
+<mods:titleInfo>
+<mods:title>Eingabe der Handelskammer zu Leipzig den Entwurf eines Tabak-Steuer-Gesetzes
+betr.</mods:title>
+<mods:subTitle>an den Reichstag zu Berlin</mods:subTitle>
+</mods:titleInfo>
+<mods:language>
+<mods:languageTerm authority="rfc3066" type="code">de</mods:languageTerm>
+</mods:language>
+<mods:originInfo>
+<mods:place>
+<mods:placeTerm type="text">[Leipzig]</mods:placeTerm>
+</mods:place>
+<mods:dateIssued keyDate="yes">1893</mods:dateIssued>
+</mods:originInfo>
+<mods:subject authority="slub">
+<mods:topic>eingdehaz</mods:topic>
+</mods:subject>
+</mods:mods>
diff --git a/export_dir_kitodo/bagit/test/meta/rights.xml b/export_dir_kitodo/bagit/test/meta/rights.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3201b82290c78afdb5e85650061cae25fe930e26
--- /dev/null
+++ b/export_dir_kitodo/bagit/test/meta/rights.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<slubarchiv:rightsRecord xmlns:slubarchiv="http://slubarchiv.slub-dresden.de/rights1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://slubarchiv.slub-dresden.de/rights1 https://slubarchiv.slub-dresden.de/slubarchiv/standards/rights/slub-rr-v09-1.xsd">
+    <slubarchiv:copyrightStatus>publicdomain</slubarchiv:copyrightStatus>
+    <slubarchiv:copyrightStatus>copyrighted</slubarchiv:copyrightStatus>
+</slubarchiv:rightsRecord>
\ No newline at end of file
diff --git a/export_dir_kitodo/bagit/test2/scans_tif/00000001.tif b/export_dir_kitodo/bagit/test2/scans_tif/00000001.tif
new file mode 100644
index 0000000000000000000000000000000000000000..53ff885628eac6799fed0d9729f80c009eee8b3d
Binary files /dev/null and b/export_dir_kitodo/bagit/test2/scans_tif/00000001.tif differ
diff --git a/export_dir_kitodo/bagit/test2/scans_tif/00000002.tif b/export_dir_kitodo/bagit/test2/scans_tif/00000002.tif
new file mode 100644
index 0000000000000000000000000000000000000000..b25d4e6c3f41f5a0dac1acd0c7bc8ed476c40820
Binary files /dev/null and b/export_dir_kitodo/bagit/test2/scans_tif/00000002.tif differ
diff --git a/export_dir_kitodo/bagit/test2/test.txt b/export_dir_kitodo/bagit/test2/test.txt
new file mode 100644
index 0000000000000000000000000000000000000000..1897e90346c2a60226554696f6b39c665ea9b589
--- /dev/null
+++ b/export_dir_kitodo/bagit/test2/test.txt
@@ -0,0 +1 @@
+test file for payload.
diff --git a/export_dir_kitodo/bagit/test3/img/scans_tif/00000001.tif b/export_dir_kitodo/bagit/test3/img/scans_tif/00000001.tif
new file mode 100644
index 0000000000000000000000000000000000000000..53ff885628eac6799fed0d9729f80c009eee8b3d
Binary files /dev/null and b/export_dir_kitodo/bagit/test3/img/scans_tif/00000001.tif differ
diff --git a/export_dir_kitodo/bagit/test3/img/scans_tif/00000002.tif b/export_dir_kitodo/bagit/test3/img/scans_tif/00000002.tif
new file mode 100644
index 0000000000000000000000000000000000000000..b25d4e6c3f41f5a0dac1acd0c7bc8ed476c40820
Binary files /dev/null and b/export_dir_kitodo/bagit/test3/img/scans_tif/00000002.tif differ
diff --git a/export_dir_kitodo/bagit/test3/test.txt b/export_dir_kitodo/bagit/test3/test.txt
new file mode 100644
index 0000000000000000000000000000000000000000..1897e90346c2a60226554696f6b39c665ea9b589
--- /dev/null
+++ b/export_dir_kitodo/bagit/test3/test.txt
@@ -0,0 +1 @@
+test file for payload.
diff --git a/t/slubsipbuilder.t b/t/slubsipbuilder.t
deleted file mode 100755
index 6c5549955e452742908edab08a4c52cc8e691482..0000000000000000000000000000000000000000
--- a/t/slubsipbuilder.t
+++ /dev/null
@@ -1,691 +0,0 @@
-#!/usr/bin/perl -w
-use strict;
-use warnings;
-use diagnostics;
-
-use Test::More tests => 78;
-use Test::Output;
-use Test::Exception;
-use Test::File;
-use Path::Tiny;
-
-# *** Read before running tests ***
-# Warning: While running project "SLUB_SIP_Builder" two directories "export_dir_kitodo" and "tmp/mysip" will be created.
-# Start scipt in the project directory to run all tests properly. 
-
-### prepare
-BEGIN {
-    use Path::Tiny;
-    push @INC, Path::Tiny::path(__FILE__)->parent->parent->path("bin")->absolute->stringify;
-    require "slubsipbuilder.pl";
-    $INC{'SLUB/LZA/SIPBuilder.pm'} = 1; # needed because inlined module
-}
-my $unpatched_mods=<<'UNPATCHED_MODS';
-<?xml version="1.0" encoding="UTF-8"?>
-<mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/mods/v3" version="3.6" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd"><titleInfo><nonSort xml:space="preserve">Der  </nonSort><title>Fichtelberg</title><subTitle>Berg der unbekannten Rekorrde</subTitle></titleInfo><name type="personal"><namePart>Schneider, Dirk</namePart><role><roleTerm type="text">FilmemacherIn</roleTerm></role><role><roleTerm authority="marcrelator" type="code">fmk</roleTerm></role><nameIdentifier>(DE-627)1235502279 (DE-576)165502274</nameIdentifier></name><typeOfResource>moving image</typeOfResource><genre authority="rdacontent">zweidimensionales bewegtes Bild</genre><genre authority="gnd-content">Film</genre><originInfo><place><placeTerm type="code" authority="marccountry">xx</placeTerm></place><dateIssued encoding="marc">2014</dateIssued><issuance>monographic</issuance></originInfo><originInfo eventType="publication"><place><placeTerm type="text">[Leipzig]</placeTerm></place><publisher>top ten tv</publisher><dateIssued>[2014]</dateIssued></originInfo><language><languageTerm authority="iso639-2b" type="code">ger</languageTerm></language><physicalDescription><form authority="marccategory">electronic resource</form><form authority="marcsmd">remote</form><extent>1 Online-Ressource (1 Videodatei, 29:49) farbig</extent><form type="media" authority="rdamedia">Computermedien</form><form type="carrier" authority="rdacarrier">Online-Ressource</form></physicalDescription><targetAudience authority="marctarget">juvenile</targetAudience><note type="statement of responsibility" altRepGroup="00">ein Film von Dirk Schneider</note><note>Dokumentarfilm. Deutschland. 2014</note><relatedItem type="series"><titleInfo><title>MDR</title></titleInfo></relatedItem><relatedItem type="series"><titleInfo><title>Der Osten - entdecke wo du lebst</title></titleInfo></relatedItem><identifier type="oclc">946544758</identifier><recordInfo><descriptionStandard>rda</descriptionStandard><recordContentSource authority="marcorg">DE-576</recordContentSource><recordCreationDate encoding="marc">160304</recordCreationDate><recordChangeDate encoding="iso8601">20160510144338.0</recordChangeDate><recordIdentifier source="DE-576">457035137</recordIdentifier><recordOrigin>Converted from MARCXML to MODS version 3.6 using MARC21slim2MODS3-6.xsl
-				(Revision 1.119 2018/06/21)</recordOrigin><languageOfCataloging><languageTerm authority="iso639-2b" type="code">ger</languageTerm></languageOfCataloging></recordInfo></mods>
-UNPATCHED_MODS
-my $patched_mods=<<'PATCHED_MODS';
-<?xml version="1.0" encoding="UTF-8"?>
-<mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/mods/v3" version="3.6" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd"><titleInfo><nonSort xml:space="preserve">Der  </nonSort><title>Fichtelberg</title><subTitle>Berg der unbekannten Rekorrde</subTitle></titleInfo><name type="personal"><namePart>Schneider, Dirk</namePart><role><roleTerm type="text">FilmemacherIn</roleTerm></role><role><roleTerm authority="marcrelator" type="code">fmk</roleTerm></role><nameIdentifier>(DE-627)1235502279 (DE-576)165502274</nameIdentifier></name><typeOfResource>moving image</typeOfResource><genre authority="rdacontent">zweidimensionales bewegtes Bild</genre><genre authority="gnd-content">Film</genre><originInfo><place><placeTerm type="code" authority="marccountry">xx</placeTerm></place><dateIssued encoding="marc">2014</dateIssued><issuance>monographic</issuance></originInfo><originInfo eventType="publication"><place><placeTerm type="text">[Leipzig]</placeTerm></place><publisher>top ten tv</publisher><dateIssued>[2014]</dateIssued></originInfo><language><languageTerm authority="iso639-2b" type="code">ger</languageTerm></language><physicalDescription><form authority="marccategory">electronic resource</form><form authority="marcsmd">remote</form><extent>1 Online-Ressource (1 Videodatei, 29:49) farbig</extent><form type="media" authority="rdamedia">Computermedien</form><form type="carrier" authority="rdacarrier">Online-Ressource</form></physicalDescription><targetAudience authority="marctarget">juvenile</targetAudience><note type="statement of responsibility" altRepGroup="00">ein Film von Dirk Schneider</note><note>Dokumentarfilm. Deutschland. 2014</note><relatedItem type="series"><titleInfo><title>MDR</title></titleInfo></relatedItem><relatedItem type="series"><titleInfo><title>Der Osten - entdecke wo du lebst</title></titleInfo></relatedItem><identifier type="oclc">946544758</identifier><recordInfo><descriptionStandard>rda</descriptionStandard><recordContentSource authority="marcorg">DE-576</recordContentSource><recordCreationDate encoding="marc">160304</recordCreationDate><recordChangeDate encoding="iso8601">20160510144338.0</recordChangeDate><recordIdentifier source="DE-576">457035137</recordIdentifier><recordOrigin>Converted from MARCXML to MODS version 3.6 using MARC21slim2MODS3-6.xsl
-				(Revision 1.119 2018/06/21)</recordOrigin><languageOfCataloging><languageTerm authority="iso639-2b" type="code">ger</languageTerm></languageOfCataloging></recordInfo></mods>
-PATCHED_MODS
-my $unpatched_mods_obj = XML::LibXML->load_xml(string => $unpatched_mods);
-
-my $unpatched_marcblob=<<'UNPATCHED_MARCBLOB';
-<?xml version="1.0"?>
-<record xmlns="http://www.loc.gov/MARC21/slim">
-  <leader>     cgm a22        4500</leader>
-  <controlfield tag="001">457035137</controlfield>
-  <controlfield tag="003">DE-576</controlfield>
-  <controlfield tag="005">20160510144338.0</controlfield>
-  <controlfield tag="006">m     o  | |      </controlfield>
-  <controlfield tag="007">cr uuu---uuuuu</controlfield>
-  <controlfield tag="007">vu uuuuuu</controlfield>
-  <controlfield tag="008">160304s2014    xx ger c</controlfield>
-  <datafield tag="035" ind1=" " ind2=" ">
-    <subfield code="a">(DE-627)1655506501</subfield>
-  </datafield>
-  <datafield tag="035" ind1=" " ind2=" ">
-    <subfield code="a">(DE-576)457035137</subfield>
-  </datafield>
-  <datafield tag="035" ind1=" " ind2=" ">
-    <subfield code="a">(DE-599)BSZ457035137</subfield>
-  </datafield>
-  <datafield tag="035" ind1=" " ind2=" ">
-    <subfield code="a">(OCoLC)946544758</subfield>
-  </datafield>
-  <datafield tag="040" ind1=" " ind2=" ">
-    <subfield code="a">DE-576</subfield>
-    <subfield code="b">ger</subfield>
-    <subfield code="c">DE-576</subfield>
-    <subfield code="e">rda</subfield>
-  </datafield>
-  <datafield tag="041" ind1=" " ind2=" ">
-    <subfield code="a">ger</subfield>
-  </datafield>
-  <datafield tag="245" ind1="1" ind2="4">
-    <subfield code="a">Der Fichtelberg</subfield>
-    <subfield code="b">Berg der unbekannten Rekorrde</subfield>
-    <subfield code="c">ein Film von Dirk Schneider</subfield>
-  </datafield>
-  <datafield tag="264" ind1=" " ind2="1">
-    <subfield code="a">[Leipzig]</subfield>
-    <subfield code="b">top ten tv</subfield>
-    <subfield code="c">[2014]</subfield>
-  </datafield>
-  <datafield tag="264" ind1=" " ind2="4">
-    <subfield code="c">&#xA9; 2014</subfield>
-  </datafield>
-  <datafield tag="300" ind1=" " ind2=" ">
-    <subfield code="a">1 Online-Ressource (1 Videodatei, 29:49)</subfield>
-    <subfield code="b">farbig</subfield>
-  </datafield>
-  <datafield tag="336" ind1=" " ind2=" ">
-    <subfield code="a">zweidimensionales bewegtes Bild</subfield>
-    <subfield code="b">tdi</subfield>
-    <subfield code="2">rdacontent</subfield>
-  </datafield>
-  <datafield tag="337" ind1=" " ind2=" ">
-    <subfield code="a">Computermedien</subfield>
-    <subfield code="b">c</subfield>
-    <subfield code="2">rdamedia</subfield>
-  </datafield>
-  <datafield tag="338" ind1=" " ind2=" ">
-    <subfield code="a">Online-Ressource</subfield>
-    <subfield code="b">cr</subfield>
-    <subfield code="2">rdacarrier</subfield>
-  </datafield>
-  <datafield tag="490" ind1="0" ind2=" ">
-    <subfield code="a">MDR</subfield>
-  </datafield>
-  <datafield tag="490" ind1="0" ind2=" ">
-    <subfield code="a">Der Osten - entdecke wo du lebst</subfield>
-  </datafield>
-  <datafield tag="500" ind1=" " ind2=" ">
-    <subfield code="a">Dokumentarfilm. Deutschland. 2014</subfield>
-  </datafield>
-  <datafield tag="591" ind1=" " ind2=" ">
-    <subfield code="a">Fernsehmitschnitt (SWB)</subfield>
-  </datafield>
-  <datafield tag="655" ind1=" " ind2="7">
-    <subfield code="a">Film</subfield>
-    <subfield code="0">(DE-588)4017102-4</subfield>
-    <subfield code="0">(DE-627)104559683</subfield>
-    <subfield code="0">(DE-576)208918531</subfield>
-    <subfield code="2">gnd-content</subfield>
-  </datafield>
-  <datafield tag="700" ind1="1" ind2=" ">
-    <subfield code="a">Schneider, Dirk</subfield>
-    <subfield code="e">FilmemacherIn</subfield>
-    <subfield code="0">(DE-627)1235502279</subfield>
-    <subfield code="0">(DE-576)165502274</subfield>
-    <subfield code="4">fmk</subfield>
-  </datafield>
-  <datafield tag="935" ind1=" " ind2=" ">
-    <subfield code="c">vide</subfield>
-  </datafield>
-  <datafield tag="937" ind1=" " ind2=" ">
-    <subfield code="a">Dokumentarfilm</subfield>
-    <subfield code="b">Deutschland</subfield>
-    <subfield code="c">2014</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">000  xxxxxcx  a22     zn 4500</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">001 901795887</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">003  DE-576</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">004  457035137</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">005  20160510125331</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">008  160304||||||||||||||||ger|||||||</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">040  </subfield>
-    <subfield code="a">DE-14</subfield>
-    <subfield code="c">DE-576</subfield>
-    <subfield code="d">DE-14</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">852  </subfield>
-    <subfield code="z">Fernsehmitschnitt: MDR, 04.02.2014. - Beilage</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">852  </subfield>
-    <subfield code="a">DE-14</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">852 1</subfield>
-    <subfield code="9">00</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">866  </subfield>
-    <subfield code="x">ddsu,pn</subfield>
-  </datafield>
-</record>
-UNPATCHED_MARCBLOB
-
-my $patched_marcblob =<<'PATCHED_MARCBLOB';
-<?xml version="1.0"?>
-<record xmlns="http://www.loc.gov/MARC21/slim">
-  <leader>     cgm a22        4500</leader>
-  <controlfield tag="001">457035137</controlfield>
-  <controlfield tag="003">DE-576</controlfield>
-  <controlfield tag="005">20160510144338.0</controlfield>
-  <controlfield tag="006">m     o  | |      </controlfield>
-  <controlfield tag="007">cr uuu---uuuuu</controlfield>
-  <controlfield tag="007">vu uuuuuu</controlfield>
-  <controlfield tag="008">160304s2014    xx ger c</controlfield>
-  <datafield tag="035" ind1=" " ind2=" ">
-    <subfield code="a">(DE-627)1655506501</subfield>
-  </datafield>
-  <datafield tag="035" ind1=" " ind2=" ">
-    <subfield code="a">(DE-576)457035137</subfield>
-  </datafield>
-  <datafield tag="035" ind1=" " ind2=" ">
-    <subfield code="a">(DE-599)BSZ457035137</subfield>
-  </datafield>
-  <datafield tag="035" ind1=" " ind2=" ">
-    <subfield code="a">(OCoLC)946544758</subfield>
-  </datafield>
-  <datafield tag="040" ind1=" " ind2=" ">
-    <subfield code="a">DE-576</subfield>
-    <subfield code="b">ger</subfield>
-    <subfield code="c">DE-576</subfield>
-    <subfield code="e">rda</subfield>
-  </datafield>
-  <datafield tag="041" ind1=" " ind2=" ">
-    <subfield code="a">ger</subfield>
-  </datafield>
-  <datafield tag="245" ind1="1" ind2="4">
-    <subfield code="a">Der Fichtelberg</subfield>
-    <subfield code="b">Berg der unbekannten Rekorrde</subfield>
-    <subfield code="c">ein Film von Dirk Schneider</subfield>
-  </datafield>
-  <datafield tag="264" ind1=" " ind2="1">
-    <subfield code="a">[Leipzig]</subfield>
-    <subfield code="b">top ten tv</subfield>
-    <subfield code="c">[2014]</subfield>
-  </datafield>
-  <datafield tag="264" ind1=" " ind2="4">
-    <subfield code="c">&#xA9; 2014</subfield>
-  </datafield>
-  <datafield tag="300" ind1=" " ind2=" ">
-    <subfield code="a">1 Online-Ressource (1 Videodatei, 29:49)</subfield>
-    <subfield code="b">farbig</subfield>
-  </datafield>
-  <datafield tag="336" ind1=" " ind2=" ">
-    <subfield code="a">zweidimensionales bewegtes Bild</subfield>
-    <subfield code="b">tdi</subfield>
-    <subfield code="2">rdacontent</subfield>
-  </datafield>
-  <datafield tag="337" ind1=" " ind2=" ">
-    <subfield code="a">Computermedien</subfield>
-    <subfield code="b">c</subfield>
-    <subfield code="2">rdamedia</subfield>
-  </datafield>
-  <datafield tag="338" ind1=" " ind2=" ">
-    <subfield code="a">Online-Ressource</subfield>
-    <subfield code="b">cr</subfield>
-    <subfield code="2">rdacarrier</subfield>
-  </datafield>
-  <datafield tag="490" ind1="0" ind2=" ">
-    <subfield code="a">MDR</subfield>
-  </datafield>
-  <datafield tag="490" ind1="0" ind2=" ">
-    <subfield code="a">Der Osten - entdecke wo du lebst</subfield>
-  </datafield>
-  <datafield tag="500" ind1=" " ind2=" ">
-    <subfield code="a">Dokumentarfilm. Deutschland. 2014</subfield>
-  </datafield>
-  <datafield tag="591" ind1=" " ind2=" ">
-    <subfield code="a">Fernsehmitschnitt (SWB)</subfield>
-  </datafield>
-  <datafield tag="655" ind1=" " ind2="7">
-    <subfield code="a">Film</subfield>
-    <subfield code="0">(DE-588)4017102-4</subfield>
-    <subfield code="0">(DE-627)104559683</subfield>
-    <subfield code="0">(DE-576)208918531</subfield>
-    <subfield code="2">gnd-content</subfield>
-  </datafield>
-  <datafield tag="700" ind1="1" ind2=" ">
-    <subfield code="a">Schneider, Dirk</subfield>
-    <subfield code="e">FilmemacherIn</subfield>
-    <subfield code="0">(DE-627)1235502279</subfield>
-    <subfield code="0">(DE-576)165502274</subfield>
-    <subfield code="4">fmk</subfield>
-  </datafield>
-  <datafield tag="935" ind1=" " ind2=" ">
-    <subfield code="c">vide</subfield>
-  </datafield>
-  <datafield tag="937" ind1=" " ind2=" ">
-    <subfield code="a">Dokumentarfilm</subfield>
-    <subfield code="b">Deutschland</subfield>
-    <subfield code="c">2014</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">000  xxxxxcx  a22     zn 4500</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">001 901795887</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">003  DE-576</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">004  457035137</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">005  20160510125331</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">008  160304||||||||||||||||ger|||||||</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">040  </subfield>
-    <subfield code="a">DE-14</subfield>
-    <subfield code="c">DE-576</subfield>
-    <subfield code="d">DE-14</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">852  </subfield>
-    <subfield code="z">Fernsehmitschnitt: MDR, 04.02.2014. - Beilage</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">852  </subfield>
-    <subfield code="a">DE-14</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">852 1</subfield>
-    <subfield code="9">00</subfield>
-  </datafield>
-  <datafield tag="LOK" ind1=" " ind2=" ">
-    <subfield code="0">866  </subfield>
-    <subfield code="x">ddsu,pn</subfield>
-  </datafield>
-</record>
-PATCHED_MARCBLOB
-my $unpatched_marcblob_obj = XML::LibXML->load_xml(string => $unpatched_marcblob);
-
-my $unpatched_marc21slimutils = <<'UNPATCHED_MARC21SLIMUTIL';
-<?xml version='1.0'?>
-<xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim"
-	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
-	<!-- 08/08/08: tmee added corrected chopPunctuation templates for 260c -->
-	<!-- 08/19/04: ntra added "marc:" prefix to datafield element -->
-	<!-- 12/14/07: ntra added url encoding template -->
-	<!-- url encoding -->
-
-	<xsl:variable name="ascii">
-		<xsl:text> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:text>
-	</xsl:variable>
-
-	<xsl:variable name="latin1">
-		<xsl:text> ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:text>
-	</xsl:variable>
-	<!-- Characters that usually don't need to be escaped -->
-	<xsl:variable name="safe">
-		<xsl:text>!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:text>
-	</xsl:variable>
-
-	<xsl:variable name="hex">0123456789ABCDEF</xsl:variable>
-
-
-	<xsl:template name="datafield">
-		<xsl:param name="tag"/>
-		<xsl:param name="ind1">
-			<xsl:text> </xsl:text>
-		</xsl:param>
-		<xsl:param name="ind2">
-			<xsl:text> </xsl:text>
-		</xsl:param>
-		<xsl:param name="subfields"/>
-		<xsl:element name="marc:datafield">
-			<xsl:attribute name="tag">
-				<xsl:value-of select="$tag"/>
-			</xsl:attribute>
-			<xsl:attribute name="ind1">
-				<xsl:value-of select="$ind1"/>
-			</xsl:attribute>
-			<xsl:attribute name="ind2">
-				<xsl:value-of select="$ind2"/>
-			</xsl:attribute>
-			<xsl:copy-of select="$subfields"/>
-		</xsl:element>
-	</xsl:template>
-
-	<xsl:template name="subfieldSelect">
-		<xsl:param name="codes">abcdefghijklmnopqrstuvwxyz</xsl:param>
-		<xsl:param name="delimeter">
-			<xsl:text> </xsl:text>
-		</xsl:param>
-		<xsl:variable name="str">
-			<xsl:for-each select="marc:subfield">
-				<xsl:if test="contains($codes, @code)">
-					<xsl:value-of select="text()"/>
-					<xsl:value-of select="$delimeter"/>
-				</xsl:if>
-			</xsl:for-each>
-		</xsl:variable>
-		<xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
-	</xsl:template>
-
-	<xsl:template name="buildSpaces">
-		<xsl:param name="spaces"/>
-		<xsl:param name="char">
-			<xsl:text> </xsl:text>
-		</xsl:param>
-		<xsl:if test="$spaces>0">
-			<xsl:value-of select="$char"/>
-			<xsl:call-template name="buildSpaces">
-				<xsl:with-param name="spaces" select="$spaces - 1"/>
-				<xsl:with-param name="char" select="$char"/>
-			</xsl:call-template>
-		</xsl:if>
-	</xsl:template>
-
-	<xsl:template name="chopPunctuation">
-		<xsl:param name="chopString"/>
-		<xsl:param name="punctuation">
-			<xsl:text>.:,;/ </xsl:text>
-		</xsl:param>
-		<xsl:variable name="length" select="string-length($chopString)"/>
-		<xsl:choose>
-			<xsl:when test="$length=0"/>
-			<xsl:when test="contains($punctuation, substring($chopString,$length,1))">
-				<xsl:call-template name="chopPunctuation">
-					<xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
-					<xsl:with-param name="punctuation" select="$punctuation"/>
-				</xsl:call-template>
-			</xsl:when>
-			<xsl:when test="not($chopString)"/>
-			<xsl:otherwise>
-				<xsl:value-of select="$chopString"/>
-			</xsl:otherwise>
-		</xsl:choose>
-	</xsl:template>
-
-	<xsl:template name="chopPunctuationFront">
-		<xsl:param name="chopString"/>
-		<xsl:variable name="length" select="string-length($chopString)"/>
-		<xsl:choose>
-			<xsl:when test="$length=0"/>
-			<xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
-				<xsl:call-template name="chopPunctuationFront">
-					<xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"
-					/>
-				</xsl:call-template>
-			</xsl:when>
-			<xsl:when test="not($chopString)"/>
-			<xsl:otherwise>
-				<xsl:value-of select="$chopString"/>
-			</xsl:otherwise>
-		</xsl:choose>
-	</xsl:template>
-
-	<xsl:template name="chopPunctuationBack">
-		<xsl:param name="chopString"/>
-		<xsl:param name="punctuation">
-			<xsl:text>.:,;/] </xsl:text>
-		</xsl:param>
-		<xsl:variable name="length" select="string-length($chopString)"/>
-		<xsl:choose>
-			<xsl:when test="$length=0"/>
-			<xsl:when test="contains($punctuation, substring($chopString,$length,1))">
-				<xsl:call-template name="chopPunctuation">
-					<xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
-					<xsl:with-param name="punctuation" select="$punctuation"/>
-				</xsl:call-template>
-			</xsl:when>
-			<xsl:when test="not($chopString)"/>
-			<xsl:otherwise>
-				<xsl:value-of select="$chopString"/>
-			</xsl:otherwise>
-		</xsl:choose>
-	</xsl:template>
-
-	<!-- nate added 12/14/2007 for lccn.loc.gov: url encode ampersand, etc. -->
-	<xsl:template name="url-encode">
-
-		<xsl:param name="str"/>
-
-		<xsl:if test="$str">
-			<xsl:variable name="first-char" select="substring($str,1,1)"/>
-			<xsl:choose>
-				<xsl:when test="contains($safe,$first-char)">
-					<xsl:value-of select="$first-char"/>
-				</xsl:when>
-				<xsl:otherwise>
-					<xsl:variable name="codepoint">
-						<xsl:choose>
-							<xsl:when test="contains($ascii,$first-char)">
-								<xsl:value-of
-									select="string-length(substring-before($ascii,$first-char)) + 32"
-								/>
-							</xsl:when>
-							<xsl:when test="contains($latin1,$first-char)">
-								<xsl:value-of
-									select="string-length(substring-before($latin1,$first-char)) + 160"/>
-								<!-- was 160 -->
-							</xsl:when>
-							<xsl:otherwise>
-								<xsl:message terminate="no">Warning: string contains a character
-									that is out of range! Substituting "?".</xsl:message>
-								<xsl:text>63</xsl:text>
-							</xsl:otherwise>
-						</xsl:choose>
-					</xsl:variable>
-					<xsl:variable name="hex-digit1"
-						select="substring($hex,floor($codepoint div 16) + 1,1)"/>
-					<xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
-					<!-- <xsl:value-of select="concat('%',$hex-digit2)"/> -->
-					<xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
-				</xsl:otherwise>
-			</xsl:choose>
-			<xsl:if test="string-length($str) &gt; 1">
-				<xsl:call-template name="url-encode">
-					<xsl:with-param name="str" select="substring($str,2)"/>
-				</xsl:call-template>
-			</xsl:if>
-		</xsl:if>
-	</xsl:template>
-</xsl:stylesheet>
-<!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
-<metaInformation>
-<scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
-</metaInformation>
--->
-UNPATCHED_MARC21SLIMUTIL
-
-my $structmap_res = "<mets:structMap TYPE=\"PHYSICAL\">
-  <mets:div ID=\"PHYS_0000\" TYPE=\"ieDir\">
-  <mets:div ID=\"PHYS_000000000000000_LZA\" TYPE=\"fileorderSequence\">
-<mets:fptr FILEID=\"FILE_000000000000000_LZA\" />
-</mets:div>
-  </mets:div>
-</mets:structMap>
-";
-
-my $filesec_res = "<mets:fileSec>
-  <mets:fileGrp USE=\"LZA\">
-  <mets:file ID=\"FILE_000000000000000_LZA\" CHECKSUMTYPE=\"MD5\" CHECKSUM=\"d41d8cd98f00b204e9800998ecf8427e\">
-<mets:FLocat xmlns:xlink=\"http://www.w3.org/1999/xlink\" LOCTYPE=\"URL\" xlink:href=\"file://data/test.txt\"/>
-</mets:file>
-  </mets:fileGrp>
-</mets:fileSec>
-";
-
-my $noppn_dmd_res = "<mets:dmdSec ID=\"DMDLOG_0000\">
-  <!-- bibliographic metadata -->
-  <mets:mdWrap MDTYPE=\"MODS\">
-    <mets:xmlData>
-      <mods version=\"3.6\"
-    xmlns=\"http://www.loc.gov/mods/v3\"
-    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
-    xsi:schemaLocation=\"http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd\">
-    <identifier>string</identifier>
-</mods>
-
-    </mets:xmlData>
-  </mets:mdWrap>
-</mets:dmdSec>
-";
-
-# preparation
-my $xsl_path = path(__FILE__)->parent->parent->child('xsl');
-my $export_dir_kitodo_path = path(__FILE__)->parent->parent->child('export_dir_kitodo');
-my $valid_ie_dir = "10_00-8";
-my $not_valid_ie_dir = "10_00-8+";
-my $valid_ie_dir_path = $export_dir_kitodo_path->absolute . "/" . $valid_ie_dir;
-my $not_valid_ie_dir_path = $export_dir_kitodo_path->absolute . "/" . $not_valid_ie_dir;
-my $file = "test.txt";
-my $file2 = "test+.txt";
-if(! -d $export_dir_kitodo_path) { mkdir $export_dir_kitodo_path or die "Error creating directory: $export_dir_kitodo_path"; }
-if(! -d $export_dir_kitodo_path->child($valid_ie_dir)) { mkdir $export_dir_kitodo_path->child($valid_ie_dir) or die "Error creating directory: $export_dir_kitodo_path->child($valid_ie_dir)"; }
-if(! -f $export_dir_kitodo_path->child($valid_ie_dir)->child($file)) { 
-	open FILE, '>'.$export_dir_kitodo_path->child($valid_ie_dir)->child($file) or die "Unable to create $file"; 
-	close FILE; 
-}	
-if(! -d $export_dir_kitodo_path->child($not_valid_ie_dir)) { mkdir $export_dir_kitodo_path->child($not_valid_ie_dir) or die "Error creating directory: $export_dir_kitodo_path->child($not_valid_ie_dir)"; }
-if(! -f $export_dir_kitodo_path->child($not_valid_ie_dir)->child($file2)) { 
-	open FILE, '>'.$export_dir_kitodo_path->child($not_valid_ie_dir)->child($file2) or die "Unable to create $file"; 
-	close FILE; 
-}
-
-my $mysip_path = path(__FILE__)->parent->parent->child('tmp')->child('mysip');
-if(! -d $mysip_path->parent) { mkdir $mysip_path->parent or die "Error creating directory: tmp";}
-if(! -d $mysip_path) { mkdir $mysip_path or die "Error creating directory: $mysip_path";}
-
-#~ structure of input output folders
-#~ .
-#~ ├── export_dir_kitodo
-#~ │   ├── 10_00-8
-#~ │   │   └── test.txt
-#~ │   │   
-#~ │   └── 10_00-8+
-#~ │	   └── test+.txt
-#~ └── tmp
-#~	   └── mysip
-
-my $ua = LWP::UserAgent->new;
-my $request = HTTP::Request->new('GET' => "https://sru.bsz-bw.de/swbf");
-my $response = $ua->request($request);
-my $marc21slimutils_file = $xsl_path->child('MARC21slimUtils.xsl');
-my $useragent_obj = LWP::UserAgent->new;
-$useragent_obj->agent("MyApp/0.1 ");
-$useragent_obj->timeout(3600); #1h
-my $filecopyhash = SLUB::LZA::SIPBuilder::create_filecopyhash($valid_ie_dir_path, $mysip_path->absolute . "/PPN-457035137_2019-10-14_08-46-50/data");
-# ensure no dir exists, then run test
-if ($xsl_path->is_dir) { $xsl_path->remove_tree; }
-
-### tests
-BEGIN { use_ok("SLUB::LZA::SIPBuilder"); }
-#
-is(SLUB::LZA::SIPBuilder::check_xsl_directory(), $xsl_path->absolute, "check_xsl_directory(), return value if not exist");
-ok($xsl_path->is_dir, "check_xsl_directory(), created if not exist");
-is(SLUB::LZA::SIPBuilder::check_xsl_directory(), $xsl_path->absolute, "check_xsl_directory(), return value if exist");
-ok($xsl_path->is_dir, "check_xsl_directory(), untouched if exist");
-#
-SKIP: {
-	skip "No response from server https://sru.bsz-bw.de/swb", 1 unless ! $response->is_error;
-	like(SLUB::LZA::SIPBuilder::get_mods_from("https://sru.bsz-bw.de/swb", "457035137", "pica.swn", "marcxmlvbos"), qr//, "get_mods_from()");
-};
-throws_ok{ SLUB::LZA::SIPBuilder::get_mods_from("", "457035137", "pica.swn", "marcxmlvbos"); } qr/invalid parameters/, "get_mods_from(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::get_mods_from("https://sru.bsz-bw.de/swb", "", "pica.swn", "marcxmlvbos"); } qr/invalid parameters/, "get_mods_from(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::get_mods_from("https://sru.bsz-bw.de/swb", "457035137", "", "marcxmlvbos"); } qr/invalid parameters/, "get_mods_from(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::get_mods_from("https://sru.bsz-bw.de/swb", "457035137", "pica.swn", ""); } qr/invalid parameters/, "get_mods_from(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::get_mods_from(undef, "457035137", "pica.swn", "marcxmlvbos"); } qr/url not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), url undef";
-throws_ok{ SLUB::LZA::SIPBuilder::get_mods_from("https://sru.bsz-bw.de/swb", undef, "pica.swn", "marcxmlvbos"); } qr/ppn not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), ppn undef";
-throws_ok{ SLUB::LZA::SIPBuilder::get_mods_from("https://sru.bsz-bw.de/swb", "457035137", undef, "marcxmlvbos"); } qr/key not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), key undef";
-throws_ok{ SLUB::LZA::SIPBuilder::get_mods_from("https://sru.bsz-bw.de/swb", "457035137", "pica.swn", undef); } qr/schema not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), schema undef";
-#
-ok(SLUB::LZA::SIPBuilder::write_file($marc21slimutils_file, $unpatched_marc21slimutils), "write_file()");
-throws_ok{ SLUB::LZA::SIPBuilder::write_file("", $unpatched_marc21slimutils); } qr/invalid parameters/, "write_file(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::write_file($marc21slimutils_file, ""); } qr/invalid parameters/, "write_file(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::write_file(undef, $unpatched_marc21slimutils); } qr/filename not defined/, "write_file(\$filename, \$value), filename undef";
-throws_ok{ SLUB::LZA::SIPBuilder::write_file($marc21slimutils_file, undef); } qr/value not defined/, "write_file(\$filename, \$value), value undef";
-#
-is(SLUB::LZA::SIPBuilder::patch_mods($unpatched_mods_obj), $patched_mods, "patch_mods()");
-throws_ok{ SLUB::LZA::SIPBuilder::patch_mods(""); } qr/invalid parameters/, "patch_mods(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::patch_mods(undef); } qr/modsobject not defined/, "patch_mods(\$modsobj), modsobj undef";
-#
-is(SLUB::LZA::SIPBuilder::patch_marc_response($unpatched_marcblob_obj), $patched_marcblob, "patch_marc_response()");
-throws_ok{ SLUB::LZA::SIPBuilder::patch_marc_response(""); } qr/invalid parameters/, "patch_marc_response(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::patch_marc_response(undef); } qr/marcobject not defined/, "patch_marc_response(\$marcobj), marcobj undef";
-#
-is(SLUB::LZA::SIPBuilder::check_marc21_utility($xsl_path, $useragent_obj), $marc21slimutils_file , "check_marc21_utility()");
-throws_ok{ SLUB::LZA::SIPBuilder::check_marc21_utility("", $useragent_obj); } qr/invalid parameters/, "check_marc21_utility(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::check_marc21_utility($xsl_path, ""); } qr/invalid parameters/, "check_marc21_utility(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::check_marc21_utility(undef, $useragent_obj); } qr/xsl directory not defined/, "check_marc21_utility(\$xsl_dir, \$useragent), xsl_dir undef";
-throws_ok{ SLUB::LZA::SIPBuilder::check_marc21_utility($xsl_path, undef); } qr/user agent not defined/, "check_marc21_utility(\$xsl_dir, \$useragent), useragent undef";
-#
-is(SLUB::LZA::SIPBuilder::check_marc21_mods_xsl($xsl_path, $useragent_obj), 'xsl/MARC21slim2MODS3-6.patched.xsl' , "check_marc21_mods_xsl()");
-throws_ok{ SLUB::LZA::SIPBuilder::check_marc21_mods_xsl("", $useragent_obj); } qr/invalid parameters/, "check_marc21_mods_xsl(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::check_marc21_mods_xsl($xsl_path, ""); } qr/invalid parameters/, "check_marc21_mods_xsl(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::check_marc21_mods_xsl(undef, $useragent_obj); } qr/xsl directory not defined/, "check_marc21_mods_xsl(\$xsl_dir, \$useragent), xsl_dir undef";
-throws_ok{ SLUB::LZA::SIPBuilder::check_marc21_mods_xsl($xsl_path, undef); } qr/user agent not defined/, "check_marc21_mods_xsl(\$xsl_dir, \$useragent), useragent undef";
-#
-like(SLUB::LZA::SIPBuilder::create_filecopyhash($valid_ie_dir_path, $mysip_path->absolute . "/PPN-457035137_2019-10-14_08-46-50/data"), qr/HASH/, "create_filecopyhash()");
-throws_ok{ SLUB::LZA::SIPBuilder::create_filecopyhash("", $mysip_path->absolute . "/PPN-457035137_2019-10-14_08-46-50/data"); } qr/invalid parameters/, "create_filecopyhash(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::create_filecopyhash($valid_ie_dir_path, ""); } qr/invalid parameters/, "create_filecopyhash(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::create_filecopyhash($valid_ie_dir_path, undef); } qr/content not defined/, "create_filecopyhash(\$directory, \$content), content undef";
-throws_ok{ SLUB::LZA::SIPBuilder::create_filecopyhash(undef, $mysip_path->absolute . "/PPN-number_date_time/data"); } qr/directory not defined/, "create_filecopyhash(\$directory, \$content), directory undef";
-#
-SKIP: {
-	skip "No response from server https://sru.bsz-bw.de/swb", 1 unless ! $response->is_error;
-	like(SLUB::LZA::SIPBuilder::prepare_dmd_section_with_ppn("457035137"), qr//, "prepare_dmd_section_with_ppn()");
-};
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_dmd_section_with_ppn(""); } qr/invalid parameters/, "prepare_dmd_section_with_ppn(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_dmd_section_with_ppn(undef); } qr/ppn not defined/, "prepare_dmd_section_with_ppn(\$ppn), ppn undef";
-#
-ok(SLUB::LZA::SIPBuilder::prepare_dmd_section_with_noppn("string") eq $noppn_dmd_res, "prepare_dmd_section_with_noppn()");
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_files_sections(""); } qr/Can't use string/, "prepare_dmd_section_with_noppn(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_dmd_section_with_noppn(undef); } qr/noppn not defined/, "prepare_dmd_section_with_noppn(\$noppn), noppn undef";
-#
-like(SLUB::LZA::SIPBuilder::prepare_amd_section("2019-10-14T13:33:56", "kitodo", "10008", "false", "DE-14", "Gesetzlicher Auftrag"), qr//, "prepare_amd_section()");
-like(SLUB::LZA::SIPBuilder::prepare_amd_section("2019-10-14T13:33:56", "kitodo", "10008", "false", "", "Gesetzlicher Auftrag"), qr//, "prepare_amd_section() with no externel_isil");
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_amd_section("", "kitodo", "10008", "false", "DE-14", "Gesetzlicher Auftrag"); } qr/invalid parameters/, "prepare_amd_section(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_amd_section("2019-10-14T13:33:56", "", "10008", "false", "DE-14", "Gesetzlicher Auftrag"); } qr/invalid parameters/, "prepare_amd_section(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_amd_section("2019-10-14T13:33:56", "kitodo", "", "false", "DE-14", "Gesetzlicher Auftrag"); } qr/invalid parameters/, "prepare_amd_section(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_amd_section("2019-10-14T13:33:56", "kitodo", "10008", "", "DE-14", "Gesetzlicher Auftrag"); } qr/invalid parameters/, "prepare_amd_section(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_amd_section("2019-10-14T13:33:56", "kitodo", "10008", "false", "DE-14", ""); } qr/invalid parameters/, "prepare_amd_section(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_amd_section(undef, "kitodo", "10008", "false", "DE-14", "Gesetzlicher Auftrag"); } qr/export to archive date not defined/, "prepare_amd_section(\$export_to_archive_date, \$external_workflow, \$external_id, \$external_conservation_flag, \$external_isil, \$external_value_descr), export_to_archive_date undef";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_amd_section("2019-10-14T13:33:56", undef, "10008", "false", "DE-14", "Gesetzlicher Auftrag"); } qr/external workflow not defined/, "prepare_amd_section(\$export_to_archive_date, \$external_workflow, \$external_id, \$external_conservation_flag, \$external_isil, \$external_value_descr), external_workflow undef";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_amd_section("2019-10-14T13:33:56", "kitodo", undef, "false", "DE-14", "Gesetzlicher Auftrag"); } qr/external id not defined/, "prepare_amd_section(\$export_to_archive_date, \$external_workflow, \$external_id, \$external_conservation_flag, \$external_isil, \$external_value_descr), external_id undef";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_amd_section("2019-10-14T13:33:56", "kitodo", "10008", undef, "DE-14", "Gesetzlicher Auftrag"); } qr/external conservation flag not defined/, "prepare_amd_section(\$export_to_archive_date, \$external_workflow, \$external_id, \$external_conservation_flag, \$external_isil, \$external_value_descr), external_conservation_flag undef";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_amd_section("2019-10-14T13:33:56", "kitodo", "10008", "false", undef, "Gesetzlicher Auftrag"); } qr/external isil not defined/, "prepare_amd_section(\$export_to_archive_date, \$external_workflow, \$external_id, \$external_conservation_flag, \$external_isil, \$external_value_descr), external_isil undef";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_amd_section("2019-10-14T13:33:56", "kitodo", "10008", "false", "DE-14", undef); } qr/external value description not defined/, "prepare_amd_section(\$export_to_archive_date, \$external_workflow, \$external_id, \$external_conservation_flag, \$external_isil, \$external_value_descr), external_value_descr undef";
-#
-ok(SLUB::LZA::SIPBuilder::prepare_files_sections($filecopyhash) eq $filesec_res, "prepare_files_sections()");
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_files_sections(""); } qr/Can't use string/, "prepare_files_sections(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_files_sections(\$filecopyhash); } qr/Not a HASH reference/, "prepare_files_sections(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_files_sections(undef); } qr/filecopyhash not defined/, "prepare_files_sections(\$filecopyhash), filecopyhash undef";
-#
-ok(SLUB::LZA::SIPBuilder::prepare_struct_map($filecopyhash) eq $structmap_res, "prepare_struct_map()");
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_struct_map(""); } qr/Can't use string/, "prepare_struct_map(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_struct_map(\$filecopyhash); } qr/Not a HASH reference/, "prepare_struct_map(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::prepare_struct_map(undef); } qr/filecopyhash not defined/, "prepare_struct_map(\$filecopyhash), filecopyhash undef";
-#
-is(SLUB::LZA::SIPBuilder::check_directory($valid_ie_dir_path, $valid_ie_dir), "", "check_directory()");
-throws_ok{ SLUB::LZA::SIPBuilder::check_directory("", $valid_ie_dir); } qr/invalid parameters/, "check_directory(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::check_directory($valid_ie_dir_path, ""); } qr/invalid parameters/, "check_directory(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::check_directory(undef, $valid_ie_dir); } qr/fullname not defined/, "check_directory(\$valid_ie_dir_path, \$valid_ie_dir), valid_ie_dir_path undef";
-throws_ok{ SLUB::LZA::SIPBuilder::check_directory($valid_ie_dir_path, undef); } qr/entry not defined/, "check_directory(\$valid_ie_dir_path, \$valid_ie_dir), valid_ie_dir undef";
-like(SLUB::LZA::SIPBuilder::check_directory($export_dir_kitodo_path->absolute . "/LFvNRFgzZQ6nXnK0wvOXqYGA3jBuHrQWWkw2ngWL/5CglQ5VNjq1kCNTVPhcRDYy59PpQg/0g9XWHBkgunA4FXGefoX5RToHrXgE6cY35wLdviFjE2gAf9mpQSTnC/hpH4omOsAl6I9UfU4HYoo4drqLGjn0QP80SPm6TRWThtKmb6dj7iWm1UfFOo9W19vcCQQIcz/1Aa_080B-", "1Aa_080B-"), qr/expected maximum 255 characters/, "validate_directory(\$valid_ie_dir_path, \$valid_ie_dir), expected valid_ie_dir_path max 255 characters");
-like(SLUB::LZA::SIPBuilder::check_directory($not_valid_ie_dir_path, $not_valid_ie_dir), qr/you need to specify/, "check_directory(\$valid_ie_dir_path, \$valid_ie_dir), file or directory must be valid to (^[A-Za-z0-9_.-]+\$)");
-like(SLUB::LZA::SIPBuilder::check_directory($valid_ie_dir_path . "/../", $valid_ie_dir), qr/relativ path/, "check_directory(\$valid_ie_dir_path, \$valid_ie_dir), relative path in form ../ is not allowed");
-#
-is(SLUB::LZA::SIPBuilder::validate_directory($valid_ie_dir_path), "", "validate_directory()");
-throws_ok{ SLUB::LZA::SIPBuilder::validate_directory(""); } qr/Could not find/, "validate_directory(), invalid parameters";
-throws_ok{ SLUB::LZA::SIPBuilder::validate_directory(undef); } qr/directory not defined/, "validate_directory(\$directory), directory undef";
-
-1;
diff --git a/t/slubsipbuilderbagit.t b/t/slubsipbuilderbagit.t
new file mode 100644
index 0000000000000000000000000000000000000000..8918a321403578ff8908b71eb37d63e3438e59bf
--- /dev/null
+++ b/t/slubsipbuilderbagit.t
@@ -0,0 +1,683 @@
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+use diagnostics;
+
+use Test::More tests => 78;
+use Test::Output;
+use Test::Exception;
+use Test::File;
+use Path::Tiny;
+use File::Copy::Recursive;  # for dircopy()
+use File::Path qw(rmtree);
+
+
+# *** Read before running tests ***
+# Usage: perl -I lib/ t/slubsipbuilderbagit.t 
+# Warning: While running project "SLUB_SIP_Builder" two directories "export_dir_kitodo/bagit" and "tmp/bagit" will be created.
+# Start scipt in the project directory to run all tests properly. 
+
+### prepare
+BEGIN {
+    use Path::Tiny;
+    push @INC, Path::Tiny::path(__FILE__)->parent->parent->path("bin")->absolute->stringify;
+    require "slubsipbuilderbagit.pl";
+    $INC{'SLUB/LZA/SIPBuilderBagIt.pm'} = 1; # needed because inlined module
+}
+my $unpatched_mods=<<'UNPATCHED_MODS';
+<?xml version="1.0" encoding="UTF-8"?>
+<mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/mods/v3" version="3.6" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd"><titleInfo><nonSort xml:space="preserve">Der  </nonSort><title>Fichtelberg</title><subTitle>Berg der unbekannten Rekorrde</subTitle></titleInfo><name type="personal"><namePart>Schneider, Dirk</namePart><role><roleTerm type="text">FilmemacherIn</roleTerm></role><role><roleTerm authority="marcrelator" type="code">fmk</roleTerm></role><nameIdentifier>(DE-627)1235502279 (DE-576)165502274</nameIdentifier></name><typeOfResource>moving image</typeOfResource><genre authority="rdacontent">zweidimensionales bewegtes Bild</genre><genre authority="gnd-content">Film</genre><originInfo><place><placeTerm type="code" authority="marccountry">xx</placeTerm></place><dateIssued encoding="marc">2014</dateIssued><issuance>monographic</issuance></originInfo><originInfo eventType="publication"><place><placeTerm type="text">[Leipzig]</placeTerm></place><publisher>top ten tv</publisher><dateIssued>[2014]</dateIssued></originInfo><language><languageTerm authority="iso639-2b" type="code">ger</languageTerm></language><physicalDescription><form authority="marccategory">electronic resource</form><form authority="marcsmd">remote</form><extent>1 Online-Ressource (1 Videodatei, 29:49) farbig</extent><form type="media" authority="rdamedia">Computermedien</form><form type="carrier" authority="rdacarrier">Online-Ressource</form></physicalDescription><targetAudience authority="marctarget">juvenile</targetAudience><note type="statement of responsibility" altRepGroup="00">ein Film von Dirk Schneider</note><note>Dokumentarfilm. Deutschland. 2014</note><relatedItem type="series"><titleInfo><title>MDR</title></titleInfo></relatedItem><relatedItem type="series"><titleInfo><title>Der Osten - entdecke wo du lebst</title></titleInfo></relatedItem><identifier type="oclc">946544758</identifier><recordInfo><descriptionStandard>rda</descriptionStandard><recordContentSource authority="marcorg">DE-576</recordContentSource><recordCreationDate encoding="marc">160304</recordCreationDate><recordChangeDate encoding="iso8601">20160510144338.0</recordChangeDate><recordIdentifier source="DE-576">457035137</recordIdentifier><recordOrigin>Converted from MARCXML to MODS version 3.6 using MARC21slim2MODS3-6.xsl
+                (Revision 1.119 2018/06/21)</recordOrigin><languageOfCataloging><languageTerm authority="iso639-2b" type="code">ger</languageTerm></languageOfCataloging></recordInfo></mods>
+UNPATCHED_MODS
+my $patched_mods=<<'PATCHED_MODS';
+<?xml version="1.0" encoding="UTF-8"?>
+<mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/mods/v3" version="3.6" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd"><titleInfo><nonSort xml:space="preserve">Der  </nonSort><title>Fichtelberg</title><subTitle>Berg der unbekannten Rekorrde</subTitle></titleInfo><name type="personal"><namePart>Schneider, Dirk</namePart><role><roleTerm type="text">FilmemacherIn</roleTerm></role><role><roleTerm authority="marcrelator" type="code">fmk</roleTerm></role><nameIdentifier>(DE-627)1235502279 (DE-576)165502274</nameIdentifier></name><typeOfResource>moving image</typeOfResource><genre authority="rdacontent">zweidimensionales bewegtes Bild</genre><genre authority="gnd-content">Film</genre><originInfo><place><placeTerm type="code" authority="marccountry">xx</placeTerm></place><dateIssued encoding="marc">2014</dateIssued><issuance>monographic</issuance></originInfo><originInfo eventType="publication"><place><placeTerm type="text">[Leipzig]</placeTerm></place><publisher>top ten tv</publisher><dateIssued>[2014]</dateIssued></originInfo><language><languageTerm authority="iso639-2b" type="code">ger</languageTerm></language><physicalDescription><form authority="marccategory">electronic resource</form><form authority="marcsmd">remote</form><extent>1 Online-Ressource (1 Videodatei, 29:49) farbig</extent><form type="media" authority="rdamedia">Computermedien</form><form type="carrier" authority="rdacarrier">Online-Ressource</form></physicalDescription><targetAudience authority="marctarget">juvenile</targetAudience><note type="statement of responsibility" altRepGroup="00">ein Film von Dirk Schneider</note><note>Dokumentarfilm. Deutschland. 2014</note><relatedItem type="series"><titleInfo><title>MDR</title></titleInfo></relatedItem><relatedItem type="series"><titleInfo><title>Der Osten - entdecke wo du lebst</title></titleInfo></relatedItem><identifier type="oclc">946544758</identifier><recordInfo><descriptionStandard>rda</descriptionStandard><recordContentSource authority="marcorg">DE-576</recordContentSource><recordCreationDate encoding="marc">160304</recordCreationDate><recordChangeDate encoding="iso8601">20160510144338.0</recordChangeDate><recordIdentifier source="DE-576">457035137</recordIdentifier><recordOrigin>Converted from MARCXML to MODS version 3.6 using MARC21slim2MODS3-6.xsl
+                (Revision 1.119 2018/06/21)</recordOrigin><languageOfCataloging><languageTerm authority="iso639-2b" type="code">ger</languageTerm></languageOfCataloging></recordInfo></mods>
+PATCHED_MODS
+my $unpatched_mods_obj = XML::LibXML->load_xml(string => $unpatched_mods);
+
+my $unpatched_marcblob=<<'UNPATCHED_MARCBLOB';
+<?xml version="1.0"?>
+<record xmlns="http://www.loc.gov/MARC21/slim">
+  <leader>     cgm a22        4500</leader>
+  <controlfield tag="001">457035137</controlfield>
+  <controlfield tag="003">DE-576</controlfield>
+  <controlfield tag="005">20160510144338.0</controlfield>
+  <controlfield tag="006">m     o  | |      </controlfield>
+  <controlfield tag="007">cr uuu---uuuuu</controlfield>
+  <controlfield tag="007">vu uuuuuu</controlfield>
+  <controlfield tag="008">160304s2014    xx ger c</controlfield>
+  <datafield tag="035" ind1=" " ind2=" ">
+    <subfield code="a">(DE-627)1655506501</subfield>
+  </datafield>
+  <datafield tag="035" ind1=" " ind2=" ">
+    <subfield code="a">(DE-576)457035137</subfield>
+  </datafield>
+  <datafield tag="035" ind1=" " ind2=" ">
+    <subfield code="a">(DE-599)BSZ457035137</subfield>
+  </datafield>
+  <datafield tag="035" ind1=" " ind2=" ">
+    <subfield code="a">(OCoLC)946544758</subfield>
+  </datafield>
+  <datafield tag="040" ind1=" " ind2=" ">
+    <subfield code="a">DE-576</subfield>
+    <subfield code="b">ger</subfield>
+    <subfield code="c">DE-576</subfield>
+    <subfield code="e">rda</subfield>
+  </datafield>
+  <datafield tag="041" ind1=" " ind2=" ">
+    <subfield code="a">ger</subfield>
+  </datafield>
+  <datafield tag="245" ind1="1" ind2="4">
+    <subfield code="a">Der Fichtelberg</subfield>
+    <subfield code="b">Berg der unbekannten Rekorrde</subfield>
+    <subfield code="c">ein Film von Dirk Schneider</subfield>
+  </datafield>
+  <datafield tag="264" ind1=" " ind2="1">
+    <subfield code="a">[Leipzig]</subfield>
+    <subfield code="b">top ten tv</subfield>
+    <subfield code="c">[2014]</subfield>
+  </datafield>
+  <datafield tag="264" ind1=" " ind2="4">
+    <subfield code="c">&#xA9; 2014</subfield>
+  </datafield>
+  <datafield tag="300" ind1=" " ind2=" ">
+    <subfield code="a">1 Online-Ressource (1 Videodatei, 29:49)</subfield>
+    <subfield code="b">farbig</subfield>
+  </datafield>
+  <datafield tag="336" ind1=" " ind2=" ">
+    <subfield code="a">zweidimensionales bewegtes Bild</subfield>
+    <subfield code="b">tdi</subfield>
+    <subfield code="2">rdacontent</subfield>
+  </datafield>
+  <datafield tag="337" ind1=" " ind2=" ">
+    <subfield code="a">Computermedien</subfield>
+    <subfield code="b">c</subfield>
+    <subfield code="2">rdamedia</subfield>
+  </datafield>
+  <datafield tag="338" ind1=" " ind2=" ">
+    <subfield code="a">Online-Ressource</subfield>
+    <subfield code="b">cr</subfield>
+    <subfield code="2">rdacarrier</subfield>
+  </datafield>
+  <datafield tag="490" ind1="0" ind2=" ">
+    <subfield code="a">MDR</subfield>
+  </datafield>
+  <datafield tag="490" ind1="0" ind2=" ">
+    <subfield code="a">Der Osten - entdecke wo du lebst</subfield>
+  </datafield>
+  <datafield tag="500" ind1=" " ind2=" ">
+    <subfield code="a">Dokumentarfilm. Deutschland. 2014</subfield>
+  </datafield>
+  <datafield tag="591" ind1=" " ind2=" ">
+    <subfield code="a">Fernsehmitschnitt (SWB)</subfield>
+  </datafield>
+  <datafield tag="655" ind1=" " ind2="7">
+    <subfield code="a">Film</subfield>
+    <subfield code="0">(DE-588)4017102-4</subfield>
+    <subfield code="0">(DE-627)104559683</subfield>
+    <subfield code="0">(DE-576)208918531</subfield>
+    <subfield code="2">gnd-content</subfield>
+  </datafield>
+  <datafield tag="700" ind1="1" ind2=" ">
+    <subfield code="a">Schneider, Dirk</subfield>
+    <subfield code="e">FilmemacherIn</subfield>
+    <subfield code="0">(DE-627)1235502279</subfield>
+    <subfield code="0">(DE-576)165502274</subfield>
+    <subfield code="4">fmk</subfield>
+  </datafield>
+  <datafield tag="935" ind1=" " ind2=" ">
+    <subfield code="c">vide</subfield>
+  </datafield>
+  <datafield tag="937" ind1=" " ind2=" ">
+    <subfield code="a">Dokumentarfilm</subfield>
+    <subfield code="b">Deutschland</subfield>
+    <subfield code="c">2014</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">000  xxxxxcx  a22     zn 4500</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">001 901795887</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">003  DE-576</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">004  457035137</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">005  20160510125331</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">008  160304||||||||||||||||ger|||||||</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">040  </subfield>
+    <subfield code="a">DE-14</subfield>
+    <subfield code="c">DE-576</subfield>
+    <subfield code="d">DE-14</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">852  </subfield>
+    <subfield code="z">Fernsehmitschnitt: MDR, 04.02.2014. - Beilage</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">852  </subfield>
+    <subfield code="a">DE-14</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">852 1</subfield>
+    <subfield code="9">00</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">866  </subfield>
+    <subfield code="x">ddsu,pn</subfield>
+  </datafield>
+</record>
+UNPATCHED_MARCBLOB
+
+my $patched_marcblob =<<'PATCHED_MARCBLOB';
+<?xml version="1.0"?>
+<record xmlns="http://www.loc.gov/MARC21/slim">
+  <leader>     cgm a22        4500</leader>
+  <controlfield tag="001">457035137</controlfield>
+  <controlfield tag="003">DE-576</controlfield>
+  <controlfield tag="005">20160510144338.0</controlfield>
+  <controlfield tag="006">m     o  | |      </controlfield>
+  <controlfield tag="007">cr uuu---uuuuu</controlfield>
+  <controlfield tag="007">vu uuuuuu</controlfield>
+  <controlfield tag="008">160304s2014    xx ger c</controlfield>
+  <datafield tag="035" ind1=" " ind2=" ">
+    <subfield code="a">(DE-627)1655506501</subfield>
+  </datafield>
+  <datafield tag="035" ind1=" " ind2=" ">
+    <subfield code="a">(DE-576)457035137</subfield>
+  </datafield>
+  <datafield tag="035" ind1=" " ind2=" ">
+    <subfield code="a">(DE-599)BSZ457035137</subfield>
+  </datafield>
+  <datafield tag="035" ind1=" " ind2=" ">
+    <subfield code="a">(OCoLC)946544758</subfield>
+  </datafield>
+  <datafield tag="040" ind1=" " ind2=" ">
+    <subfield code="a">DE-576</subfield>
+    <subfield code="b">ger</subfield>
+    <subfield code="c">DE-576</subfield>
+    <subfield code="e">rda</subfield>
+  </datafield>
+  <datafield tag="041" ind1=" " ind2=" ">
+    <subfield code="a">ger</subfield>
+  </datafield>
+  <datafield tag="245" ind1="1" ind2="4">
+    <subfield code="a">Der Fichtelberg</subfield>
+    <subfield code="b">Berg der unbekannten Rekorrde</subfield>
+    <subfield code="c">ein Film von Dirk Schneider</subfield>
+  </datafield>
+  <datafield tag="264" ind1=" " ind2="1">
+    <subfield code="a">[Leipzig]</subfield>
+    <subfield code="b">top ten tv</subfield>
+    <subfield code="c">[2014]</subfield>
+  </datafield>
+  <datafield tag="264" ind1=" " ind2="4">
+    <subfield code="c">&#xA9; 2014</subfield>
+  </datafield>
+  <datafield tag="300" ind1=" " ind2=" ">
+    <subfield code="a">1 Online-Ressource (1 Videodatei, 29:49)</subfield>
+    <subfield code="b">farbig</subfield>
+  </datafield>
+  <datafield tag="336" ind1=" " ind2=" ">
+    <subfield code="a">zweidimensionales bewegtes Bild</subfield>
+    <subfield code="b">tdi</subfield>
+    <subfield code="2">rdacontent</subfield>
+  </datafield>
+  <datafield tag="337" ind1=" " ind2=" ">
+    <subfield code="a">Computermedien</subfield>
+    <subfield code="b">c</subfield>
+    <subfield code="2">rdamedia</subfield>
+  </datafield>
+  <datafield tag="338" ind1=" " ind2=" ">
+    <subfield code="a">Online-Ressource</subfield>
+    <subfield code="b">cr</subfield>
+    <subfield code="2">rdacarrier</subfield>
+  </datafield>
+  <datafield tag="490" ind1="0" ind2=" ">
+    <subfield code="a">MDR</subfield>
+  </datafield>
+  <datafield tag="490" ind1="0" ind2=" ">
+    <subfield code="a">Der Osten - entdecke wo du lebst</subfield>
+  </datafield>
+  <datafield tag="500" ind1=" " ind2=" ">
+    <subfield code="a">Dokumentarfilm. Deutschland. 2014</subfield>
+  </datafield>
+  <datafield tag="591" ind1=" " ind2=" ">
+    <subfield code="a">Fernsehmitschnitt (SWB)</subfield>
+  </datafield>
+  <datafield tag="655" ind1=" " ind2="7">
+    <subfield code="a">Film</subfield>
+    <subfield code="0">(DE-588)4017102-4</subfield>
+    <subfield code="0">(DE-627)104559683</subfield>
+    <subfield code="0">(DE-576)208918531</subfield>
+    <subfield code="2">gnd-content</subfield>
+  </datafield>
+  <datafield tag="700" ind1="1" ind2=" ">
+    <subfield code="a">Schneider, Dirk</subfield>
+    <subfield code="e">FilmemacherIn</subfield>
+    <subfield code="0">(DE-627)1235502279</subfield>
+    <subfield code="0">(DE-576)165502274</subfield>
+    <subfield code="4">fmk</subfield>
+  </datafield>
+  <datafield tag="935" ind1=" " ind2=" ">
+    <subfield code="c">vide</subfield>
+  </datafield>
+  <datafield tag="937" ind1=" " ind2=" ">
+    <subfield code="a">Dokumentarfilm</subfield>
+    <subfield code="b">Deutschland</subfield>
+    <subfield code="c">2014</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">000  xxxxxcx  a22     zn 4500</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">001 901795887</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">003  DE-576</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">004  457035137</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">005  20160510125331</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">008  160304||||||||||||||||ger|||||||</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">040  </subfield>
+    <subfield code="a">DE-14</subfield>
+    <subfield code="c">DE-576</subfield>
+    <subfield code="d">DE-14</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">852  </subfield>
+    <subfield code="z">Fernsehmitschnitt: MDR, 04.02.2014. - Beilage</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">852  </subfield>
+    <subfield code="a">DE-14</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">852 1</subfield>
+    <subfield code="9">00</subfield>
+  </datafield>
+  <datafield tag="LOK" ind1=" " ind2=" ">
+    <subfield code="0">866  </subfield>
+    <subfield code="x">ddsu,pn</subfield>
+  </datafield>
+</record>
+PATCHED_MARCBLOB
+my $unpatched_marcblob_obj = XML::LibXML->load_xml(string => $unpatched_marcblob);
+
+my $unpatched_marc21slimutils = <<'UNPATCHED_MARC21SLIMUTIL';
+<?xml version='1.0'?>
+<xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim"
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+    <!-- 08/08/08: tmee added corrected chopPunctuation templates for 260c -->
+    <!-- 08/19/04: ntra added "marc:" prefix to datafield element -->
+    <!-- 12/14/07: ntra added url encoding template -->
+    <!-- url encoding -->
+
+    <xsl:variable name="ascii">
+        <xsl:text> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:text>
+    </xsl:variable>
+
+    <xsl:variable name="latin1">
+        <xsl:text> ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:text>
+    </xsl:variable>
+    <!-- Characters that usually don't need to be escaped -->
+    <xsl:variable name="safe">
+        <xsl:text>!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:text>
+    </xsl:variable>
+
+    <xsl:variable name="hex">0123456789ABCDEF</xsl:variable>
+
+
+    <xsl:template name="datafield">
+        <xsl:param name="tag"/>
+        <xsl:param name="ind1">
+            <xsl:text> </xsl:text>
+        </xsl:param>
+        <xsl:param name="ind2">
+            <xsl:text> </xsl:text>
+        </xsl:param>
+        <xsl:param name="subfields"/>
+        <xsl:element name="marc:datafield">
+            <xsl:attribute name="tag">
+                <xsl:value-of select="$tag"/>
+            </xsl:attribute>
+            <xsl:attribute name="ind1">
+                <xsl:value-of select="$ind1"/>
+            </xsl:attribute>
+            <xsl:attribute name="ind2">
+                <xsl:value-of select="$ind2"/>
+            </xsl:attribute>
+            <xsl:copy-of select="$subfields"/>
+        </xsl:element>
+    </xsl:template>
+
+    <xsl:template name="subfieldSelect">
+        <xsl:param name="codes">abcdefghijklmnopqrstuvwxyz</xsl:param>
+        <xsl:param name="delimeter">
+            <xsl:text> </xsl:text>
+        </xsl:param>
+        <xsl:variable name="str">
+            <xsl:for-each select="marc:subfield">
+                <xsl:if test="contains($codes, @code)">
+                    <xsl:value-of select="text()"/>
+                    <xsl:value-of select="$delimeter"/>
+                </xsl:if>
+            </xsl:for-each>
+        </xsl:variable>
+        <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
+    </xsl:template>
+
+    <xsl:template name="buildSpaces">
+        <xsl:param name="spaces"/>
+        <xsl:param name="char">
+            <xsl:text> </xsl:text>
+        </xsl:param>
+        <xsl:if test="$spaces>0">
+            <xsl:value-of select="$char"/>
+            <xsl:call-template name="buildSpaces">
+                <xsl:with-param name="spaces" select="$spaces - 1"/>
+                <xsl:with-param name="char" select="$char"/>
+            </xsl:call-template>
+        </xsl:if>
+    </xsl:template>
+
+    <xsl:template name="chopPunctuation">
+        <xsl:param name="chopString"/>
+        <xsl:param name="punctuation">
+            <xsl:text>.:,;/ </xsl:text>
+        </xsl:param>
+        <xsl:variable name="length" select="string-length($chopString)"/>
+        <xsl:choose>
+            <xsl:when test="$length=0"/>
+            <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
+                    <xsl:with-param name="punctuation" select="$punctuation"/>
+                </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="not($chopString)"/>
+            <xsl:otherwise>
+                <xsl:value-of select="$chopString"/>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="chopPunctuationFront">
+        <xsl:param name="chopString"/>
+        <xsl:variable name="length" select="string-length($chopString)"/>
+        <xsl:choose>
+            <xsl:when test="$length=0"/>
+            <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
+                <xsl:call-template name="chopPunctuationFront">
+                    <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"
+                    />
+                </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="not($chopString)"/>
+            <xsl:otherwise>
+                <xsl:value-of select="$chopString"/>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="chopPunctuationBack">
+        <xsl:param name="chopString"/>
+        <xsl:param name="punctuation">
+            <xsl:text>.:,;/] </xsl:text>
+        </xsl:param>
+        <xsl:variable name="length" select="string-length($chopString)"/>
+        <xsl:choose>
+            <xsl:when test="$length=0"/>
+            <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
+                    <xsl:with-param name="punctuation" select="$punctuation"/>
+                </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="not($chopString)"/>
+            <xsl:otherwise>
+                <xsl:value-of select="$chopString"/>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <!-- nate added 12/14/2007 for lccn.loc.gov: url encode ampersand, etc. -->
+    <xsl:template name="url-encode">
+
+        <xsl:param name="str"/>
+
+        <xsl:if test="$str">
+            <xsl:variable name="first-char" select="substring($str,1,1)"/>
+            <xsl:choose>
+                <xsl:when test="contains($safe,$first-char)">
+                    <xsl:value-of select="$first-char"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:variable name="codepoint">
+                        <xsl:choose>
+                            <xsl:when test="contains($ascii,$first-char)">
+                                <xsl:value-of
+                                    select="string-length(substring-before($ascii,$first-char)) + 32"
+                                />
+                            </xsl:when>
+                            <xsl:when test="contains($latin1,$first-char)">
+                                <xsl:value-of
+                                    select="string-length(substring-before($latin1,$first-char)) + 160"/>
+                                <!-- was 160 -->
+                            </xsl:when>
+                            <xsl:otherwise>
+                                <xsl:message terminate="no">Warning: string contains a character
+                                    that is out of range! Substituting "?".</xsl:message>
+                                <xsl:text>63</xsl:text>
+                            </xsl:otherwise>
+                        </xsl:choose>
+                    </xsl:variable>
+                    <xsl:variable name="hex-digit1"
+                        select="substring($hex,floor($codepoint div 16) + 1,1)"/>
+                    <xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
+                    <!-- <xsl:value-of select="concat('%',$hex-digit2)"/> -->
+                    <xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
+                </xsl:otherwise>
+            </xsl:choose>
+            <xsl:if test="string-length($str) &gt; 1">
+                <xsl:call-template name="url-encode">
+                    <xsl:with-param name="str" select="substring($str,2)"/>
+                </xsl:call-template>
+            </xsl:if>
+        </xsl:if>
+    </xsl:template>
+</xsl:stylesheet>
+<!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
+<metaInformation>
+<scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
+</metaInformation>
+-->
+UNPATCHED_MARC21SLIMUTIL
+
+my $noppn_mods_res = "<mods version=\"3.6\"
+    xmlns=\"http://www.loc.gov/mods/v3\"
+    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
+    xsi:schemaLocation=\"http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd\">
+    <identifier>string</identifier>
+</mods>
+";
+
+# preparation
+my $xsl_path = path(__FILE__)->parent->parent->child('xsl');
+# input
+my $export_dir_kitodo_path = path(__FILE__)->parent->parent->child('export_dir_kitodo');
+if(! -d $export_dir_kitodo_path) { mkdir $export_dir_kitodo_path or die "Error creating directory: $export_dir_kitodo_path"; }
+my $input_path = path(__FILE__)->parent->parent->child('export_dir_kitodo')->child('bagit');
+if(! -d $input_path) { mkdir $input_path or die "Error creating directory: $input_path"; }
+# output
+my $output_path = path(__FILE__)->parent->parent->child('tmp')->child('bagit');
+if(! -d $output_path->parent) { mkdir $output_path->parent or die "Error creating directory: tmp";}
+if(! -d $output_path) { mkdir $output_path or die "Error creating directory: $output_path";}
+# create ie
+my $ie = 'test';
+my @addBagInfo;
+push @addBagInfo, {'SLUBArchiv-sipVersion' => 'v2020.1'};
+push @addBagInfo, {'Author' => 'Taras Schevchenko'};
+my $ie_input_path = $input_path . '/' . $ie;
+my $ie_output_path = $output_path . '/' . $ie;
+my $file_name = $ie_output_path . '/data/' . 'test.txt';
+if(! -d $input_path->child("test")){ mkdir $input_path->child("test") or die "Error creating directory: " . $input_path->child("test"); }
+if(! -d $input_path->child("test")->child("data")){ mkdir $input_path->child("test")->child("data") or die "Error creating directory: " . $input_path->child("test")->("data"); }
+if(! -f $input_path->child("test")->child("data")->child("test.txt")) { 
+    open(my $fh, '>:encoding(UTF-8)', $input_path->child("test")->child("data")->child("test.txt")) or die "Could not open file " . $input_path->child("test")->child("data")->child("test.txt") . " $!";
+    print $fh "test file for payload.\n";
+    close $fh; 
+}
+if(! -d $input_path->child("test")->child("meta")){ mkdir $input_path->child("test")->child("meta") or die "Error creating directory: " . $input_path->child("test")->child("meta"); }
+# copy Fallbeispiele-*.xml (as rights.xml) file to output_path/meta
+my $rightsXMLPath = path(__FILE__)->parent->realpath->parent->child("export_dir_kitodo")->child("bagit")->child("rights");    # absolute path
+File::Copy::Recursive::dircopy($rightsXMLPath, "$ie_input_path/meta") or die "Could not perform dircopy() of $rightsXMLPath to $ie_input_path/meta: $!";
+# copy other meta files to output_path/meta
+my $otherMetaPath = path(__FILE__)->parent->realpath->parent->child("export_dir_kitodo")->child("bagit")->child("meta");    # absolute path
+File::Copy::Recursive::dircopy($otherMetaPath, "$ie_input_path/meta") or die "Could not perform dircopy() of $rightsXMLPath to $ie_input_path/meta: $!";
+# delete bagit from last session
+rmtree $ie_output_path;
+# copy new ie to output_path
+File::Copy::Recursive::dircopy($ie_input_path, $ie_output_path) or die "Could not perform dircopy() of $ie_input_path to $ie_output_path: $!";
+
+#~ structure of input output folders for tests
+#~ .
+#~ ├── export_dir_kitodo
+#~ │   └─── bagit
+#~ │      └── test    
+#~ │    
+#~ └── tmp
+#~       └── bagit
+#~         └── test
+
+my $ua = LWP::UserAgent->new;
+my $request = HTTP::Request->new('GET' => "https://sru.bsz-bw.de/swbf");
+my $response = $ua->request($request);
+my $marc21slimutils_file = $xsl_path->child('MARC21slimUtils.xsl');
+my $useragent_obj = LWP::UserAgent->new;
+$useragent_obj->agent("MyApp/0.1 ");
+$useragent_obj->timeout(3600); #1h
+
+# ensure no dir exists, then run test
+if($xsl_path->is_dir){ $xsl_path->remove_tree; }
+
+### tests
+BEGIN { use_ok("SLUB::LZA::SIPBuilderBagIt"); }
+#
+is(SLUB::LZA::SIPBuilderBagIt::check_xsl_directory(), $xsl_path->absolute, "check_xsl_directory(), return value if not exist");
+ok($xsl_path->is_dir, "check_xsl_directory(), created if not exist");
+is(SLUB::LZA::SIPBuilderBagIt::check_xsl_directory(), $xsl_path->absolute, "check_xsl_directory(), return value if exist");
+ok($xsl_path->is_dir, "check_xsl_directory(), untouched if exist");
+#
+SKIP: {
+    skip "No response from server https://sru.bsz-bw.de/swb", 1 unless ! $response->is_error;
+    like(SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", "457035137", "pica.swn", "marcxmlvbos"), qr//, "get_mods_from()");
+};
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("", "457035137", "pica.swn", "marcxmlvbos"); } qr/invalid parameters/, "get_mods_from(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", "", "pica.swn", "marcxmlvbos"); } qr/invalid parameters/, "get_mods_from(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", "457035137", "", "marcxmlvbos"); } qr/invalid parameters/, "get_mods_from(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", "457035137", "pica.swn", ""); } qr/invalid parameters/, "get_mods_from(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from(undef, "457035137", "pica.swn", "marcxmlvbos"); } qr/url not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), url undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", undef, "pica.swn", "marcxmlvbos"); } qr/ppn not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), ppn undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", "457035137", undef, "marcxmlvbos"); } qr/key not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), key undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", "457035137", "pica.swn", undef); } qr/schema not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), schema undef";
+#
+ok(SLUB::LZA::SIPBuilderBagIt::write_file($marc21slimutils_file, $unpatched_marc21slimutils), "write_file()");
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::write_file("", $unpatched_marc21slimutils); } qr/invalid parameters/, "write_file(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::write_file($marc21slimutils_file, ""); } qr/invalid parameters/, "write_file(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::write_file(undef, $unpatched_marc21slimutils); } qr/filename not defined/, "write_file(\$filename, \$value), filename undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::write_file($marc21slimutils_file, undef); } qr/value not defined/, "write_file(\$filename, \$value), value undef";
+#
+is(SLUB::LZA::SIPBuilderBagIt::patch_mods($unpatched_mods_obj), $patched_mods, "patch_mods()");
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::patch_mods(""); } qr/invalid parameters/, "patch_mods(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::patch_mods(undef); } qr/modsobject not defined/, "patch_mods(\$modsobj), modsobj undef";
+#
+is(SLUB::LZA::SIPBuilderBagIt::patch_marc_response($unpatched_marcblob_obj), $patched_marcblob, "patch_marc_response()");
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::patch_marc_response(""); } qr/invalid parameters/, "patch_marc_response(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::patch_marc_response(undef); } qr/marcobject not defined/, "patch_marc_response(\$marcobj), marcobj undef";
+#
+is(SLUB::LZA::SIPBuilderBagIt::check_marc21_utility($xsl_path, $useragent_obj), $marc21slimutils_file , "check_marc21_utility()");
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_utility("", $useragent_obj); } qr/invalid parameters/, "check_marc21_utility(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_utility($xsl_path, ""); } qr/invalid parameters/, "check_marc21_utility(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_utility(undef, $useragent_obj); } qr/xsl directory not defined/, "check_marc21_utility(\$xsl_dir, \$useragent), xsl_dir undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_utility($xsl_path, undef); } qr/user agent not defined/, "check_marc21_utility(\$xsl_dir, \$useragent), useragent undef";
+#
+is(SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl($xsl_path, $useragent_obj), 'xsl/MARC21slim2MODS3-6.patched.xsl' , "check_marc21_mods_xsl()");
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl("", $useragent_obj); } qr/invalid parameters/, "check_marc21_mods_xsl(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl($xsl_path, ""); } qr/invalid parameters/, "check_marc21_mods_xsl(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl(undef, $useragent_obj); } qr/xsl directory not defined/, "check_marc21_mods_xsl(\$xsl_dir, \$useragent), xsl_dir undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl($xsl_path, undef); } qr/user agent not defined/, "check_marc21_mods_xsl(\$xsl_dir, \$useragent), useragent undef";
+#
+SKIP: {
+    skip "No response from server https://sru.bsz-bw.de/swb", 1 unless ! $response->is_error;
+    like(SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_ppn("457035137"), qr//, "prepare_mods_section_with_ppn()");
+};
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_ppn(""); } qr/invalid parameters/, "prepare_mods_section_with_ppn(), invalid parameters";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_ppn(undef); } qr/ppn not defined/, "prepare_mods_section_with_ppn(\$ppn), ppn undef";
+#
+is(SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_noppn("string"), $noppn_mods_res, "prepare_mods_section_with_noppn()");
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_noppn(""); } qr/noppn is empty string!/, "prepare_mods_section_with_noppn(), noppn is empty string!";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_noppn(undef); } qr/noppn is not defined/, "prepare_mods_section_with_noppn(\$noppn), noppn undef";
+# test new
+ok(SLUB::LZA::SIPBuilderBagIt::create_slub_bagit($ie_output_path, \@addBagInfo), "create_slub_bagit()");
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::create_slub_bagit(undef, \@addBagInfo); } qr/ie_path is not defined/, "create_slub_bagit(\$ie_path, \$refAddBagInfo), ie_path undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::create_slub_bagit($ie_output_path, undef); } qr/array of hashes not defined for bag-info.txt/, "create_slub_bagit(\$ie_path, \$refAddBagInfo), refAddBagInfo undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::create_slub_bagit("", \@addBagInfo); } qr/path is not directory/, "create_slub_bagit(), invalid parameters";
+#
+is(SLUB::LZA::SIPBuilderBagIt::getBagItName($ie_output_path), $ie, "getBagItName()");
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::getBagItName(undef); } qr/path for getting bagit name is not defined/, "getBagItName(\$bagit_name), bagit_name undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::getBagItName(""); } qr/path is not directory/, "getBagItName(), invalid parameters";
+#
+is(SLUB::LZA::SIPBuilderBagIt::getFileName($file_name), "test.txt", "getFileName()");
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::getFileName(undef); } qr/path with file name is not defined/, "getFileName(\$file_name), file_name undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::getFileName(""); } qr/invalid parameters/, "getFileName(), invalid parameters";
+#
+is(SLUB::LZA::SIPBuilderBagIt::save_option("copy", $ie_input_path, $ie_output_path, "ID-10000000_2020-01-01_20-00-00"), $ie_output_path . "/ID-10000000_2020-01-01_20-00-00", "save_option()");
+rmtree $ie_output_path . "/ID-10000000_2020-01-01_20-00-00";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::save_option(undef, $ie_input_path, $ie_output_path, "ID-10000000_2020-01-01_20-00-00"); } qr/save option not defined/, "save_option(\$save, \$directory, \$output, \$bagNewDir), save undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::save_option("copy", undef, $ie_output_path, "ID-10000000_2020-01-01_20-00-00"); } qr/IE directory path not defined/, "save_option(\$save, \$directory, \$output, \$bagNewDir), directory undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::save_option("copy", $ie_input_path, undef, "ID-10000000_2020-01-01_20-00-00"); } qr/output path not defined/, "save_option(\$save, \$directory, \$output, \$bagNewDir), for \$save=copy directory undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::save_option("move", $ie_input_path, undef, "ID-10000000_2020-01-01_20-00-00"); } qr/output path not defined/, "save_option(\$save, \$directory, \$output, \$bagNewDir), for \$save=move directory undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::save_option("copy", $ie_input_path, $ie_output_path, undef); } qr/sip root dir is not defined/, "save_option(\$save, \$directory, \$output, \$bagNewDir), bagNewDir undef";
+#
+is(SLUB::LZA::SIPBuilderBagIt::getPayloadFiles($ie_input_path), 2, "getPayloadFiles()"); # meta, data
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::getPayloadFiles(undef); } qr/path is not defined/, "getPayloadFiles(\$import_dir), import_dir undef";
+#
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-01.xml"), 1, "validateRightsXML() Fallbeispiel-01.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-02.xml"), 1, "validateRightsXML() Fallbeispiel-02.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-03.xml"), 1, "validateRightsXML() Fallbeispiel-03.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-04.xml"), 1, "validateRightsXML() Fallbeispiel-04.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-05.xml"), 1, "validateRightsXML() Fallbeispiel-05.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-06.xml"), 1, "validateRightsXML() Fallbeispiel-06.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-07.xml"), 1, "validateRightsXML() Fallbeispiel-07.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-08a-undef.xml"), 1, "validateRightsXML() Fallbeispiel-08a-undef.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-09.xml"), 1, "validateRightsXML() Fallbeispiel-09.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-10.xml"), 1, "validateRightsXML() Fallbeispiel-10.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-11.xml"), 1, "validateRightsXML() Fallbeispiel-11.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-12.xml"), 1, "validateRightsXML() Fallbeispiel-12.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-13.xml"), 1, "validateRightsXML() Fallbeispiel-13.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-14.xml"), 1, "validateRightsXML() Fallbeispiel-14.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-15.xml"), 1, "validateRightsXML() Fallbeispiel-15.xml");
+is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-16.xml"), 1, "validateRightsXML() Fallbeispiel-16.xml");
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML(undef, "rights.xml"); } qr/ie_path to rights.xsd not defined/, "validateRightsXML(\$ie_path, \$rightsName), ie_path undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, undef); } qr/file name not defined/, "validateRightsXML(\$ie_path, \$rightsName), rightsName undef";
+throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "mods.xml"); } qr/failed validation/, "validateRightsXML(\$ie_path, \$rightsName), not valid rights.xml";
+
+
+1;
diff --git a/xsd/archive.xsd b/xsd/archive.xsd
deleted file mode 100644
index 15d034a11877d937a19c3d5eea17397bfecf0d07..0000000000000000000000000000000000000000
--- a/xsd/archive.xsd
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" targetNamespace="http://slub-dresden.de/slubarchiv" xmlns:archive="http://slub-dresden.de/slubarchiv">
-  <xs:element name="record" type="archive:record"/>
-  <xs:complexType name="record">
-    <xs:all>
-      <xs:element name="archivalValueDescription" type="archive:NonEmptyString" minOccurs="1" maxOccurs="1"/>
-      <xs:element name="exportToArchiveDate" type="xs:dateTime" minOccurs="1" maxOccurs="1"/>
-      <xs:element name="externalId" type="archive:LzaIdSubstring" minOccurs="1" maxOccurs="1"/>
-      <xs:element name="externalIsilId" type="archive:NonEmptyString" minOccurs="0" maxOccurs="1"/>
-      <xs:element name="externalWorkflow" type="archive:LzaIdSubstring" minOccurs="1" maxOccurs="1"/>
-      <xs:element name="hasConservationReason" type="xs:boolean" minOccurs="1" maxOccurs="1"/>
-    </xs:all>
-    <xs:attribute name="version" type="archive:SipVersionString" use="required"/>
-  </xs:complexType>
-  <xs:simpleType name="NonEmptyString">
-    <xs:restriction base="xs:string">
-      <xs:pattern value="[\s\S]*[^ ][\s\S]*"/>
-    </xs:restriction>
-  </xs:simpleType>
-  <xs:simpleType name="LzaIdSubstring">
-    <xs:restriction base="xs:string">
-      <xs:pattern value="[a-z0-9]+"/>
-    </xs:restriction>
-  </xs:simpleType>
-  <xs:simpleType name="SipVersionString">
-    <xs:restriction base="xs:string">
-      <xs:enumeration value="v2017.1"/>
-    </xs:restriction>
-  </xs:simpleType>
-</xs:schema>
diff --git a/xsd/rights1.xsd b/xsd/rights1.xsd
new file mode 100644
index 0000000000000000000000000000000000000000..95237503a10786714ebb22f5762dfee4d4611df5
--- /dev/null
+++ b/xsd/rights1.xsd
@@ -0,0 +1,274 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- SLUB Archiv Rechteschema -->
+<!-- 2019-12-18: Version 1.0 -->
+
+<xs:schema
+    targetNamespace="http://slubarchiv.slub-dresden.de/rights1"
+    xmlns="http://slubarchiv.slub-dresden.de/rights1"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    elementFormDefault="qualified"
+    version="1.0">
+    <xs:annotation>
+        <xs:documentation xml:lang="de">Schema zur Beschreibung von Rechten</xs:documentation>
+    </xs:annotation>
+    <xs:element name="rightsRecord" type="typeRightsRecord">
+        <xs:annotation>
+            <xs:documentation xml:lang="de">Rechteinformationen</xs:documentation>
+        </xs:annotation>
+    </xs:element>
+    <xs:complexType name="typeRightsRecord">
+        <xs:sequence>
+            <xs:element name="copyrightStatus" minOccurs="1" maxOccurs="1" type="typeCopyrightStatus">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Aussage zum Urheberrecht des Materials.</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="permissions" minOccurs="0" maxOccurs="1" type="typePermissions">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Aussage(n) zu rechtskräftigen Erlaubnissen oder Genehmigungen des Materials</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="legalRestrictions" minOccurs="0" maxOccurs="1" type="typeLegalRestrictions">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Aussage(n) zu gesetzlichen Einschränkungen des Materials</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="typePermissions">
+        <xs:sequence>
+            <xs:element name="contract" minOccurs="0" maxOccurs="unbounded" type="typeContract">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Eine kurze Beschreibung des Vertrags inklusive Vertragspartner.</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="license" minOccurs="0" maxOccurs="unbounded" type="typeLicense">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Lizenz</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="orphanedWork" minOccurs="0" maxOccurs="1" type="typeStringWithOptionalLanguageDeclaration">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Das Material ist ein verwaistes Werk nach Urheberrechtsgesetz §61 (Fassung vom 01.01.2014). Optionale Aussagen sind möglich, haben aber nur informativen Charakter.</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="outOfPrintWork" minOccurs="0" maxOccurs="1" type="typeStringWithOptionalLanguageDeclaration">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Das Material ist ein vergriffenes Werk nach Verwertungsgesellschaftengesetz §51 (Fassung vom 01.06.2016). Optionale Aussagen sind möglich, haben aber nur informativen Charakter.</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="typeLegalRestrictions">
+        <xs:sequence>
+            <xs:element name="childProtection" type="typeStringWithOptionalLanguageDeclaration" minOccurs="0" maxOccurs="unbounded">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Material mit Jugendschutz-relevanten Inhalten</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="confidentialContent" type="typeStringWithOptionalLanguageDeclaration" minOccurs="0" maxOccurs="unbounded">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Material mit vertraulichen oder sicherheitsrelevanten Inhalten</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="other" type="typeStringWithOptionalLanguageDeclaration" minOccurs="0" maxOccurs="unbounded">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Eine sonstige Beschränkung, die aktuell nicht abbildbar ist.</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="personalRight" type="typeStringWithOptionalLanguageDeclaration" minOccurs="0" maxOccurs="unbounded">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Material mit persönlichen Rechten</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="pornographicContent" type="typeStringWithOptionalLanguageDeclaration" minOccurs="0" maxOccurs="unbounded">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">pornografisches Material mit sittenwidrigen oder strafrechtlich verfolgten Inhalten</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="trademark" type="typeStringWithOptionalLanguageDeclaration" minOccurs="0" maxOccurs="unbounded">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Material mit Markenrecht-relevanten Inhalten</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="unconstitutionalContent" type="typeStringWithOptionalLanguageDeclaration" minOccurs="0" maxOccurs="unbounded">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Material mit verfassungswidrigen Inhalten</xs:documentation>
+                </xs:annotation>
+            </xs:element>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="typeContract">
+        <xs:simpleContent>
+            <xs:extension base="xs:string">
+                <xs:attribute name="date" use="required" type="xs:date">
+                    <xs:annotation>
+                        <xs:documentation xml:lang="de">Datum des Vertrags</xs:documentation>
+                    </xs:annotation>
+                </xs:attribute>
+                <xs:attribute name="fileNumber" use="optional" type="typeNonEmptyString">
+                    <xs:annotation>
+                        <xs:documentation xml:lang="de">Vertragsnummer oder Aktenzeichen</xs:documentation>
+                    </xs:annotation>
+                </xs:attribute>
+            </xs:extension>
+        </xs:simpleContent>
+    </xs:complexType>
+    <xs:complexType name="typeLicense" mixed="true">
+        <xs:simpleContent>
+            <xs:extension base="typeLicenseStrings">
+                <xs:attribute name="url" use="optional" type="xs:anyURI">
+                    <xs:annotation>
+                        <xs:documentation xml:lang="de">URL zum Lizenztext</xs:documentation>
+                    </xs:annotation>
+                </xs:attribute>
+            </xs:extension>
+        </xs:simpleContent>
+    </xs:complexType>
+    <xs:complexType name="typeStringWithOptionalLanguageDeclaration">
+        <xs:simpleContent>
+            <xs:extension base="xs:string">
+                <xs:attribute name="lang" use="optional" type="xs:language" default="de">
+                    <xs:annotation>
+                        <xs:documentation xml:lang="de">Sprache der Beschreibung</xs:documentation>
+                    </xs:annotation>
+                </xs:attribute>
+            </xs:extension>
+        </xs:simpleContent>
+    </xs:complexType>
+    <xs:complexType name="typeNonEmptyStringWithOptionalLanguageDeclaration">
+        <xs:simpleContent>
+            <xs:extension base="typeNonEmptyString">
+                <xs:attribute name="lang" use="optional" type="xs:language" default="de">
+                    <xs:annotation>
+                        <xs:documentation xml:lang="de">Sprache der Beschreibung</xs:documentation>
+                    </xs:annotation>
+                </xs:attribute>
+            </xs:extension>
+        </xs:simpleContent>
+    </xs:complexType>
+    <xs:simpleType name="typeCopyrightStatus">
+        <xs:restriction base="xs:string">
+            <xs:enumeration value="publicdomain">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Das Material ist gemeinfrei und nicht urheberrechtsbehaftet nach deutschem Recht.</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="copyrighted">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Das Material ist urheberrechtsbehaftet nach deutschem Recht. Es gilt das Urheberrechtsgesetz (in der Fassung vom 01.01.2019).</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="undefined">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Die Urheberrechte des Materials sind ungeklärt. Eine Prüfung läuft gerade oder hat noch nicht stattgefunden.</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+        </xs:restriction>
+    </xs:simpleType>
+    <xs:simpleType name="typeLicenseStrings">
+        <xs:restriction base="xs:string">
+            <xs:enumeration value="CC0 1.0">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: CC0 1.0 Universell - Public Domain Dedication</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY 3.0 DE">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung 3.0 Deutschland</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY 4.0">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung 4.0 International</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY-SA 3.0 DE">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung - Weitergabe unter gleichen Bedingungen 3.0 Deutschland</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY-SA 4.0">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung - Weitergabe unter gleichen Bedingungen 4.0 International</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY-ND 3.0 DE">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung - Keine Bearbeitung 3.0 Deutschland</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY-ND 4.0">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung - Keine Bearbeitung 4.0 International</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY-NC 3.0 DE">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung - Nicht kommerziell 3.0 Deutschland</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY-NC 4.0">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung - Nicht kommerziell 4.0 International</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY-NC-SA 3.0 DE">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung - Nicht kommerziell - Weitergabe unter gleichen Bedingungen 3.0 Deutschland</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY-NC-SA 4.0">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung - Nicht kommerziell - Weitergabe unter gleichen Bedingungen 4.0 International</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY-NC-ND 3.0 DE">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung - Nicht kommerziell - Keine Bearbeitung 3.0 Deutschland</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="CC BY-NC-ND 4.0">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Creative Commons: Namensnennung - Nicht kommerziell - Keine Bearbeitung 4.0 International</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="DL-DE BY 1.0">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Datenlizenz Deutschland - Namensnennung - Version 1.0</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="DL-DE BY-NC 1.0">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Datenlizenz Deutschland - Namensnennung - nicht kommerziell - Version 1.0</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="DL-DE BY 2.0">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Datenlizenz Deutschland - Namensnennung - Version 2.0</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="DL-DE Zero 2.0">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Datenlizenz Deutschland - Zero - Version 2.0</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="GNU FDL 1.3">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">GNU Free Documentation License 1.3</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+            <xs:enumeration value="other">
+                <xs:annotation>
+                    <xs:documentation xml:lang="de">Eine sonstige Lizenz, die aktuell nicht abbildbar ist.</xs:documentation>
+                </xs:annotation>
+            </xs:enumeration>
+        </xs:restriction>
+    </xs:simpleType>
+    <xs:simpleType name="typeNonEmptyString">
+        <xs:restriction base="xs:string">
+            <xs:minLength value="1"></xs:minLength>
+        </xs:restriction>
+    </xs:simpleType>
+</xs:schema>