[open-ils-commits] [GIT] Evergreen ILS branch master updated. c7bad82a66554251b8a0f636e629fe98680b7765

Evergreen Git git at git.evergreen-ils.org
Fri Aug 9 15:15:16 EDT 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  c7bad82a66554251b8a0f636e629fe98680b7765 (commit)
       via  32ec20b71540b1230ecc15f1aec95059e044499e (commit)
       via  256b4d24240332ae3fd2a5cc14b1709c90f18d05 (commit)
       via  cfc828d832ecee92478466cd2f4e174c2f4b5c3c (commit)
       via  6990fd819c0dae385c3cc7a40d39a0ebed91086c (commit)
       via  c0dea517395c733b77e8eb219d2c3f43f6098d42 (commit)
       via  9d37f6890ce6b591d62972ce3e341cecf7c45535 (commit)
       via  e710ecbee519d374bcf69b0c535c3f83814c782b (commit)
       via  d2f4cac923668ff05854ffc9720cafe514b9b71c (commit)
       via  3eb616e56c82a5106e14f5a446f1d875015db7f0 (commit)
      from  a6f3e3bd7f1f2d62db72a6155b0df1d8942627f4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c7bad82a66554251b8a0f636e629fe98680b7765
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Fri Aug 9 15:12:58 2013 -0400

    Stamping upgrade scripts for bib record browser
    
    LP #1177810
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>

diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql b/Open-ILS/src/sql/Pg/upgrade/0815.schema.config-metabib-interauthority.sql
similarity index 100%
rename from Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql
rename to Open-ILS/src/sql/Pg/upgrade/0815.schema.config-metabib-interauthority.sql
diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql b/Open-ILS/src/sql/Pg/upgrade/0816.schema.bib-auth-browse.sql
similarity index 100%
rename from Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
rename to Open-ILS/src/sql/Pg/upgrade/0816.schema.bib-auth-browse.sql

commit 32ec20b71540b1230ecc15f1aec95059e044499e
Author: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
Date:   Thu Aug 8 10:27:10 2013 -0400

    Fix problem where basic search bar was flush with left edge of page
    
    Reported by Ben Shum.
    
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>

diff --git a/Open-ILS/src/templates/opac/css/style.css.tt2 b/Open-ILS/src/templates/opac/css/style.css.tt2
index 422fdd6..fde5d43 100644
--- a/Open-ILS/src/templates/opac/css/style.css.tt2
+++ b/Open-ILS/src/templates/opac/css/style.css.tt2
@@ -41,6 +41,7 @@ a {
 .searchbar {
     font-weight: bold;
     padding-top: 10px;
+    margin-left: 1em;
 }
 
 /*

commit 256b4d24240332ae3fd2a5cc14b1709c90f18d05
Author: Jason Stephenson <jstephenson at mvlc.org>
Date:   Fri Jul 26 09:48:59 2013 -0400

    Fix issues with multiple divs having the search-wrapper id.
    
    Basically, remove the extra <div> from all the files that INCLUDE
    searchbar.tt2, and leave the <div> that searchar.tt2 uses alone.
    
    Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>

diff --git a/Open-ILS/src/templates/opac/cnbrowse.tt2 b/Open-ILS/src/templates/opac/cnbrowse.tt2
index f4d7e78..958dfec 100644
--- a/Open-ILS/src/templates/opac/cnbrowse.tt2
+++ b/Open-ILS/src/templates/opac/cnbrowse.tt2
@@ -6,9 +6,7 @@
     WRAPPER "opac/parts/base.tt2";
     INCLUDE "opac/parts/topnav.tt2";
     ctx.page_title = l("Call Number Browse"); %]
-    <div id="search-wrapper">
-        [% INCLUDE "opac/parts/searchbar.tt2" %]
-    </div>
+    [% INCLUDE "opac/parts/searchbar.tt2" %]
     <div id="content-wrapper">
         <div id="main-content">
             <div class="cnbrowse_div">
diff --git a/Open-ILS/src/templates/opac/home.tt2 b/Open-ILS/src/templates/opac/home.tt2
index 8ede2cf..123f47b 100644
--- a/Open-ILS/src/templates/opac/home.tt2
+++ b/Open-ILS/src/templates/opac/home.tt2
@@ -2,9 +2,7 @@
     WRAPPER "opac/parts/base.tt2";
     INCLUDE "opac/parts/topnav.tt2";
     ctx.page_title = l("Home") %]
-    <div id="search-wrapper">
-        [% INCLUDE "opac/parts/searchbar.tt2" %]
-    </div>
+    [% INCLUDE "opac/parts/searchbar.tt2" %]
     <div id="content-wrapper">
         <div id="main-content-home">
             <div class="common-full-pad"></div>
diff --git a/Open-ILS/src/templates/opac/login.tt2 b/Open-ILS/src/templates/opac/login.tt2
index 1c7d41a..1de7468 100644
--- a/Open-ILS/src/templates/opac/login.tt2
+++ b/Open-ILS/src/templates/opac/login.tt2
@@ -3,9 +3,7 @@
     INCLUDE "opac/parts/topnav.tt2";
     basic_search = "f";
     ctx.page_title = l("Account Login") %]
-    <div id="search-wrapper">
-        [% INCLUDE "opac/parts/searchbar.tt2" %]
-    </div>
+    [% INCLUDE "opac/parts/searchbar.tt2" %]
     <div id="content-wrapper">
         <div id="main-content">
             [% INCLUDE "opac/parts/login/form.tt2" %]
diff --git a/Open-ILS/src/templates/opac/mylist.tt2 b/Open-ILS/src/templates/opac/mylist.tt2
index 1da9914..2a00a35 100644
--- a/Open-ILS/src/templates/opac/mylist.tt2
+++ b/Open-ILS/src/templates/opac/mylist.tt2
@@ -3,9 +3,7 @@
     WRAPPER "opac/parts/base.tt2";
     INCLUDE "opac/parts/topnav.tt2";
     ctx.page_title = l("Record Detail") %]
-    <div id="search-wrapper">
-        [% INCLUDE "opac/parts/searchbar.tt2" %]
-    </div>
+    [% INCLUDE "opac/parts/searchbar.tt2" %]
     <div id="content-wrapper">
         <div id="main-content">
             [%  IF ctx.mylist.size;
diff --git a/Open-ILS/src/templates/opac/parts/myopac/base.tt2 b/Open-ILS/src/templates/opac/parts/myopac/base.tt2
index 30ac614..e478f83 100644
--- a/Open-ILS/src/templates/opac/parts/myopac/base.tt2
+++ b/Open-ILS/src/templates/opac/parts/myopac/base.tt2
@@ -10,9 +10,7 @@
     skin_root = "../"
 %]
     [% INCLUDE "opac/parts/topnav.tt2" %]
-    <div id="search-wrapper">
-        [% INCLUDE "opac/parts/searchbar.tt2" %]
-    </div>
+    [% INCLUDE "opac/parts/searchbar.tt2" %]
     <div id="content-wrapper">
         <div id="myopac_tabs">
             <div id="acct_tabs">
diff --git a/Open-ILS/src/templates/opac/password_reset.tt2 b/Open-ILS/src/templates/opac/password_reset.tt2
index 08577d5..d6a27de 100644
--- a/Open-ILS/src/templates/opac/password_reset.tt2
+++ b/Open-ILS/src/templates/opac/password_reset.tt2
@@ -3,9 +3,7 @@
     INCLUDE "opac/parts/topnav.tt2";
     ctx.page_title = l('Library system password reset request form');
 -%]
-<div id="search-wrapper">
-    [% INCLUDE "opac/parts/searchbar.tt2" %]
-</div>
+[% INCLUDE "opac/parts/searchbar.tt2" %]
 
 [%  
     uuid = ctx.page_args.0;
diff --git a/Open-ILS/src/templates/opac/place_hold.tt2 b/Open-ILS/src/templates/opac/place_hold.tt2
index cb97e88..2c1da79 100644
--- a/Open-ILS/src/templates/opac/place_hold.tt2
+++ b/Open-ILS/src/templates/opac/place_hold.tt2
@@ -5,9 +5,7 @@
         basic_search = "f";
     END;
     ctx.page_title = l("Place Hold") %]
-    <div id="search-wrapper">
-        [% INCLUDE "opac/parts/searchbar.tt2" %]
-    </div>
+    [% INCLUDE "opac/parts/searchbar.tt2" %]
     <div id="content-wrapper">
         <div id="main-content">
             <div class="common-full-pad"></div>	
diff --git a/Open-ILS/src/templates/opac/record.tt2 b/Open-ILS/src/templates/opac/record.tt2
index 4576493..935ebdd 100644
--- a/Open-ILS/src/templates/opac/record.tt2
+++ b/Open-ILS/src/templates/opac/record.tt2
@@ -4,9 +4,7 @@
     ctx.page_title = l("Record Detail");
     IF CGI.param("expand"); basic_search = "f"; END;    
 -%]
-    <div id="search-wrapper">
-        [% INCLUDE "opac/parts/searchbar.tt2" %]
-    </div>
+    [% INCLUDE "opac/parts/searchbar.tt2" %]
     <br class="clear-both" />
     <div id="content-wrapper" class="content-wrapper-record-page">
         [% IF ctx.staff_saved_search_size %]
diff --git a/Open-ILS/src/templates/opac/record/email.tt2 b/Open-ILS/src/templates/opac/record/email.tt2
index bafd20a..d41226c 100644
--- a/Open-ILS/src/templates/opac/record/email.tt2
+++ b/Open-ILS/src/templates/opac/record/email.tt2
@@ -3,9 +3,7 @@
     WRAPPER "opac/parts/base.tt2";
     INCLUDE "opac/parts/topnav.tt2";
     ctx.page_title = l("Record Detail") %]
-    <div id="search-wrapper">
-        [% INCLUDE "opac/parts/searchbar.tt2" %]
-    </div>
+    [% INCLUDE "opac/parts/searchbar.tt2" %]
     <br class="clear-both" />
     <div id="content-wrapper" class="content-wrapper-record-page">
         <div id='main-content'>
diff --git a/Open-ILS/src/templates/opac/results.tt2 b/Open-ILS/src/templates/opac/results.tt2
index d199ce9..39b40ad 100644
--- a/Open-ILS/src/templates/opac/results.tt2
+++ b/Open-ILS/src/templates/opac/results.tt2
@@ -17,9 +17,7 @@
     PROCESS get_library;
 -%]
     <form action="[% ctx.opac_root %]/results" method="get">
-    <div id="search-wrapper">
-        [% INCLUDE "opac/parts/searchbar.tt2" took_care_of_form=1 %]
-    </div>
+    [% INCLUDE "opac/parts/searchbar.tt2" took_care_of_form=1 %]
     <div class="almost-content-wrapper">
         <div id="results_header_bar">
             <div id="results_header_inner">
diff --git a/Open-ILS/src/templates/opac/sms_cn.tt2 b/Open-ILS/src/templates/opac/sms_cn.tt2
index b3d554f..3ccbf6f 100644
--- a/Open-ILS/src/templates/opac/sms_cn.tt2
+++ b/Open-ILS/src/templates/opac/sms_cn.tt2
@@ -2,9 +2,7 @@
     WRAPPER "opac/parts/base.tt2";
     INCLUDE "opac/parts/topnav.tt2";
     ctx.page_title = l("Send Call Number via Text/SMS") %]
-    <div id="search-wrapper">
-        [% INCLUDE "opac/parts/searchbar.tt2" %]
-    </div>
+    [% INCLUDE "opac/parts/searchbar.tt2" %]
     <div id="content-wrapper">
         <div id="main-content">
             <div class="common-full-pad"></div>
diff --git a/Open-ILS/src/templates/opac/temp_warn.tt2 b/Open-ILS/src/templates/opac/temp_warn.tt2
index 525db1f..9adbcb5 100644
--- a/Open-ILS/src/templates/opac/temp_warn.tt2
+++ b/Open-ILS/src/templates/opac/temp_warn.tt2
@@ -3,9 +3,7 @@
     WRAPPER "opac/parts/base.tt2";
     INCLUDE "opac/parts/topnav.tt2";
     ctx.page_title = l("Temporary List Warning") %]
-    <div id="search-wrapper">
-        [% INCLUDE "opac/parts/searchbar.tt2" %]
-    </div>
+    [% INCLUDE "opac/parts/searchbar.tt2" %]
     <div id="content-wrapper">
         <div id="main-content">
              <p class="big-strong">[% l('You are adding to a temporary list.') %]

commit cfc828d832ecee92478466cd2f4e174c2f4b5c3c
Author: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
Date:   Mon Jul 22 10:14:51 2013 -0400

    OPAC Browse: bugfixes squashed together from LP #1177810
    
    In specific:
        OPAC Browse: go back from numbered to bulleted results
        OPAC Browse: Avoid showing tracing if linked authorities have no bibs
        OPAC Browse: Replace English pager with customizable pager
        OPAC Browse: Extra small bit of documentation about author headings
    
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
index 81644e6..593eb2b 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
@@ -338,6 +338,19 @@ sub load_browse {
         }
     }
 
+    my $pager_shortcuts = $self->ctx->{get_org_setting}->(
+        $self->ctx->{physical_loc} || $self->ctx->{search_ou} ||
+            $self->ctx->{aou_tree}->id, 'opac.browse.pager_shortcuts'
+    );
+    if ($pager_shortcuts) {
+        my @pager_shortcuts;
+        while ($pager_shortcuts =~ s/(\*(.+?)\*)//) {
+            push @pager_shortcuts, [substr($2, 0, 1), $2];
+        }
+        push @pager_shortcuts, map { [$_, $_] } split //, $pager_shortcuts;
+        $self->ctx->{pager_shortcuts} = \@pager_shortcuts;
+    }
+
     if ($self->cgi->param('qtype') and defined $self->cgi->param('bterm')) {
 
         $self->leading_article_test(
diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
index 2b6772d..dad8658 100644
--- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql
+++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
@@ -4824,6 +4824,20 @@ INSERT into config.org_unit_setting_type
         'description'
     ),
     'string', null)
+,( 'opac.browse.pager_shortcuts', 'opac',
+    oils_i18n_gettext(
+        'opac.browse.pager_shortcuts',
+        'Paging shortcut links for OPAC Browse',
+        'coust',
+        'label'
+    ),
+    oils_i18n_gettext(
+        '',
+        'The characters in this string, in order, will be used as shortcut links for quick paging in the OPAC browse interface. Any sequence surrounded by asterisks will be taken as a whole label, not split into individual labels at the character level, but only the first character will serve as the basis of the search.',
+        'coust',
+        'description'
+    ),
+    'string', null)
 
 ;
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
index 466053c..358fb49 100644
--- a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
@@ -7487,6 +7487,16 @@ UPDATE config.metabib_field
         browse_xpath IS NULL AND
         field_class = 'author';
 
+INSERT INTO config.org_unit_setting_type (
+    name, label, grp, description, datatype
+) VALUES (
+    'opac.browse.pager_shortcuts',
+    'Paging shortcut links for OPAC Browse',
+    'opac',
+    'The characters in this string, in order, will be used as shortcut links for quick paging in the OPAC browse interface. Any sequence surrounded by asterisks will be taken as a whole label, not split into individual labels at the character level, but only the first character will serve as the basis of the search.',
+    'string'
+);
+
 COMMIT;
 
 \qecho This is a browse-only reingest of your bib records. It may take a while.
diff --git a/Open-ILS/src/templates/opac/browse.tt2 b/Open-ILS/src/templates/opac/browse.tt2
index 44062b6..8ad04e8 100644
--- a/Open-ILS/src/templates/opac/browse.tt2
+++ b/Open-ILS/src/templates/opac/browse.tt2
@@ -50,12 +50,11 @@
                     [% IF ctx.back_pivot %]
                     <a class="opac-button" href="[% mkurl('', {bpivot => ctx.back_pivot}) %]" onclick="$('browse-pager-spinner-[% id %]').className = '';">&larr; [%l ('Back') %]</a>
                     [% END %]
-                    [% IF browse.english_pager; # XXX how to apply i18n here?
+                    [% IF ctx.pager_shortcuts;
                         current_qtype = CGI.param('qtype') || 'title' %]
                     <span class="browse-shortcuts">
-                        <a href="[% mkurl('', {qtype => current_qtype, bterm => '0'}, ['bpivot']) %]">0-9</a>
-                        [% FOR letter IN ['A'..'Z'] %]
-                            <a href="[% mkurl('', {qtype => current_qtype, bterm => letter}, ['bpivot']) %]">[% letter %]</a>
+                        [% FOR shortcut IN ctx.pager_shortcuts %]
+                            <a href="[% mkurl('', {qtype => current_qtype, bterm => shortcut.0}, ['bpivot']) %]">[% shortcut.1 %]</a>
                         [% END %]
                     </span>
                     [% END %]
@@ -92,7 +91,7 @@
                     </div>
                     [% END %]
 
-                    <ol class="browse-result-list">
+                    <ul class="browse-result-list">
                     [% FOR result IN ctx.browse_results %]
                         <li class="browse-result">
                             <span class="browse-result-value[% result.row_number == 0 && !CGI.param('bpivot') ? ' browse-result-best-match' : '' %]">
@@ -129,7 +128,7 @@
                                             # that h.target_count is only
                                             # defined when h.target is.
 
-                                            IF h.target %]
+                                            IF h.target AND h.target_count %]
                                             <li><span class="browse-result-authority-field-name">[% field.name %]</span>
                                             <a href="[% mkurl(ctx.opac_root _ '/results', {query => 'identifier|authority_id[' _ h.target _ ']'}) %]">[% h.heading | html %]</a>
                                             <span class="browse-result-authority-bib-links">([% h.target_count %])</span>
diff --git a/Open-ILS/src/templates/opac/parts/config.tt2 b/Open-ILS/src/templates/opac/parts/config.tt2
index a0be85b..bc046bd 100644
--- a/Open-ILS/src/templates/opac/parts/config.tt2
+++ b/Open-ILS/src/templates/opac/parts/config.tt2
@@ -155,12 +155,4 @@ ctx.google_books_preview = 0;
 #
 # ctx.maintenance_message = "The system will not be available February 29, 2104.";
 
-# Browse settings
-# Set to 1 or 'true' to enable.  This controls whether or not the
-# "0-9 A B C D ..." links appear on the browse page.  We don't yet have a
-# serviceable way to internationalize these links, so sites must choose to
-# turn on this feature.
-
-browse.english_pager = 0;
-
 %]
diff --git a/docs/RELEASE_NOTES_NEXT/OPAC/BibAuthBrowse.txt b/docs/RELEASE_NOTES_NEXT/OPAC/BibAuthBrowse.txt
index 279bfbd..1f4bcac 100644
--- a/docs/RELEASE_NOTES_NEXT/OPAC/BibAuthBrowse.txt
+++ b/docs/RELEASE_NOTES_NEXT/OPAC/BibAuthBrowse.txt
@@ -26,14 +26,19 @@ Configuration considerations for site administrators
 There are two off-by-default features that site administrators may wish
 to enable.
 
-  * Quick paging links (English): By changing the
-    ''browse.english_pager'' setting to 1 in the
-    ''opac/parts/config.tt2'' file for a site's active OPAC templates,
-    you can make shortcut browsing links ''0-9 A B C D ...'' appear
-    between the Back and Forward buttons on the browse page. I haven't
-    figured out how to make this feature internationalizable, so it's
-    off by default.  You can turn it on if it works for your language,
-    or have a look at improving it if it doesn't.
+  * Quick paging links: By adding a value for the org unit setting
+    ''opac.browse.pager_shortcuts'' , you can make shortcut browsing
+    links such as ''0-9 A B C D ...'' appear between the Back and Next
+    buttons on the browse page. The set of shortcuts should be chosen
+    based on the languages in use at your site, but a reasonable value
+    for English might be the string "*0-9*ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+    which will yield a link for 0-9 and one for each letter A-Z.  The
+    use of asterisks in the string group a shortcut whose label is more
+    than a single letter in length.  Such longer shortcuts have the multi-
+    character string for the shortcut label, and the link just goes to the
+    first heading matching the first character of the label.  The letters
+    not enclosed in asterisks just lead to individual letter shortcuts.
+
 
   * There is a global flag by the name
     ''opac.browse.warnable_regexp_per_class'' to control what leading
@@ -43,3 +48,9 @@ to enable.
     enabled if it suits your catalog, and can even be customized per
     search class (author, title, series, subject).
 
+Also, by default, authors are indexed for browse in such a way that
+relator roles like "creator" are dropped off the end of their headings.
+This was an aesthetic choice. If a site wanted to display those kinds
+of terms, they would update the 'config.metabib_field' table in
+the database, setting 'browse_xpath' to NULL where 'field_class' =
+''author'' and 'browse_field' is true.

commit 6990fd819c0dae385c3cc7a40d39a0ebed91086c
Author: Mike Rylander <mrylander at gmail.com>
Date:   Fri Jul 19 12:35:31 2013 -0400

    Break up expensive queries, match index to quals
    
    First, we order browse queries over MBE by (sort_value, value) so we
    want to match the unique index to that.
    
    We're only going to use the first few rows of the cursors we build from
    the back/forward MBE paging queries, and the embedded GROUP BY defeats
    the planners desire to use an index for ordering the rows. So, instead,
    we use a simpler core query and gather aggregate data as a secondary,
    index-capable query for each MBE row.
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>

diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql
index 2014655..542eaed 100644
--- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql
+++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql
@@ -188,7 +188,7 @@ CREATE TABLE metabib.browse_entry (
     value TEXT,
     index_vector tsvector,
     sort_value  TEXT NOT NULL,
-    UNIQUE(value, sort_value)
+    UNIQUE(sort_value, value)
 );
 
 
@@ -1808,7 +1808,8 @@ END;
 $p$ LANGUAGE PLPGSQL;
 
 CREATE OR REPLACE FUNCTION metabib.staged_browse(
-    query               TEXT,
+    query                   TEXT,
+    fields                  INT[],
     context_org             INT,
     context_locations       INT[],
     staff                   BOOL,
@@ -1828,6 +1829,7 @@ DECLARE
     slice_start             INT;
     slice_end               INT;
     full_end                INT;
+    all_records             BIGINT[];
     superpage_of_records    BIGINT[];
     superpage_size          INT;
 BEGIN
@@ -1848,15 +1850,24 @@ BEGIN
             RETURN;
         END IF;
 
+        -- Gather aggregate data based on the MBE row we're looking at now
+        SELECT INTO all_records, result_row.authorities, result_row.fields
+                ARRAY_AGG(DISTINCT source),
+                ARRAY_TO_STRING(ARRAY_AGG(DISTINCT authority), $$,$$),
+                ARRAY_TO_STRING(ARRAY_AGG(DISTINCT def), $$,$$)
+          FROM  metabib.browse_entry_def_map
+          WHERE entry = rec.id
+                AND def = ANY(fields);
+
         result_row.sources := 0;
 
-        full_end := ARRAY_LENGTH(rec.records, 1);
+        full_end := ARRAY_LENGTH(all_records, 1);
         superpage_size := COALESCE(browse_superpage_size, full_end);
         slice_start := 1;
         slice_end := superpage_size;
 
         WHILE result_row.sources = 0 AND slice_start <= full_end LOOP
-            superpage_of_records := rec.records[slice_start:slice_end];
+            superpage_of_records := all_records[slice_start:slice_end];
             qpfts_query :=
                 'SELECT NULL::BIGINT AS id, ARRAY[r] AS records, ' ||
                 '1::INT AS rel FROM (SELECT UNNEST(' ||
@@ -1899,8 +1910,6 @@ BEGIN
 
             IF row_counter < result_limit THEN
                 result_row.browse_entry := rec.id;
-                result_row.authorities := rec.authorities;
-                result_row.fields := rec.fields;
                 result_row.value := rec.value;
 
                 RETURN NEXT result_row;
@@ -2007,43 +2016,33 @@ BEGIN
     SELECT
         mbe.id,
         mbe.value,
-        mbe.sort_value,
-        (SELECT ARRAY_AGG(src) FROM (
-            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.source)) AS src
-        ) ss) AS records,
-        (SELECT ARRAY_TO_STRING(ARRAY_AGG(authority), $$,$$) FROM (
-            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.authority)) AS authority
-        ) au) AS authorities,
-        (SELECT ARRAY_TO_STRING(ARRAY_AGG(field), $$,$$) FROM (
-            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.def)) AS field
-        ) fi) AS fields
+        mbe.sort_value
     FROM metabib.browse_entry mbe
-    JOIN metabib.browse_entry_def_map mbedm ON (
+    WHERE EXISTS (SELECT 1 FROM  metabib.browse_entry_def_map mbedm WHERE
         mbedm.entry = mbe.id AND
         mbedm.def = ANY(' || quote_literal(search_field) || ')
-    )
-    WHERE ';
+    ) AND ';
 
     -- This is the variant of the query for browsing backward.
     back_query := core_query ||
         ' mbe.sort_value <= ' || quote_literal(pivot_sort_value) ||
-    ' GROUP BY 1,2,3 ORDER BY mbe.sort_value DESC, mbe.value DESC ';
+    ' ORDER BY mbe.sort_value DESC, mbe.value DESC ';
 
     -- This variant browses forward.
     forward_query := core_query ||
         ' mbe.sort_value > ' || quote_literal(pivot_sort_value) ||
-    ' GROUP BY 1,2,3 ORDER BY mbe.sort_value, mbe.value ';
+    ' ORDER BY mbe.sort_value, mbe.value ';
 
     -- We now call the function which applies a cursor to the provided
     -- queries, stopping at the appropriate limits and also giving us
     -- the next page's pivot.
     RETURN QUERY
         SELECT * FROM metabib.staged_browse(
-            back_query, context_org, context_locations,
+            back_query, search_field, context_org, context_locations,
             staff, browse_superpage_size, TRUE, back_limit, back_to_pivot
         ) UNION
         SELECT * FROM metabib.staged_browse(
-            forward_query, context_org, context_locations,
+            forward_query, search_field, context_org, context_locations,
             staff, browse_superpage_size, FALSE, forward_limit, forward_to_pivot
         ) ORDER BY row_number DESC;
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
index 2077f9c..466053c 100644
--- a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
@@ -7126,7 +7126,7 @@ ALTER TABLE metabib.browse_entry ADD COLUMN sort_value TEXT;
 DELETE FROM metabib.browse_entry_def_map; -- Yeah.
 DELETE FROM metabib.browse_entry WHERE sort_value IS NULL;
 ALTER TABLE metabib.browse_entry ALTER COLUMN sort_value SET NOT NULL;
-ALTER TABLE metabib.browse_entry ADD UNIQUE (value, sort_value);
+ALTER TABLE metabib.browse_entry ADD UNIQUE (sort_value, value);
 DROP TRIGGER IF EXISTS mbe_sort_value ON metabib.browse_entry;
 
 CREATE INDEX browse_entry_sort_value_idx
@@ -7175,7 +7175,8 @@ END;
 $p$ LANGUAGE PLPGSQL;
 
 CREATE OR REPLACE FUNCTION metabib.staged_browse(
-    query               TEXT,
+    query                   TEXT,
+    fields                  INT[],
     context_org             INT,
     context_locations       INT[],
     staff                   BOOL,
@@ -7195,6 +7196,7 @@ DECLARE
     slice_start             INT;
     slice_end               INT;
     full_end                INT;
+    all_records             BIGINT[];
     superpage_of_records    BIGINT[];
     superpage_size          INT;
 BEGIN
@@ -7215,15 +7217,24 @@ BEGIN
             RETURN;
         END IF;
 
+        -- Gather aggregate data based on the MBE row we're looking at now
+        SELECT INTO all_records, result_row.authorities, result_row.fields
+                ARRAY_AGG(DISTINCT source),
+                ARRAY_TO_STRING(ARRAY_AGG(DISTINCT authority), $$,$$),
+                ARRAY_TO_STRING(ARRAY_AGG(DISTINCT def), $$,$$)
+          FROM  metabib.browse_entry_def_map
+          WHERE entry = rec.id
+                AND def = ANY(fields);
+
         result_row.sources := 0;
 
-        full_end := ARRAY_LENGTH(rec.records, 1);
+        full_end := ARRAY_LENGTH(all_records, 1);
         superpage_size := COALESCE(browse_superpage_size, full_end);
         slice_start := 1;
         slice_end := superpage_size;
 
         WHILE result_row.sources = 0 AND slice_start <= full_end LOOP
-            superpage_of_records := rec.records[slice_start:slice_end];
+            superpage_of_records := all_records[slice_start:slice_end];
             qpfts_query :=
                 'SELECT NULL::BIGINT AS id, ARRAY[r] AS records, ' ||
                 '1::INT AS rel FROM (SELECT UNNEST(' ||
@@ -7266,8 +7277,6 @@ BEGIN
 
             IF row_counter < result_limit THEN
                 result_row.browse_entry := rec.id;
-                result_row.authorities := rec.authorities;
-                result_row.fields := rec.fields;
                 result_row.value := rec.value;
 
                 RETURN NEXT result_row;
@@ -7301,7 +7310,6 @@ BEGIN
 END;
 $p$ LANGUAGE PLPGSQL;
 
-
 CREATE OR REPLACE FUNCTION metabib.browse(
     search_field            INT[],
     browse_term             TEXT,
@@ -7374,43 +7382,33 @@ BEGIN
     SELECT
         mbe.id,
         mbe.value,
-        mbe.sort_value,
-        (SELECT ARRAY_AGG(src) FROM (
-            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.source)) AS src
-        ) ss) AS records,
-        (SELECT ARRAY_TO_STRING(ARRAY_AGG(authority), $$,$$) FROM (
-            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.authority)) AS authority
-        ) au) AS authorities,
-        (SELECT ARRAY_TO_STRING(ARRAY_AGG(field), $$,$$) FROM (
-            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.def)) AS field
-        ) fi) AS fields
+        mbe.sort_value
     FROM metabib.browse_entry mbe
-    JOIN metabib.browse_entry_def_map mbedm ON (
+    WHERE EXISTS (SELECT 1 FROM  metabib.browse_entry_def_map mbedm WHERE
         mbedm.entry = mbe.id AND
         mbedm.def = ANY(' || quote_literal(search_field) || ')
-    )
-    WHERE ';
+    ) AND ';
 
     -- This is the variant of the query for browsing backward.
     back_query := core_query ||
         ' mbe.sort_value <= ' || quote_literal(pivot_sort_value) ||
-    ' GROUP BY 1,2,3 ORDER BY mbe.sort_value DESC, mbe.value DESC ';
+    ' ORDER BY mbe.sort_value DESC, mbe.value DESC ';
 
     -- This variant browses forward.
     forward_query := core_query ||
         ' mbe.sort_value > ' || quote_literal(pivot_sort_value) ||
-    ' GROUP BY 1,2,3 ORDER BY mbe.sort_value, mbe.value ';
+    ' ORDER BY mbe.sort_value, mbe.value ';
 
     -- We now call the function which applies a cursor to the provided
     -- queries, stopping at the appropriate limits and also giving us
     -- the next page's pivot.
     RETURN QUERY
         SELECT * FROM metabib.staged_browse(
-            back_query, context_org, context_locations,
+            back_query, search_field, context_org, context_locations,
             staff, browse_superpage_size, TRUE, back_limit, back_to_pivot
         ) UNION
         SELECT * FROM metabib.staged_browse(
-            forward_query, context_org, context_locations,
+            forward_query, search_field, context_org, context_locations,
             staff, browse_superpage_size, FALSE, forward_limit, forward_to_pivot
         ) ORDER BY row_number DESC;
 

commit c0dea517395c733b77e8eb219d2c3f43f6098d42
Author: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
Date:   Thu Jun 13 16:22:13 2013 -0400

    OPAC Browse: some squashed commits from LP #1177810
    
    Namely:
        OPAC Browse: Various interface improvements
        OPAC Browse: Put best-matched browse entry in middle of result set
        OPAC Browse: Don't try to build hyperlinks from 680 ‡a
        OPAC Browse: add a CSS class to the best-matching result when not paging
        Remove unwanted space before question makr in "Did you mean" message
        OPAC Browse: Fix browse interface's use of hits-per-page user setting
    
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
index cc9d73c..81644e6 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
@@ -15,6 +15,7 @@ use OpenSRF::Utils::SettingsClient;
 use Digest::MD5 qw/md5_hex/;
 use Apache2::Const -compile => qw/OK/;
 use MARC::Record;
+use List::Util qw/first/;
 #use Data::Dumper;
 #$Data::Dumper::Indent = 0;
 
@@ -53,12 +54,7 @@ sub prepare_browse_parameters {
 
     no warnings 'uninitialized';
 
-    # XXX TODO add config.global_flag rows for browse limit-limit and
-    # browse offset-limit?
-
-    my $limit = int($self->cgi->param('blimit') || 10);
-    my $offset = int($self->cgi->param('boffset') || 0);
-    my $force_backward = scalar($self->cgi->param('bback'));
+    # XXX TODO add config.global_flag rows for browse limit-limit ?
 
     my @params = (
         scalar($self->cgi->param('qtype')),
@@ -68,59 +64,36 @@ sub prepare_browse_parameters {
         $self->ctx->{copy_location_group},
         $self->ctx->{is_staff} ? 't' : 'f',
         scalar($self->cgi->param('bpivot')),
-        $force_backward ? 't' : 'f'
+        int(
+            $self->cgi->param('blimit') ||
+            $self->ctx->{opac_hits_per_page} || 10
+        )
     );
 
-    # We do need $limit, $offset, and $force_backward as part of the
-    # cache key, but we also need to keep them separate from other
-    # parameters for purposes of paging link generation.
     return (
-        "oils_browse_" . md5_hex(
-            OpenSRF::Utils::JSON->perl2JSON(
-                [@params, $limit, $offset, $force_backward]
-            )
-        ),
-        $limit, $offset, $force_backward, @params
+        "oils_browse_" . md5_hex(OpenSRF::Utils::JSON->perl2JSON(\@params)),
+        @params
     );
 }
 
-# Break out any Public General Notes (field 680) for display and
-# hyperlinking. These are sometimes (erroneously?) called "scope notes."
-# I say erroneously, tentatively, because LoC doesn't seem to document
-# a "scope notes" field for authority records, while it does so for
-# classification records, which are something else. But I am not a
-# librarian.
+# Break out any Public General Notes (field 680) for display. These are
+# sometimes (erroneously?) called "scope notes." I say erroneously,
+# tentatively, because LoC doesn't seem to document a "scope notes"
+# field for authority records, while it does so for classification
+# records, which are something else. But I am not a librarian.
 sub extract_public_general_notes {
     my ($self, $record, $row) = @_;
 
-    my @notes;
-    foreach my $note ($record->field('680')) {
-        my @note;
-        my $last_heading;
-
-        foreach my $subfield ($note->subfields) {
-            my ($code, $value) = @$subfield;
-
-            if ($code eq 'i') {
-                push @note, $value;
-            } elsif ($code eq '5') {
-                if ($last_heading) {
-                    my $org = $self->ctx->{get_aou_by_shortname}->($value);
-                    $last_heading->{org_id} = $org->id if $org;
-                }
-                push @note, { institution => $value };
-            } elsif ($code eq 'a') {
-                $last_heading = {
-                    heading => $value, bterm => search_normalize($value)
-                };
-                push @note, $last_heading;
-            }
-        }
-
-        push @notes, \@note if @note;
-    }
-
-    $row->{notes} = \@notes;
+    # Make a list of strings, each string being a concatentation of any
+    # subfields 'i', '5', or 'a' from one field 680, in order of appearance.
+    $row->{notes} = [
+        map {
+            join(
+                " ",
+                map { $_->[1] } grep { $_->[0] =~ /[i5a]/ } $_->subfields
+            )
+        } $record->field('680')
+    ];
 }
 
 sub find_authority_headings_and_notes {
@@ -273,15 +246,10 @@ sub flesh_browse_results {
 }
 
 sub load_browse_impl {
-    my ($self, $limit, $offset, $force_backward, @params) = @_;
-
-    my $inner_limit = ($offset >= 0 and not $force_backward) ?
-        $limit + 1 : $limit;
+    my ($self, @params) = @_;
 
     my $results = $self->editor->json_query({
-        from => [
-            "metabib.browse", (@params, $inner_limit, $offset)
-        ]
+        from => [ "metabib.browse", @params ]
     });
 
     if (not $results) {  # DB error, not empty result set.
@@ -303,50 +271,23 @@ sub load_browse_impl {
     return $results;
 }
 
-# $results can be modified by this function.  This would be simpler
-# but for the moving pivot concept that helps us avoid paging with
-# large offsets (slow).
+# Find paging information, put it into $self->ctx, and return "real"
+# rows from $results, excluding those that contain only paging
+# information.
 sub infer_browse_paging {
-    my ($self, $results, $limit, $offset, $force_backward) = @_;
-
-    # (All these comments assume a default limit of 10).  For typical
-    # not-backwards requests not at the end of the result set, we
-    # should have an eleventh result that tells us what's next.
-    while (scalar @$results > $limit) {
-        $self->ctx->{forward_pivot} = (pop @$results)->{browse_entry};
-        $self->ctx->{more_forward} = 1;
-    }
-
-    # If we're going backwards by pivot id, we don't have an eleventh
-    # result to tell us we can page forward, but we can assume we can
-    # go forward because duh, we followed a link backward to get here.
-    if ($force_backward and $self->cgi->param('bpivot')) {
-        $self->ctx->{forward_pivot} = scalar($self->cgi->param('bpivot'));
-        $self->ctx->{more_forward} = 1;
-    }
-
-    # The pivot that the user can use for going backwards is the first
-    # of the result set.
-    if (@$results) {
-        $self->ctx->{back_pivot} = $results->[0]->{browse_entry};
-    }
-
-    # The result of these tests relate to basic limit/offset paging.
+    my ($self, $results) = @_;
 
-    # This comparison for setting more_forward does not fold into
-    # those for setting more_back.
-    if ($offset < 0 || $force_backward) {
-        $self->ctx->{more_forward} = 1;
+    foreach (@$results) {
+        if ($_->{pivot_point}) {
+            if ($_->{row_number} < 0) { # sic
+                $self->ctx->{forward_pivot} = $_->{pivot_point};
+            } else {
+                $self->ctx->{back_pivot} = $_->{pivot_point};
+            }
+        }
     }
 
-    if ($offset > 0 or (!$force_backward and $self->cgi->param('bpivot'))) {
-        $self->ctx->{more_back} = 1;
-    } elsif (scalar @$results < $limit) {
-        $self->ctx->{more_back} = 0;
-    } elsif (not($self->cgi->param('bterm') eq '0' and
-        not defined $self->cgi->param('bpivot'))) {   # paging links
-        $self->ctx->{more_back} = 1;
-    }
+    return [ grep { not defined $_->{pivot_point} } @$results ];
 }
 
 sub leading_article_test {
@@ -370,6 +311,8 @@ sub leading_article_test {
         if ($map->{$qtype}) {
             if ($bterm =~ qr/$map->{$qtype}/i) {
                 $self->ctx->{browse_leading_article_warning} = 1;
+                ($self->ctx->{browse_leading_article_alternative} = $bterm) =~
+                    s/$map->{$qtype}//;
             }
         }
     };
@@ -383,8 +326,17 @@ sub load_browse {
 
     _init_browse_cache();
 
-    $self->ctx->{more_forward} = 0;
-    $self->ctx->{more_back} = 0;
+    # If there's a user logged in, flesh extended user info so we can get
+    # her opac.hits_per_page setting, if any.
+    if ($self->ctx->{user}) {
+        $self->prepare_extended_user_info('settings');
+        if (my $setting = first { $_->name eq 'opac.hits_per_page' }
+            @{$self->ctx->{user}->settings}) {
+
+            $self->ctx->{opac_hits_per_page} =
+                int(OpenSRF::Utils::JSON->JSON2perl($setting->value));
+        }
+    }
 
     if ($self->cgi->param('qtype') and defined $self->cgi->param('bterm')) {
 
@@ -393,24 +345,18 @@ sub load_browse {
             $self->cgi->param('bterm')
         );
 
-        my ($cache_key, $limit, $offset, $force_backward, @params) =
-            $self->prepare_browse_parameters;
+        my ($cache_key, @params) = $self->prepare_browse_parameters;
 
         my $results = $browse_cache->get_cache($cache_key);
         if (not $results) {
-            $results = $self->load_browse_impl(
-                $limit, $offset, $force_backward, @params
-            );
+            $results = $self->load_browse_impl(@params);
             if ($results) {
                 $browse_cache->put_cache($cache_key, $results, $browse_timeout);
             }
         }
 
         if ($results) {
-            $self->infer_browse_paging(
-                $results, $limit, $offset, $force_backward
-            );
-            $self->ctx->{browse_results} = $results;
+            $self->ctx->{browse_results} = $self->infer_browse_paging($results);
         }
 
         # We don't need an else clause to send the user a 5XX error or
diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql
index ae74fba..2014655 100644
--- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql
+++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql
@@ -1781,9 +1781,10 @@ CREATE TYPE metabib.flat_browse_entry_appearance AS (
     authorities     TEXT,
     sources         INT,        -- visible ones, that is
     row_number      INT,        -- internal use, sort of
-    accurate        BOOL        -- Count in sources field is accurate? Not
+    accurate        BOOL,       -- Count in sources field is accurate? Not
                                 -- if we had more than a browse superpage
                                 -- of records to look at.
+    pivot_point     BIGINT
 );
 
 
@@ -1807,42 +1808,55 @@ END;
 $p$ LANGUAGE PLPGSQL;
 
 CREATE OR REPLACE FUNCTION metabib.staged_browse(
-    core_query              TEXT,
+    query               TEXT,
     context_org             INT,
     context_locations       INT[],
     staff                   BOOL,
     browse_superpage_size   INT,
+    count_up_from_zero      BOOL,   -- if false, count down from -1
     result_limit            INT,
-    use_offset              INT
+    next_pivot_pos          INT
 ) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
 DECLARE
-    core_cursor             REFCURSOR;
-    core_record             RECORD;
+    curs                    REFCURSOR;
+    rec                     RECORD;
     qpfts_query             TEXT;
     result_row              metabib.flat_browse_entry_appearance%ROWTYPE;
     results_skipped         INT := 0;
-    results_returned        INT := 0;
+    row_counter             INT := 0;
+    row_number              INT;
     slice_start             INT;
     slice_end               INT;
     full_end                INT;
     superpage_of_records    BIGINT[];
     superpage_size          INT;
 BEGIN
-    OPEN core_cursor FOR EXECUTE core_query;
+    IF count_up_from_zero THEN
+        row_number := 0;
+    ELSE
+        row_number := -1;
+    END IF;
+
+    OPEN curs FOR EXECUTE query;
 
     LOOP
-        FETCH core_cursor INTO core_record;
-        EXIT WHEN NOT FOUND;
+        FETCH curs INTO rec;
+        IF NOT FOUND THEN
+            IF result_row.pivot_point IS NOT NULL THEN
+                RETURN NEXT result_row;
+            END IF;
+            RETURN;
+        END IF;
 
         result_row.sources := 0;
 
-        full_end := ARRAY_LENGTH(core_record.records, 1);
+        full_end := ARRAY_LENGTH(rec.records, 1);
         superpage_size := COALESCE(browse_superpage_size, full_end);
         slice_start := 1;
         slice_end := superpage_size;
 
         WHILE result_row.sources = 0 AND slice_start <= full_end LOOP
-            superpage_of_records := core_record.records[slice_start:slice_end];
+            superpage_of_records := rec.records[slice_start:slice_end];
             qpfts_query :=
                 'SELECT NULL::BIGINT AS id, ARRAY[r] AS records, ' ||
                 '1::INT AS rel FROM (SELECT UNNEST(' ||
@@ -1870,30 +1884,57 @@ BEGIN
             browse_superpage_size >= full_end;
 
         IF result_row.sources > 0 THEN
-            IF results_skipped < use_offset THEN
-                results_skipped := results_skipped + 1;
-                CONTINUE;
-            END IF;
+            -- We've got a browse entry with visible holdings. Yay.
+
 
-            result_row.browse_entry := core_record.id;
-            result_row.authorities := core_record.authorities;
-            result_row.fields := core_record.fields;
-            result_row.value := core_record.value;
+            -- The function that calls this function needs row_number in order
+            -- to correctly order results from two different runs of this
+            -- functions.
+            result_row.row_number := row_number;
 
-            -- This is needed so our caller can flip it and reverse it.
-            result_row.row_number := results_returned;
+            -- Now, if row_counter is still less than limit, return a row.  If
+            -- not, but it is less than next_pivot_pos, continue on without
+            -- returning actual result rows until we find
+            -- that next pivot, and return it.
 
-            RETURN NEXT result_row;
+            IF row_counter < result_limit THEN
+                result_row.browse_entry := rec.id;
+                result_row.authorities := rec.authorities;
+                result_row.fields := rec.fields;
+                result_row.value := rec.value;
 
-            results_returned := results_returned + 1;
+                RETURN NEXT result_row;
+            ELSE
+                result_row.browse_entry := NULL;
+                result_row.authorities := NULL;
+                result_row.fields := NULL;
+                result_row.value := NULL;
+                result_row.sources := NULL;
+                result_row.accurate := NULL;
+                result_row.pivot_point := rec.id;
+
+                IF row_counter >= next_pivot_pos THEN
+                    RETURN NEXT result_row;
+                    RETURN;
+                END IF;
+            END IF;
 
-            EXIT WHEN results_returned >= result_limit;
+            IF count_up_from_zero THEN
+                row_number := row_number + 1;
+            ELSE
+                row_number := row_number - 1;
+            END IF;
+
+            -- row_counter is different from row_number.
+            -- It simply counts up from zero so that we know when
+            -- we've reached our limit.
+            row_counter := row_counter + 1;
         END IF;
     END LOOP;
 END;
 $p$ LANGUAGE PLPGSQL;
 
--- This is optimized to be fast for values of result_offset near zero.
+
 CREATE OR REPLACE FUNCTION metabib.browse(
     search_field            INT[],
     browse_term             TEXT,
@@ -1901,20 +1942,23 @@ CREATE OR REPLACE FUNCTION metabib.browse(
     context_loc_group       INT DEFAULT NULL,
     staff                   BOOL DEFAULT FALSE,
     pivot_id                BIGINT DEFAULT NULL,
-    force_backward          BOOL DEFAULT FALSE,
-    result_limit            INT DEFAULT 10,
-    result_offset           INT DEFAULT 0   -- Can be negative!
+    result_limit            INT DEFAULT 10
 ) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
 DECLARE
     core_query              TEXT;
-    whole_query             TEXT;
+    back_query              TEXT;
+    forward_query           TEXT;
     pivot_sort_value        TEXT;
     pivot_sort_fallback     TEXT;
     context_locations       INT[];
-    use_offset              INT;
     browse_superpage_size   INT;
     results_skipped         INT := 0;
+    back_limit              INT;
+    back_to_pivot           INT;
+    forward_limit           INT;
+    forward_to_pivot        INT;
 BEGIN
+    -- First, find the pivot if we were given a browse term but not a pivot.
     IF pivot_id IS NULL THEN
         pivot_id := metabib.browse_pivot(search_field, browse_term);
     END IF;
@@ -1922,20 +1966,43 @@ BEGIN
     SELECT INTO pivot_sort_value, pivot_sort_fallback
         sort_value, value FROM metabib.browse_entry WHERE id = pivot_id;
 
+    -- Bail if we couldn't find a pivot.
     IF pivot_sort_value IS NULL THEN
         RETURN;
     END IF;
 
+    -- Transform the context_loc_group argument (if any) (logc at the
+    -- TPAC layer) into a form we'll be able to use.
     IF context_loc_group IS NOT NULL THEN
         SELECT INTO context_locations ARRAY_AGG(location)
             FROM asset.copy_location_group_map
             WHERE lgroup = context_loc_group;
     END IF;
 
+    -- Get the configured size of browse superpages.
     SELECT INTO browse_superpage_size value     -- NULL ok
         FROM config.global_flag
         WHERE enabled AND name = 'opac.browse.holdings_visibility_test_limit';
 
+    -- First we're going to search backward from the pivot, then we're going
+    -- to search forward.  In each direction, we need two limits.  At the
+    -- lesser of the two limits, we delineate the edge of the result set
+    -- we're going to return.  At the greater of the two limits, we find the
+    -- pivot value that would represent an offset from the current pivot
+    -- at a distance of one "page" in either direction, where a "page" is a
+    -- result set of the size specified in the "result_limit" argument.
+    --
+    -- The two limits in each direction make four derived values in total,
+    -- and we calculate them now.
+    back_limit := CEIL(result_limit::FLOAT / 2);
+    back_to_pivot := result_limit;
+    forward_limit := result_limit / 2;
+    forward_to_pivot := result_limit - 1;
+
+    -- This is the meat of the SQL query that finds browse entries.  We'll
+    -- pass this to a function which uses it with a cursor, so that individual
+    -- rows may be fetched in a loop until some condition is satisfied, without
+    -- waiting for a result set of fixed size to be collected all at once.
     core_query := '
     SELECT
         mbe.id,
@@ -1957,30 +2024,29 @@ BEGIN
     )
     WHERE ';
 
-    -- PostgreSQL is not magic. We can't actually pass a negative offset.
-    IF result_offset >= 0 AND NOT force_backward THEN
-        use_offset := result_offset;
-        core_query := core_query ||
-            ' mbe.sort_value >= ' || quote_literal(pivot_sort_value) ||
-        ' GROUP BY 1,2,3 ORDER BY mbe.sort_value, mbe.value ';
-
-        RETURN QUERY SELECT * FROM metabib.staged_browse(
-            core_query, context_org, context_locations,
-            staff, browse_superpage_size, result_limit, use_offset
-        );
-    ELSE
-        -- Part 1 of 2 to deliver what the user wants with a negative offset:
-        core_query := core_query ||
-            ' mbe.sort_value < ' || quote_literal(pivot_sort_value) ||
-        ' GROUP BY 1,2,3 ORDER BY mbe.sort_value DESC, mbe.value DESC ';
-
-        -- Part 2 of 2 to deliver what the user wants with a negative offset:
-        RETURN QUERY SELECT * FROM (SELECT * FROM metabib.staged_browse(
-            core_query, context_org, context_locations,
-            staff, browse_superpage_size, result_limit, use_offset
-        )) sb ORDER BY row_number DESC;
+    -- This is the variant of the query for browsing backward.
+    back_query := core_query ||
+        ' mbe.sort_value <= ' || quote_literal(pivot_sort_value) ||
+    ' GROUP BY 1,2,3 ORDER BY mbe.sort_value DESC, mbe.value DESC ';
+
+    -- This variant browses forward.
+    forward_query := core_query ||
+        ' mbe.sort_value > ' || quote_literal(pivot_sort_value) ||
+    ' GROUP BY 1,2,3 ORDER BY mbe.sort_value, mbe.value ';
+
+    -- We now call the function which applies a cursor to the provided
+    -- queries, stopping at the appropriate limits and also giving us
+    -- the next page's pivot.
+    RETURN QUERY
+        SELECT * FROM metabib.staged_browse(
+            back_query, context_org, context_locations,
+            staff, browse_superpage_size, TRUE, back_limit, back_to_pivot
+        ) UNION
+        SELECT * FROM metabib.staged_browse(
+            forward_query, context_org, context_locations,
+            staff, browse_superpage_size, FALSE, forward_limit, forward_to_pivot
+        ) ORDER BY row_number DESC;
 
-    END IF;
 END;
 $p$ LANGUAGE PLPGSQL;
 
@@ -1991,9 +2057,7 @@ CREATE OR REPLACE FUNCTION metabib.browse(
     context_loc_group   INT DEFAULT NULL,
     staff               BOOL DEFAULT FALSE,
     pivot_id            BIGINT DEFAULT NULL,
-    force_backward      BOOL DEFAULT FALSE,
-    result_limit        INT DEFAULT 10,
-    result_offset       INT DEFAULT 0   -- Can be negative, implying backward!
+    result_limit        INT DEFAULT 10
 ) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
 BEGIN
     RETURN QUERY SELECT * FROM metabib.browse(
@@ -2004,12 +2068,9 @@ BEGIN
         context_loc_group,
         staff,
         pivot_id,
-        force_backward,
-        result_limit,
-        result_offset
+        result_limit
     );
 END;
 $p$ LANGUAGE PLPGSQL;
 
-
 COMMIT;
diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
index e441641..2077f9c 100644
--- a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
@@ -7148,9 +7148,10 @@ CREATE TYPE metabib.flat_browse_entry_appearance AS (
     authorities     TEXT,
     sources         INT,        -- visible ones, that is
     row_number      INT,        -- internal use, sort of
-    accurate        BOOL        -- Count in sources field is accurate? Not
+    accurate        BOOL,       -- Count in sources field is accurate? Not
                                 -- if we had more than a browse superpage
                                 -- of records to look at.
+    pivot_point     BIGINT
 );
 
 
@@ -7174,42 +7175,55 @@ END;
 $p$ LANGUAGE PLPGSQL;
 
 CREATE OR REPLACE FUNCTION metabib.staged_browse(
-    core_query              TEXT,
+    query               TEXT,
     context_org             INT,
     context_locations       INT[],
     staff                   BOOL,
     browse_superpage_size   INT,
+    count_up_from_zero      BOOL,   -- if false, count down from -1
     result_limit            INT,
-    use_offset              INT
+    next_pivot_pos          INT
 ) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
 DECLARE
-    core_cursor             REFCURSOR;
-    core_record             RECORD;
+    curs                    REFCURSOR;
+    rec                     RECORD;
     qpfts_query             TEXT;
     result_row              metabib.flat_browse_entry_appearance%ROWTYPE;
     results_skipped         INT := 0;
-    results_returned        INT := 0;
+    row_counter             INT := 0;
+    row_number              INT;
     slice_start             INT;
     slice_end               INT;
     full_end                INT;
     superpage_of_records    BIGINT[];
     superpage_size          INT;
 BEGIN
-    OPEN core_cursor FOR EXECUTE core_query;
+    IF count_up_from_zero THEN
+        row_number := 0;
+    ELSE
+        row_number := -1;
+    END IF;
+
+    OPEN curs FOR EXECUTE query;
 
     LOOP
-        FETCH core_cursor INTO core_record;
-        EXIT WHEN NOT FOUND;
+        FETCH curs INTO rec;
+        IF NOT FOUND THEN
+            IF result_row.pivot_point IS NOT NULL THEN
+                RETURN NEXT result_row;
+            END IF;
+            RETURN;
+        END IF;
 
         result_row.sources := 0;
 
-        full_end := ARRAY_LENGTH(core_record.records, 1);
+        full_end := ARRAY_LENGTH(rec.records, 1);
         superpage_size := COALESCE(browse_superpage_size, full_end);
         slice_start := 1;
         slice_end := superpage_size;
 
         WHILE result_row.sources = 0 AND slice_start <= full_end LOOP
-            superpage_of_records := core_record.records[slice_start:slice_end];
+            superpage_of_records := rec.records[slice_start:slice_end];
             qpfts_query :=
                 'SELECT NULL::BIGINT AS id, ARRAY[r] AS records, ' ||
                 '1::INT AS rel FROM (SELECT UNNEST(' ||
@@ -7237,30 +7251,57 @@ BEGIN
             browse_superpage_size >= full_end;
 
         IF result_row.sources > 0 THEN
-            IF results_skipped < use_offset THEN
-                results_skipped := results_skipped + 1;
-                CONTINUE;
-            END IF;
+            -- We've got a browse entry with visible holdings. Yay.
 
-            result_row.browse_entry := core_record.id;
-            result_row.authorities := core_record.authorities;
-            result_row.fields := core_record.fields;
-            result_row.value := core_record.value;
 
-            -- This is needed so our caller can flip it and reverse it.
-            result_row.row_number := results_returned;
+            -- The function that calls this function needs row_number in order
+            -- to correctly order results from two different runs of this
+            -- functions.
+            result_row.row_number := row_number;
 
-            RETURN NEXT result_row;
+            -- Now, if row_counter is still less than limit, return a row.  If
+            -- not, but it is less than next_pivot_pos, continue on without
+            -- returning actual result rows until we find
+            -- that next pivot, and return it.
 
-            results_returned := results_returned + 1;
+            IF row_counter < result_limit THEN
+                result_row.browse_entry := rec.id;
+                result_row.authorities := rec.authorities;
+                result_row.fields := rec.fields;
+                result_row.value := rec.value;
 
-            EXIT WHEN results_returned >= result_limit;
+                RETURN NEXT result_row;
+            ELSE
+                result_row.browse_entry := NULL;
+                result_row.authorities := NULL;
+                result_row.fields := NULL;
+                result_row.value := NULL;
+                result_row.sources := NULL;
+                result_row.accurate := NULL;
+                result_row.pivot_point := rec.id;
+
+                IF row_counter >= next_pivot_pos THEN
+                    RETURN NEXT result_row;
+                    RETURN;
+                END IF;
+            END IF;
+
+            IF count_up_from_zero THEN
+                row_number := row_number + 1;
+            ELSE
+                row_number := row_number - 1;
+            END IF;
+
+            -- row_counter is different from row_number.
+            -- It simply counts up from zero so that we know when
+            -- we've reached our limit.
+            row_counter := row_counter + 1;
         END IF;
     END LOOP;
 END;
 $p$ LANGUAGE PLPGSQL;
 
--- This is optimized to be fast for values of result_offset near zero.
+
 CREATE OR REPLACE FUNCTION metabib.browse(
     search_field            INT[],
     browse_term             TEXT,
@@ -7268,20 +7309,23 @@ CREATE OR REPLACE FUNCTION metabib.browse(
     context_loc_group       INT DEFAULT NULL,
     staff                   BOOL DEFAULT FALSE,
     pivot_id                BIGINT DEFAULT NULL,
-    force_backward          BOOL DEFAULT FALSE,
-    result_limit            INT DEFAULT 10,
-    result_offset           INT DEFAULT 0   -- Can be negative!
+    result_limit            INT DEFAULT 10
 ) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
 DECLARE
     core_query              TEXT;
-    whole_query             TEXT;
+    back_query              TEXT;
+    forward_query           TEXT;
     pivot_sort_value        TEXT;
     pivot_sort_fallback     TEXT;
     context_locations       INT[];
-    use_offset              INT;
     browse_superpage_size   INT;
     results_skipped         INT := 0;
+    back_limit              INT;
+    back_to_pivot           INT;
+    forward_limit           INT;
+    forward_to_pivot        INT;
 BEGIN
+    -- First, find the pivot if we were given a browse term but not a pivot.
     IF pivot_id IS NULL THEN
         pivot_id := metabib.browse_pivot(search_field, browse_term);
     END IF;
@@ -7289,20 +7333,43 @@ BEGIN
     SELECT INTO pivot_sort_value, pivot_sort_fallback
         sort_value, value FROM metabib.browse_entry WHERE id = pivot_id;
 
+    -- Bail if we couldn't find a pivot.
     IF pivot_sort_value IS NULL THEN
         RETURN;
     END IF;
 
+    -- Transform the context_loc_group argument (if any) (logc at the
+    -- TPAC layer) into a form we'll be able to use.
     IF context_loc_group IS NOT NULL THEN
         SELECT INTO context_locations ARRAY_AGG(location)
             FROM asset.copy_location_group_map
             WHERE lgroup = context_loc_group;
     END IF;
 
+    -- Get the configured size of browse superpages.
     SELECT INTO browse_superpage_size value     -- NULL ok
         FROM config.global_flag
         WHERE enabled AND name = 'opac.browse.holdings_visibility_test_limit';
 
+    -- First we're going to search backward from the pivot, then we're going
+    -- to search forward.  In each direction, we need two limits.  At the
+    -- lesser of the two limits, we delineate the edge of the result set
+    -- we're going to return.  At the greater of the two limits, we find the
+    -- pivot value that would represent an offset from the current pivot
+    -- at a distance of one "page" in either direction, where a "page" is a
+    -- result set of the size specified in the "result_limit" argument.
+    --
+    -- The two limits in each direction make four derived values in total,
+    -- and we calculate them now.
+    back_limit := CEIL(result_limit::FLOAT / 2);
+    back_to_pivot := result_limit;
+    forward_limit := result_limit / 2;
+    forward_to_pivot := result_limit - 1;
+
+    -- This is the meat of the SQL query that finds browse entries.  We'll
+    -- pass this to a function which uses it with a cursor, so that individual
+    -- rows may be fetched in a loop until some condition is satisfied, without
+    -- waiting for a result set of fixed size to be collected all at once.
     core_query := '
     SELECT
         mbe.id,
@@ -7324,30 +7391,29 @@ BEGIN
     )
     WHERE ';
 
-    -- PostgreSQL is not magic. We can't actually pass a negative offset.
-    IF result_offset >= 0 AND NOT force_backward THEN
-        use_offset := result_offset;
-        core_query := core_query ||
-            ' mbe.sort_value >= ' || quote_literal(pivot_sort_value) ||
-        ' GROUP BY 1,2,3 ORDER BY mbe.sort_value, mbe.value ';
-
-        RETURN QUERY SELECT * FROM metabib.staged_browse(
-            core_query, context_org, context_locations,
-            staff, browse_superpage_size, result_limit, use_offset
-        );
-    ELSE
-        -- Part 1 of 2 to deliver what the user wants with a negative offset:
-        core_query := core_query ||
-            ' mbe.sort_value < ' || quote_literal(pivot_sort_value) ||
-        ' GROUP BY 1,2,3 ORDER BY mbe.sort_value DESC, mbe.value DESC ';
-
-        -- Part 2 of 2 to deliver what the user wants with a negative offset:
-        RETURN QUERY SELECT * FROM (SELECT * FROM metabib.staged_browse(
-            core_query, context_org, context_locations,
-            staff, browse_superpage_size, result_limit, use_offset
-        )) sb ORDER BY row_number DESC;
+    -- This is the variant of the query for browsing backward.
+    back_query := core_query ||
+        ' mbe.sort_value <= ' || quote_literal(pivot_sort_value) ||
+    ' GROUP BY 1,2,3 ORDER BY mbe.sort_value DESC, mbe.value DESC ';
+
+    -- This variant browses forward.
+    forward_query := core_query ||
+        ' mbe.sort_value > ' || quote_literal(pivot_sort_value) ||
+    ' GROUP BY 1,2,3 ORDER BY mbe.sort_value, mbe.value ';
+
+    -- We now call the function which applies a cursor to the provided
+    -- queries, stopping at the appropriate limits and also giving us
+    -- the next page's pivot.
+    RETURN QUERY
+        SELECT * FROM metabib.staged_browse(
+            back_query, context_org, context_locations,
+            staff, browse_superpage_size, TRUE, back_limit, back_to_pivot
+        ) UNION
+        SELECT * FROM metabib.staged_browse(
+            forward_query, context_org, context_locations,
+            staff, browse_superpage_size, FALSE, forward_limit, forward_to_pivot
+        ) ORDER BY row_number DESC;
 
-    END IF;
 END;
 $p$ LANGUAGE PLPGSQL;
 
@@ -7358,9 +7424,7 @@ CREATE OR REPLACE FUNCTION metabib.browse(
     context_loc_group   INT DEFAULT NULL,
     staff               BOOL DEFAULT FALSE,
     pivot_id            BIGINT DEFAULT NULL,
-    force_backward      BOOL DEFAULT FALSE,
-    result_limit        INT DEFAULT 10,
-    result_offset       INT DEFAULT 0   -- Can be negative, implying backward!
+    result_limit        INT DEFAULT 10
 ) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
 BEGIN
     RETURN QUERY SELECT * FROM metabib.browse(
@@ -7371,9 +7435,7 @@ BEGIN
         context_loc_group,
         staff,
         pivot_id,
-        force_backward,
-        result_limit,
-        result_offset
+        result_limit
     );
 END;
 $p$ LANGUAGE PLPGSQL;
diff --git a/Open-ILS/src/templates/opac/browse.tt2 b/Open-ILS/src/templates/opac/browse.tt2
index 35a9d5a..44062b6 100644
--- a/Open-ILS/src/templates/opac/browse.tt2
+++ b/Open-ILS/src/templates/opac/browse.tt2
@@ -7,10 +7,9 @@
     INCLUDE "opac/parts/topnav.tt2";
 
     ctx.page_title = l("Browse the Catalog");
-    blimit = CGI.param('blimit') || 10;
-    boffset = CGI.param('boffset') || 0;
+    blimit = CGI.param('blimit') || ctx.opac_hits_per_page || 10;
 
-    depart_list = ['blimit', 'bterm', 'boffset', 'bpivot', 'bback'];
+    depart_list = ['blimit', 'bterm', 'bpivot'];
 %]
 
     <div id="search-wrapper">
@@ -27,46 +26,49 @@
         <div id="main-content">
             <div id="browse-the-catalog">
                 <div id="browse-controls">
-                    <form method="get">
+                    <form method="get" onsubmit="$('browse-submit-spinner').className = ''; return true">
                         <input type="hidden" name="blimit"
                             value="[% blimit %]" />
 
                         [% control_qtype = INCLUDE "opac/parts/qtype_selector.tt2"
-                            id="browse-search-class" browse_only=1 %]
+                            id="browse-search-class" browse_only=1 plural=1 %]
 
                         [% control_bterm = BLOCK %]<input type="text" name="bterm" id="browse-term"
                             value="[% CGI.param('bterm') | html %]" />[% END %]
                         [% control_locg = INCLUDE build_org_selector id='browse-context'
                             show_loc_groups=1
                             arialabel=l('Select holding library') %]
-                        [% l('Browse by [_1] for [_2] held under [_3]', control_qtype, control_bterm, control_locg) %]
+                        [% l('Browse for [_1] starting with [_2] in [_3]', control_qtype, control_bterm, control_locg) %]
 
                         <input type="submit" value="[% l('Go') %]" />
+                        <img id="browse-submit-spinner" src="[% ctx.media_prefix %]/opac/images/progressbar_green.gif" class="hidden" style="width: 16px; height: 16px;" alt="" />
                     </form>
                 </div>
 
                 [% BLOCK browse_pager %]
                 <div class="browse-pager">
-                    [% IF ctx.more_back %]
-                    <a class="opac-button" href="[% mkurl('', {bpivot => ctx.back_pivot, bback => 1}) %]">&larr; [%l ('Back') %]</a>
+                    [% IF ctx.back_pivot %]
+                    <a class="opac-button" href="[% mkurl('', {bpivot => ctx.back_pivot}) %]" onclick="$('browse-pager-spinner-[% id %]').className = '';">&larr; [%l ('Back') %]</a>
                     [% END %]
                     [% IF browse.english_pager; # XXX how to apply i18n here?
                         current_qtype = CGI.param('qtype') || 'title' %]
                     <span class="browse-shortcuts">
-                        <a href="[% mkurl('', {qtype => current_qtype, bterm => '0'}, ['boffset','bpivot','bback']) %]">0-9</a>
+                        <a href="[% mkurl('', {qtype => current_qtype, bterm => '0'}, ['bpivot']) %]">0-9</a>
                         [% FOR letter IN ['A'..'Z'] %]
-                            <a href="[% mkurl('', {qtype => current_qtype, bterm => letter}, ['boffset','bpivot','bback']) %]">[% letter %]</a>
+                            <a href="[% mkurl('', {qtype => current_qtype, bterm => letter}, ['bpivot']) %]">[% letter %]</a>
                         [% END %]
                     </span>
                     [% END %]
 
-                    [% IF ctx.more_forward %]
-                    <a class="opac-button" href="[% mkurl('', {bpivot => ctx.forward_pivot}, ['bback']) %]">[%l ('Forward') %] &rarr;</a>
+                    [% IF ctx.forward_pivot %]
+                    <a class="opac-button" href="[% mkurl('', {bpivot => ctx.forward_pivot}) %]" onclick="$('browse-pager-spinner-[% id %]').className = '';">[%l ('Next') %] &rarr;</a>
                     [% END %]
+
+                    <img id="browse-pager-spinner-[% id %]" src="[% ctx.media_prefix %]/opac/images/progressbar_green.gif" class="hidden" style="width: 16px; height: 16px;" alt="" />
                 </div>
                 [% END %]
 
-                [% PROCESS browse_pager %]
+                [% PROCESS browse_pager id=0 %]
 
                 <div id="browse-results">
                 [% IF ctx.browse_error %]
@@ -78,13 +80,22 @@
                 [% ELSE %]
                     [% IF ctx.browse_leading_article_warning %]
                     <div class="browse-leading-article-warning">
-                            [% l("Your browse term seems to begin with an article. You might get better results by omitting the article.") %]
+                            [% l("Your browse term seems to begin with an article (a, an, the). You might get better results by omitting the article.") %]
+                            [% IF ctx.browse_leading_article_alternative %]
+                            <p>
+                            [% alternative_link = BLOCK %]
+                            <a href="[% mkurl('', {bterm => ctx.browse_leading_article_alternative}, ['bpivot']) %]">[% ctx.browse_leading_article_alternative | html %]</a>
+                            [%-  END; # alternative_link BLOCK
+                                l("Did you mean [_1]?", alternative_link);
+                            END # IF %]
+                            </p>
                     </div>
                     [% END %]
-                    <ul class="browse-result-list">
+
+                    <ol class="browse-result-list">
                     [% FOR result IN ctx.browse_results %]
                         <li class="browse-result">
-                            <span class="browse-result-value">
+                            <span class="browse-result-value[% result.row_number == 0 && !CGI.param('bpivot') ? ' browse-result-best-match' : '' %]">
                                 <a href="[% mkurl(
                                     ctx.opac_root _ '/results', {
                                         'fi:has_browse_entry' => (result.browse_entry _ ',' _ result.fields)
@@ -135,7 +146,7 @@
                 [% END %]
                 </div>
 
-                [% PROCESS browse_pager %]
+                [% PROCESS browse_pager id=1 %]
             </div>
 
             <div class="common-full-pad"></div>	
@@ -150,22 +161,7 @@
                     [% l("Note:") %]
                 </span>
                 <span class="browse-public-general-note-body">
-            [% FOR piece IN note;
-                IF piece.heading;
-                    mkurl_args = {bterm => piece.bterm};
-                    IF piece.org_id;
-                        mkurl_args.locg = piece.org_id;
-                    END;
-                %]
-                <a href="[% mkurl('', mkurl_args, ['boffset','bpivot','bback']) %]">[% piece.heading | html %]</a>
-                [% ELSIF piece.institution %]
-                <span class="browse-public-general-note-institution">
-                    [% piece.institution | html %]
-                </span>
-                [% ELSE %]
-                    [% piece | html %]
-                [% END;
-            END %]
+                [% FOR piece IN note; piece | html; END %]
                 </span>
             </div>
         [% END;
diff --git a/Open-ILS/src/templates/opac/css/style.css.tt2 b/Open-ILS/src/templates/opac/css/style.css.tt2
index 3efc864..422fdd6 100644
--- a/Open-ILS/src/templates/opac/css/style.css.tt2
+++ b/Open-ILS/src/templates/opac/css/style.css.tt2
@@ -1543,11 +1543,14 @@ a.preflib_change {
 .browse-result-sources, .browse-result-authority-bib-links {
     margin-left: 1em;
 }
+.browse-result-best-match {
+    font-weight: bold;
+}
 .browse-pager {
     margin: 2ex 0;
 }
 .browse-result-list {
-    list-style-type: square;
+    padding-bottom: 0.5ex;
 }
 .browse-shortcuts {
     font-size: 120%;
diff --git a/Open-ILS/src/templates/opac/parts/qtype_selector.tt2 b/Open-ILS/src/templates/opac/parts/qtype_selector.tt2
index 30edbc6..6986fc1 100644
--- a/Open-ILS/src/templates/opac/parts/qtype_selector.tt2
+++ b/Open-ILS/src/templates/opac/parts/qtype_selector.tt2
@@ -1,10 +1,10 @@
 [%  query_types = [
     {value => "keyword", label => l("Keyword")},
-    {value => "title", label => l("Title"), browse => 1},
+    {value => "title", label => l("Title"), plural_label => l("Titles"), browse => 1},
     {value => "jtitle", label => l("Journal Title")},
-    {value => "author", label => l("Author"), browse => 1},
-    {value => "subject", label => l("Subject"), browse => 1},
-    {value => "series", label => l("Series"), browse => 1},
+    {value => "author", label => l("Author"), plural_label => l("Authors"), browse => 1},
+    {value => "subject", label => l("Subject"), plural_label => l("Subjects"), browse => 1},
+    {value => "series", label => l("Series"), plural_label => l("Series"), browse => 1},
     {value => "id|bibcn", label => l("Bib Call Number")}
 ] %]
 <select name="[% name || 'qtype' %]"[% IF id; ' id="'; id ; '"' ; END -%]
@@ -14,6 +14,10 @@
         NEXT IF browse_only AND NOT qt.browse -%]
     <option value='[% qt.value | html %]'[%
         query_type == qt.value ? ' selected="selected"' : ''
-    %]>[% qt.label | html %]</option>
+    %]>[% IF plural AND qt.plural_label;
+        qt.plural_label | html;
+    ELSE;
+        qt.label | html;
+    END %]</option>
     [% END -%]
 </select>

commit 9d37f6890ce6b591d62972ce3e341cecf7c45535
Author: Jason Stephenson <jstephenson at mvlc.org>
Date:   Fri Jun 7 10:31:30 2013 -0400

    Fix problem with YYYY.schema.bib-auth-browse.sql.
    
    Disable ALL triggers on authority.control_set_authority_field before
    altering and updating the table to avoid an error related to altering
    a table with pending trigger events.
    
    The triggers are enabled again after the updates and alters are done.
    
    Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>

diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
index 66c8fcb..e441641 100644
--- a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
@@ -3,6 +3,11 @@ BEGIN;
 -- check whether patch can be applied
 -- SELECT evergreen.upgrade_deps_block_check('YYYY', :eg_version);
 
+-- To avoid problems with altering a table column after doing an
+-- update.
+ALTER TABLE authority.control_set_authority_field
+    DISABLE TRIGGER ALL;
+
 ALTER TABLE authority.control_set_authority_field
     ADD COLUMN display_sf_list TEXT;
 
@@ -12,6 +17,9 @@ UPDATE authority.control_set_authority_field
 ALTER TABLE authority.control_set_authority_field
     ALTER COLUMN display_sf_list SET NOT NULL;
 
+ALTER TABLE authority.control_set_authority_field
+    ENABLE TRIGGER ALL;
+
 ALTER TABLE metabib.browse_entry_def_map
     ADD COLUMN authority BIGINT REFERENCES authority.record_entry (id)
         ON DELETE SET NULL;

commit e710ecbee519d374bcf69b0c535c3f83814c782b
Author: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
Date:   Wed Apr 24 10:46:27 2013 -0400

    Bib record browser with 'see also', etc from linked authority headings
    
    This feature provides a patron-oriented OPAC interface for browsing
    bibliographic records.
    
    Users choose to browse by Author, Title, Subject, or Series. They then
    enter a browse term, and the nearest match from a left-anchored search
    on the headings extracted for browse purposes will be displayed in a
    typical backwards/forwards paging display. Headings link to search
    results pages showing the related records. If the browse heading is
    linked to any authority records, and if any *other* authority records
    point to those with "See also" or other non-main entry headings, those
    alternative headings are displayed a linked to a search results page
    showing related bib records related to the alternate heading.
    
    The counts of holdings displayed next to headings from bibliographic
    records are subject to the same visiibility tests as search. This means
    that the org unit (and copy location group) dropdown on the browse
    interface affects counds, and it further means that whether or not
    you're looking at the browse interface through the staff client makes a
    difference.
    
    This builds on the two previous commits that provide inter-authority
    linking and the linking of metabib.browse_entry rows to authority
    records.
    
    This also contains, in squashed form, these commits that resulted from
    collaboration on LP #1177810:
    
        Two bugfixes to OPAC Browse: non-filing indicators, leading-article warning
        Fix paste-o encountered in Bib browse upgrade script
        OPAC Browse: fix 0-9 link in paging shortcuts; padding issues
        OPAC Browse: Improve authority code to show more headings
        OPAC Browse: Fix authority counting
        Extensions to our MODS32 stylesheet to capture all possible NFI in fields
        OPAC Browse: i18n improvement for short terms
        OPAC Browser: Display Public General Notes from authorities when possible
        OPAC Browse: Build browse entry sort_value column separately from value
        OPAC Browse: We don't want role/relator info in browse headings
        OPAC Browse: Better display of tracings from authorities
        OPAC Browse: Pick up authority links from 650 fields
        OPAC Browse: Show authority tracings only when inter-authority links exist
        OPAC Browse: use  superpage concept for performance; fix other counting bug
        OPAC Browse: Fix broken authority reference link
    
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>

diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml
index a439d6d..f7843ba 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -2116,6 +2116,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 			<field reporter:label="Control Set" name="control_set" reporter:datatype="link"/>
 			<field reporter:label="Tag" name="tag" reporter:datatype="text" oils_obj:required="true" oils_obj:validate="^.{3}$"/>
 			<field reporter:label="Subfield List" name="sf_list" reporter:datatype="text" />
+			<field reporter:label="Subfield List for Display" name="display_sf_list" reporter:datatype="text" />
 			<field reporter:label="Non-filing Indicator" name="nfi" reporter:datatype="text" />
 			<field reporter:label="Name" name="name" reporter:datatype="text" oils_persist:i18n="true" oils_obj:required="true" />
 			<field reporter:label="Description" name="description" reporter:datatype="text" oils_persist:i18n="true" />
@@ -5852,6 +5853,19 @@ SELECT  usr,
 			<link field="record" reltype="has_a" key="id" map="" class="are"/>
 		</links>
 	</class>
+	<class id="aalink" controller="open-ils.cstore" oils_obj:fieldmapper="authority::authority_linking" oils_persist:tablename="authority.authority_linking" reporter:label="Authority to Authority Linking">
+		<fields oils_persist:primary="id" oils_persist:sequence="authority.authority_linking_id_seq">
+			<field name="id" reporter:label="ID" reporter:datatype="id" />
+			<field name="source" reporter:label="Source Record" reporter:datatype="link" />
+			<field name="target" reporter:label="Target Record" reporter:datatype="link" />
+			<field name="field" reporter:label="Authority Field" reporter:datatype="link" />
+		</fields>
+		<links>
+			<link field="source" reltype="has_a" key="id" map="" class="are"/>
+			<link field="target" reltype="has_a" key="id" map="" class="are"/>
+			<link field="field" reltype="has_a" key="id" map="" class="acsaf"/>
+		</links>
+	</class>
 	<class id="cnct" controller="open-ils.cstore" oils_obj:fieldmapper="config::non_cataloged_type" oils_persist:tablename="config.non_cataloged_type" reporter:label="Non-cataloged Type">
 		<fields oils_persist:primary="id" oils_persist:sequence="config.non_cataloged_type_id_seq">
 			<field reporter:label="Circulation Duration" name="circ_duration" reporter:datatype="interval"/>
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
index 82644f9..92f1daf 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
@@ -17,6 +17,7 @@ use UUID::Tiny;
 use Encode;
 use DateTime;
 use DateTime::Format::ISO8601;
+use List::MoreUtils qw/uniq/;
 
 # ---------------------------------------------------------------------------
 # Pile of utilty methods used accross applications.
@@ -2120,6 +2121,22 @@ sub strip_marc_fields {
     return $class->entityize($marcdoc->documentElement->toString);
 }
 
+# Given a list of PostgreSQL arrays of numbers,
+# unnest the numbers and return a unique set, skipping any list elements
+# that are just '{NULL}'.
+sub unique_unnested_numbers {
+    my $class = shift;
+
+    no warnings 'numeric';
+
+    return uniq(
+        map(
+            int,
+            map { $_ eq 'NULL' ? undef : (split /,/, $_) }
+                map { substr($_, 1, -1) } @_
+        )
+    );
+}
 
 1;
 
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
index 431e26f..544dba9 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
@@ -666,6 +666,8 @@ __PACKAGE__->add_search_filter( 'container' );
 # Start from a list of record ids, either bre or metarecords, depending on the #metabib modifier
 __PACKAGE__->add_search_filter( 'record_list' );
 
+__PACKAGE__->add_search_filter( 'has_browse_entry' );
+
 # used internally, but generally not user-settable
 __PACKAGE__->add_search_filter( 'preferred_language' );
 __PACKAGE__->add_search_filter( 'preferred_language_weight' );
@@ -1110,6 +1112,12 @@ sub flatten {
                     $where .= "$key ${NOT}IN (" . join(',', map { $self->QueryParser->quote_value($_) } @{$filter->args}) . ')';
                 }
 
+            } elsif ($filter->name eq 'has_browse_entry') {
+                if (@{$filter->args} >= 2) {
+                    my $entry = int(shift @{$filter->args});
+                    my $fields = join(",", map(int, @{$filter->args}));
+                    $from .= "\n" . $spc x 3 . sprintf("INNER JOIN metabib.browse_entry_def_map mbedm ON (mbedm.source = m.source AND mbedm.entry = %d AND mbedm.def IN (%s))", $entry, $fields);
+                }
             } elsif ($filter->name eq 'edit_date' or $filter->name eq 'create_date') {
                 # bre.create_date and bre.edit_date filtering
                 my $datefilter = $filter->name;
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
index 0838a29..244afa2 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
@@ -19,6 +19,7 @@ use Time::HiRes;
 # EGCatLoader sub-modules 
 use OpenILS::WWW::EGCatLoader::Util;
 use OpenILS::WWW::EGCatLoader::Account;
+use OpenILS::WWW::EGCatLoader::Browse;
 use OpenILS::WWW::EGCatLoader::Search;
 use OpenILS::WWW::EGCatLoader::Record;
 use OpenILS::WWW::EGCatLoader::Container;
@@ -123,6 +124,7 @@ sub load {
     return $self->load_print_record if $path =~ m|opac/record/print|;
     return $self->load_record if $path =~ m|opac/record/\d|;
     return $self->load_cnbrowse if $path =~ m|opac/cnbrowse|;
+    return $self->load_browse if $path =~ m|opac/browse|;
 
     return $self->load_mylist_add if $path =~ m|opac/mylist/add|;
     return $self->load_mylist_delete if $path =~ m|opac/mylist/delete|;
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
new file mode 100644
index 0000000..cc9d73c
--- /dev/null
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
@@ -0,0 +1,424 @@
+package OpenILS::WWW::EGCatLoader;
+
+use strict;
+use warnings;
+
+use OpenSRF::Utils::Logger qw/$logger/;
+use OpenILS::Utils::CStoreEditor qw/:funcs/;
+use OpenILS::Utils::Fieldmapper;
+use OpenILS::Utils::Normalize qw/search_normalize/;
+use OpenILS::Application::AppUtils;
+use OpenSRF::Utils::JSON;
+use OpenSRF::Utils::Cache;
+use OpenSRF::Utils::SettingsClient;
+
+use Digest::MD5 qw/md5_hex/;
+use Apache2::Const -compile => qw/OK/;
+use MARC::Record;
+#use Data::Dumper;
+#$Data::Dumper::Indent = 0;
+
+my $U = 'OpenILS::Application::AppUtils';
+my $browse_cache;
+my $browse_timeout;
+
+# Plain procedural functions start here.
+#
+sub _init_browse_cache {
+    if (not defined $browse_cache) {
+        my $conf = new OpenSRF::Utils::SettingsClient;
+
+        $browse_timeout = $conf->config_value(
+            "apps", "open-ils.search", "app_settings", "cache_timeout"
+        ) || 300;
+        $browse_cache = new OpenSRF::Utils::Cache("global");
+    }
+}
+
+sub _get_authority_heading {
+    my ($field, $sf_lookup) = @_;
+
+    return join(
+        " ",
+        map { $_->[1] } grep { $sf_lookup->{$_->[0]} } $field->subfields
+    );
+}
+
+# Object methods start here.
+#
+
+# Returns cache key and a list of parameters for DB proc metabib.browse().
+sub prepare_browse_parameters {
+    my ($self) = @_;
+
+    no warnings 'uninitialized';
+
+    # XXX TODO add config.global_flag rows for browse limit-limit and
+    # browse offset-limit?
+
+    my $limit = int($self->cgi->param('blimit') || 10);
+    my $offset = int($self->cgi->param('boffset') || 0);
+    my $force_backward = scalar($self->cgi->param('bback'));
+
+    my @params = (
+        scalar($self->cgi->param('qtype')),
+        scalar($self->cgi->param('bterm')),
+        $self->ctx->{copy_location_group_org} ||
+            $self->ctx->{aou_tree}->()->id,
+        $self->ctx->{copy_location_group},
+        $self->ctx->{is_staff} ? 't' : 'f',
+        scalar($self->cgi->param('bpivot')),
+        $force_backward ? 't' : 'f'
+    );
+
+    # We do need $limit, $offset, and $force_backward as part of the
+    # cache key, but we also need to keep them separate from other
+    # parameters for purposes of paging link generation.
+    return (
+        "oils_browse_" . md5_hex(
+            OpenSRF::Utils::JSON->perl2JSON(
+                [@params, $limit, $offset, $force_backward]
+            )
+        ),
+        $limit, $offset, $force_backward, @params
+    );
+}
+
+# Break out any Public General Notes (field 680) for display and
+# hyperlinking. These are sometimes (erroneously?) called "scope notes."
+# I say erroneously, tentatively, because LoC doesn't seem to document
+# a "scope notes" field for authority records, while it does so for
+# classification records, which are something else. But I am not a
+# librarian.
+sub extract_public_general_notes {
+    my ($self, $record, $row) = @_;
+
+    my @notes;
+    foreach my $note ($record->field('680')) {
+        my @note;
+        my $last_heading;
+
+        foreach my $subfield ($note->subfields) {
+            my ($code, $value) = @$subfield;
+
+            if ($code eq 'i') {
+                push @note, $value;
+            } elsif ($code eq '5') {
+                if ($last_heading) {
+                    my $org = $self->ctx->{get_aou_by_shortname}->($value);
+                    $last_heading->{org_id} = $org->id if $org;
+                }
+                push @note, { institution => $value };
+            } elsif ($code eq 'a') {
+                $last_heading = {
+                    heading => $value, bterm => search_normalize($value)
+                };
+                push @note, $last_heading;
+            }
+        }
+
+        push @notes, \@note if @note;
+    }
+
+    $row->{notes} = \@notes;
+}
+
+sub find_authority_headings_and_notes {
+    my ($self, $row) = @_;
+
+    my $acsaf_table =
+        $self->ctx->{get_authority_fields}->($row->{control_set});
+
+    $row->{headings} = [];
+
+    my $record;
+    eval {
+        $record = new_from_xml MARC::Record($row->{marc});
+    };
+    if ($@) {
+        $logger->warn("Problem with MARC from authority record #" .
+            $row->{id} . ": $@");
+        return $row;    # We're called in map(), so we must move on without
+                        # a fuss.
+    }
+
+    $self->extract_public_general_notes($record, $row);
+
+    # By applying grep in this way, we get acsaf objects that *have* and
+    # therefore *aren't* main entries, which is what we want.
+    foreach my $acsaf (grep { $_->main_entry } values(%$acsaf_table)) {
+        my @fields = $record->field($acsaf->tag);
+        my %sf_lookup = map { $_ => 1 } split("", $acsaf->display_sf_list);
+        my @headings;
+
+        foreach my $field (@fields) {
+            my $h = { heading => _get_authority_heading($field, \%sf_lookup) };
+
+            # XXX I was getting "target" from authority.authority_linking, but
+            # that makes no sense: that table can only tell you that one
+            # authority record as a whole points at another record.  It does
+            # not record when a specific *field* in one authority record
+            # points to another record (not that it makes much sense for
+            # one authority record to have links to multiple others, but I can't
+            # say there definitely aren't cases for that).
+            $h->{target} = $2
+                if ($field->subfield('0') || "") =~ /(^|\))(\d+)$/;
+
+            push @headings, $h;
+        }
+
+        push @{$row->{headings}}, {$acsaf->id => \@headings} if @headings;
+    }
+
+    return $row;
+}
+
+sub map_authority_headings_to_results {
+    my ($self, $linked, $results, $auth_ids) = @_;
+
+    # Use the linked authority records' control sets to find and pick
+    # out non-main-entry headings. Build the headings and make a
+    # combined data structure for the template's use.
+    my %linked_headings_by_auth_id = map {
+        $_->{id} => $self->find_authority_headings_and_notes($_)
+    } @$linked;
+
+    # Graft this authority heading data onto our main result set at the
+    # "authorities" column.
+    foreach my $row (@$results) {
+        $row->{authorities} = [
+            map { $linked_headings_by_auth_id{$_} } @{$row->{authorities}}
+        ];
+    }
+
+    # Get linked-bib counts for each of those authorities, and put THAT
+    # information into place in the data structure.
+    my $counts = $self->editor->json_query({
+        select => {
+            abl => [
+                {column => "id", transform => "count",
+                    alias => "count", aggregate => 1},
+                "authority"
+            ]
+        },
+        from => {abl => {}},
+        where => {
+            "+abl" => {
+                authority => [
+                    @$auth_ids,
+                    $U->unique_unnested_numbers(map { $_->{target} } @$linked)
+                ]
+            }
+        }
+    }) or return;
+
+    my %auth_counts = map { $_->{authority} => $_->{count} } @$counts;
+
+    # Soooo nesty!  We look for places where we'll need a count of bibs
+    # linked to an authority record, and put it there for the template to find.
+    for my $row (@$results) {
+        for my $auth (@{$row->{authorities}}) {
+            if ($auth->{headings}) {
+                for my $outer_heading (@{$auth->{headings}}) {
+                    for my $heading_blob (@{(values %$outer_heading)[0]}) {
+                        if ($heading_blob->{target}) {
+                            $heading_blob->{target_count} =
+                                $auth_counts{$heading_blob->{target}};
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+
+# flesh_browse_results() attaches data from authority records. It
+# changes $results and returns 1 for success, undef for failure (in which
+# case $self->editor->event should always point to the reason for failure).
+# $results must be an arrayref of result rows from the DB's metabib.browse()
+sub flesh_browse_results {
+    my ($self, $results) = @_;
+
+    # Turn comma-seprated strings of numbers in "authorities" column
+    # into arrays.
+    $_->{authorities} = [split /,/, $_->{authorities}] foreach @$results;
+
+    # Group them in one arrray, not worrying about dupes because we're about
+    # to use them in an IN () comparison in a SQL query.
+    my @auth_ids = map { @{$_->{authorities}} } @$results;
+
+    if (@auth_ids) {
+        # Get all linked authority records themselves
+        my $linked = $self->editor->json_query({
+            select => {
+                are => [qw/id marc control_set/],
+                aalink => [{column => "target", transform => "array_agg",
+                    aggregate => 1}]
+            },
+            from => {
+                are => {
+                    aalink => {
+                        type => "left",
+                        fkey => "id", field => "source"
+                    }
+                }
+            },
+            where => {"+are" => {id => \@auth_ids}}
+        }) or return;
+
+        $self->map_authority_headings_to_results($linked, $results, \@auth_ids);
+    }
+
+    return 1;
+}
+
+sub load_browse_impl {
+    my ($self, $limit, $offset, $force_backward, @params) = @_;
+
+    my $inner_limit = ($offset >= 0 and not $force_backward) ?
+        $limit + 1 : $limit;
+
+    my $results = $self->editor->json_query({
+        from => [
+            "metabib.browse", (@params, $inner_limit, $offset)
+        ]
+    });
+
+    if (not $results) {  # DB error, not empty result set.
+        $logger->warn(
+            "error in browse (direct): " . $self->editor->event->{textcode}
+        );
+        $self->ctx->{browse_error} = 1;
+
+        return;
+    } elsif (not $self->flesh_browse_results($results)) {
+        $logger->warn(
+            "error in browse (flesh): " . $self->editor->event->{textcode}
+        );
+        $self->ctx->{browse_error} = 1;
+
+        return;
+    }
+
+    return $results;
+}
+
+# $results can be modified by this function.  This would be simpler
+# but for the moving pivot concept that helps us avoid paging with
+# large offsets (slow).
+sub infer_browse_paging {
+    my ($self, $results, $limit, $offset, $force_backward) = @_;
+
+    # (All these comments assume a default limit of 10).  For typical
+    # not-backwards requests not at the end of the result set, we
+    # should have an eleventh result that tells us what's next.
+    while (scalar @$results > $limit) {
+        $self->ctx->{forward_pivot} = (pop @$results)->{browse_entry};
+        $self->ctx->{more_forward} = 1;
+    }
+
+    # If we're going backwards by pivot id, we don't have an eleventh
+    # result to tell us we can page forward, but we can assume we can
+    # go forward because duh, we followed a link backward to get here.
+    if ($force_backward and $self->cgi->param('bpivot')) {
+        $self->ctx->{forward_pivot} = scalar($self->cgi->param('bpivot'));
+        $self->ctx->{more_forward} = 1;
+    }
+
+    # The pivot that the user can use for going backwards is the first
+    # of the result set.
+    if (@$results) {
+        $self->ctx->{back_pivot} = $results->[0]->{browse_entry};
+    }
+
+    # The result of these tests relate to basic limit/offset paging.
+
+    # This comparison for setting more_forward does not fold into
+    # those for setting more_back.
+    if ($offset < 0 || $force_backward) {
+        $self->ctx->{more_forward} = 1;
+    }
+
+    if ($offset > 0 or (!$force_backward and $self->cgi->param('bpivot'))) {
+        $self->ctx->{more_back} = 1;
+    } elsif (scalar @$results < $limit) {
+        $self->ctx->{more_back} = 0;
+    } elsif (not($self->cgi->param('bterm') eq '0' and
+        not defined $self->cgi->param('bpivot'))) {   # paging links
+        $self->ctx->{more_back} = 1;
+    }
+}
+
+sub leading_article_test {
+    my ($self, $qtype, $bterm) = @_;
+
+    my $flag_name = "opac.browse.warnable_regexp_per_class";
+    my $flag = $self->ctx->{get_cgf}->($flag_name);
+
+    return unless $flag->enabled eq 't';
+
+    my $map;
+
+    eval { $map = OpenSRF::Utils::JSON->JSON2perl($flag->value); };
+    if ($@) {
+        $logger->warn("cgf '$flag_name' enabled but value is invalid JSON? $@");
+        return;
+    }
+
+    # Don't crash over any of the things that could go wrong in here:
+    eval {
+        if ($map->{$qtype}) {
+            if ($bterm =~ qr/$map->{$qtype}/i) {
+                $self->ctx->{browse_leading_article_warning} = 1;
+            }
+        }
+    };
+    if ($@) {
+        $logger->warn("cgf '$flag_name' has valid JSON in value, but: $@");
+    }
+}
+
+sub load_browse {
+    my ($self) = @_;
+
+    _init_browse_cache();
+
+    $self->ctx->{more_forward} = 0;
+    $self->ctx->{more_back} = 0;
+
+    if ($self->cgi->param('qtype') and defined $self->cgi->param('bterm')) {
+
+        $self->leading_article_test(
+            $self->cgi->param('qtype'),
+            $self->cgi->param('bterm')
+        );
+
+        my ($cache_key, $limit, $offset, $force_backward, @params) =
+            $self->prepare_browse_parameters;
+
+        my $results = $browse_cache->get_cache($cache_key);
+        if (not $results) {
+            $results = $self->load_browse_impl(
+                $limit, $offset, $force_backward, @params
+            );
+            if ($results) {
+                $browse_cache->put_cache($cache_key, $results, $browse_timeout);
+            }
+        }
+
+        if ($results) {
+            $self->infer_browse_paging(
+                $results, $limit, $offset, $force_backward
+            );
+            $self->ctx->{browse_results} = $results;
+        }
+
+        # We don't need an else clause to send the user a 5XX error or
+        # anything. Errors will have been logged, and $ctx will be
+        # prepared so a template can show a nicer error to the user.
+    }
+
+    return Apache2::Const::OK;
+}
+
+1;
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
index b8dd4f6..6382210 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
@@ -21,7 +21,8 @@ our %cache = ( # cached data
     search_filter_groups => {en_us => {}},
     aou_tree => {en_us => undef},
     aouct_tree => {},
-    eg_cache_hash => undef
+    eg_cache_hash => undef,
+    authority_fields => {en_us => {}}
 );
 
 sub init_ro_object_cache {
@@ -230,6 +231,21 @@ sub init_ro_object_cache {
         return $cache{org_settings}{$ctx->{locale}}{$org_id}{$setting};
     };
 
+    # retrieve and cache acsaf values
+    $ro_object_subs->{get_authority_fields} = sub {
+        my ($control_set) = @_;
+
+        if (not exists $cache{authority_fields}{$ctx->{locale}}{$control_set}) {
+            my $acs = $e->search_authority_control_set_authority_field(
+                {control_set => $control_set}
+            ) or return;
+            $cache{authority_fields}{$ctx->{locale}}{$control_set} =
+                +{ map { $_->id => $_ } @$acs };
+        }
+
+        return $cache{authority_fields}{$ctx->{locale}}{$control_set};
+    };
+
     $ctx->{$_} = $ro_object_subs->{$_} for keys %$ro_object_subs;
 }
 
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 0b6cd8b..5c1e0b1 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -193,7 +193,9 @@ CREATE TABLE config.metabib_field (
 	facet_field	BOOL	NOT NULL DEFAULT FALSE,
 	browse_field	BOOL	NOT NULL DEFAULT TRUE,
 	browse_xpath   TEXT,
+	browse_sort_xpath TEXT,
 	facet_xpath	TEXT,
+	authority_xpath TEXT,
 	restrict	BOOL    DEFAULT FALSE NOT NULL
 );
 COMMENT ON TABLE config.metabib_field IS $$
diff --git a/Open-ILS/src/sql/Pg/011.schema.authority.sql b/Open-ILS/src/sql/Pg/011.schema.authority.sql
index 6d4fb50..3277555 100644
--- a/Open-ILS/src/sql/Pg/011.schema.authority.sql
+++ b/Open-ILS/src/sql/Pg/011.schema.authority.sql
@@ -35,6 +35,7 @@ CREATE TABLE authority.control_set_authority_field (
     tag         CHAR(3) NOT NULL,
     nfi         CHAR(1),          -- non-filing indicator
     sf_list     TEXT    NOT NULL,
+    display_sf_list     TEXT NOT NULL,
     name        TEXT    NOT NULL, -- i18n
     description TEXT,             -- i18n
     linking_subfield CHAR(1)
diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql
index 1cd740d..ae74fba 100644
--- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql
+++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql
@@ -185,9 +185,16 @@ CREATE INDEX metabib_facet_entry_source_idx ON metabib.facet_entry (source);
 
 CREATE TABLE metabib.browse_entry (
     id BIGSERIAL PRIMARY KEY,
-    value TEXT unique,
-    index_vector tsvector
+    value TEXT,
+    index_vector tsvector,
+    sort_value  TEXT NOT NULL,
+    UNIQUE(value, sort_value)
 );
+
+
+CREATE INDEX browse_entry_sort_value_idx
+    ON metabib.browse_entry USING BTREE (sort_value);
+
 CREATE INDEX metabib_browse_entry_index_vector_idx ON metabib.browse_entry USING GIN (index_vector);
 CREATE TRIGGER metabib_browse_entry_fti_trigger
     BEFORE INSERT OR UPDATE ON metabib.browse_entry
@@ -198,7 +205,8 @@ CREATE TABLE metabib.browse_entry_def_map (
     id BIGSERIAL PRIMARY KEY,
     entry BIGINT REFERENCES metabib.browse_entry (id),
     def INT REFERENCES config.metabib_field (id),
-    source BIGINT REFERENCES biblio.record_entry (id)
+    source BIGINT REFERENCES biblio.record_entry (id),
+    authority BIGINT REFERENCES authority.record_entry (id) ON DELETE SET NULL
 );
 CREATE INDEX browse_entry_def_map_def_idx ON metabib.browse_entry_def_map (def);
 CREATE INDEX browse_entry_def_map_entry_idx ON metabib.browse_entry_def_map (entry);
@@ -384,14 +392,15 @@ CREATE INDEX metabib_metarecord_source_map_metarecord_idx ON metabib.metarecord_
 CREATE INDEX metabib_metarecord_source_map_source_record_idx ON metabib.metarecord_source_map (source);
 
 CREATE TYPE metabib.field_entry_template AS (
-        field_class     TEXT,
-        field           INT,
-        facet_field     BOOL,
-        search_field    BOOL,
-        browse_field   BOOL,
-        source          BIGINT,
-        value           TEXT,
-        authority       BIGINT
+    field_class         TEXT,
+    field               INT,
+    facet_field         BOOL,
+    search_field        BOOL,
+    browse_field        BOOL,
+    source              BIGINT,
+    value               TEXT,
+    authority           BIGINT,
+    sort_value          TEXT
 );
 
 
@@ -406,6 +415,7 @@ DECLARE
     xml_node_list   TEXT[];
     facet_text  TEXT;
     browse_text TEXT;
+    sort_value  TEXT;
     raw_text    TEXT;
     curr_text   TEXT;
     joiner      TEXT := default_joiner; -- XXX will index defs supply a joiner?
@@ -479,10 +489,25 @@ BEGIN
                     browse_text := curr_text;
                 END IF;
 
+                IF idx.browse_sort_xpath IS NOT NULL AND
+                    idx.browse_sort_xpath <> '' THEN
+
+                    sort_value := oils_xpath_string(
+                        idx.browse_sort_xpath, xml_node, joiner,
+                        ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]]
+                    );
+                ELSE
+                    sort_value := browse_text;
+                END IF;
+
                 output_row.field_class = idx.field_class;
                 output_row.field = idx.id;
                 output_row.source = rid;
                 output_row.value = BTRIM(REGEXP_REPLACE(browse_text, E'\\s+', ' ', 'g'));
+                output_row.sort_value :=
+                    public.search_normalize(sort_value);
+
+                output_row.authority := NULL;
 
                 IF idx.authority_xpath IS NOT NULL AND idx.authority_xpath <> '' THEN
                     authority_text := oils_xpath_string(
@@ -506,6 +531,7 @@ BEGIN
                 output_row.browse_field = TRUE;
                 RETURN NEXT output_row;
                 output_row.browse_field = FALSE;
+                output_row.sort_value := NULL;
             END IF;
 
             -- insert raw node text for faceting
@@ -611,6 +637,7 @@ DECLARE
     b_skip_facet    BOOL;
     b_skip_browse   BOOL;
     b_skip_search   BOOL;
+    value_prepped   TEXT;
 BEGIN
 
     SELECT COALESCE(NULLIF(skip_facet, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_facet_indexing' AND enabled)) INTO b_skip_facet;
@@ -650,12 +677,18 @@ BEGIN
             -- evergreen.oils_tsearch2()) changes.  It may or may not be
             -- expensive to add a comparison of index_vector to index_vector
             -- to the WHERE clause below.
-            SELECT INTO mbe_row * FROM metabib.browse_entry WHERE value = ind_data.value;
+
+            value_prepped := metabib.browse_normalize(ind_data.value, ind_data.field);
+            SELECT INTO mbe_row * FROM metabib.browse_entry
+                WHERE value = value_prepped AND sort_value = ind_data.sort_value;
+
             IF FOUND THEN
                 mbe_id := mbe_row.id;
             ELSE
-                INSERT INTO metabib.browse_entry (value) VALUES
-                    (metabib.browse_normalize(ind_data.value, ind_data.field));
+                INSERT INTO metabib.browse_entry
+                    ( value, sort_value ) VALUES
+                    ( value_prepped, ind_data.sort_value );
+
                 mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
             END IF;
 
@@ -1740,4 +1773,243 @@ BEGIN
 END;
 $$ LANGUAGE PLPGSQL;
 
+
+CREATE TYPE metabib.flat_browse_entry_appearance AS (
+    browse_entry    BIGINT,
+    value           TEXT,
+    fields          TEXT,
+    authorities     TEXT,
+    sources         INT,        -- visible ones, that is
+    row_number      INT,        -- internal use, sort of
+    accurate        BOOL        -- Count in sources field is accurate? Not
+                                -- if we had more than a browse superpage
+                                -- of records to look at.
+);
+
+
+CREATE OR REPLACE FUNCTION metabib.browse_pivot(
+    search_field        INT[],
+    browse_term         TEXT
+) RETURNS BIGINT AS $p$
+DECLARE
+    id                  BIGINT;
+BEGIN
+    SELECT INTO id mbe.id FROM metabib.browse_entry mbe
+        JOIN metabib.browse_entry_def_map mbedm ON (
+            mbedm.entry = mbe.id AND
+            mbedm.def = ANY(search_field)
+        )
+        WHERE mbe.sort_value >= public.search_normalize(browse_term)
+        ORDER BY mbe.sort_value, mbe.value LIMIT 1;
+
+    RETURN id;
+END;
+$p$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION metabib.staged_browse(
+    core_query              TEXT,
+    context_org             INT,
+    context_locations       INT[],
+    staff                   BOOL,
+    browse_superpage_size   INT,
+    result_limit            INT,
+    use_offset              INT
+) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
+DECLARE
+    core_cursor             REFCURSOR;
+    core_record             RECORD;
+    qpfts_query             TEXT;
+    result_row              metabib.flat_browse_entry_appearance%ROWTYPE;
+    results_skipped         INT := 0;
+    results_returned        INT := 0;
+    slice_start             INT;
+    slice_end               INT;
+    full_end                INT;
+    superpage_of_records    BIGINT[];
+    superpage_size          INT;
+BEGIN
+    OPEN core_cursor FOR EXECUTE core_query;
+
+    LOOP
+        FETCH core_cursor INTO core_record;
+        EXIT WHEN NOT FOUND;
+
+        result_row.sources := 0;
+
+        full_end := ARRAY_LENGTH(core_record.records, 1);
+        superpage_size := COALESCE(browse_superpage_size, full_end);
+        slice_start := 1;
+        slice_end := superpage_size;
+
+        WHILE result_row.sources = 0 AND slice_start <= full_end LOOP
+            superpage_of_records := core_record.records[slice_start:slice_end];
+            qpfts_query :=
+                'SELECT NULL::BIGINT AS id, ARRAY[r] AS records, ' ||
+                '1::INT AS rel FROM (SELECT UNNEST(' ||
+                quote_literal(superpage_of_records) || '::BIGINT[]) AS r) rr';
+
+            -- We use search.query_parser_fts() for visibility testing.
+            -- We're calling it once per browse-superpage worth of records
+            -- out of the set of records related to a given mbe, until we've
+            -- either exhausted that set of records or found at least 1
+            -- visible record.
+
+            SELECT INTO result_row.sources visible
+                FROM search.query_parser_fts(
+                    context_org, NULL, qpfts_query, NULL,
+                    context_locations, 0, NULL, NULL, FALSE, staff, FALSE
+                ) qpfts
+                WHERE qpfts.rel IS NULL;
+
+            slice_start := slice_start + superpage_size;
+            slice_end := slice_end + superpage_size;
+        END LOOP;
+
+        -- Accurate?  Well, probably.
+        result_row.accurate := browse_superpage_size IS NULL OR
+            browse_superpage_size >= full_end;
+
+        IF result_row.sources > 0 THEN
+            IF results_skipped < use_offset THEN
+                results_skipped := results_skipped + 1;
+                CONTINUE;
+            END IF;
+
+            result_row.browse_entry := core_record.id;
+            result_row.authorities := core_record.authorities;
+            result_row.fields := core_record.fields;
+            result_row.value := core_record.value;
+
+            -- This is needed so our caller can flip it and reverse it.
+            result_row.row_number := results_returned;
+
+            RETURN NEXT result_row;
+
+            results_returned := results_returned + 1;
+
+            EXIT WHEN results_returned >= result_limit;
+        END IF;
+    END LOOP;
+END;
+$p$ LANGUAGE PLPGSQL;
+
+-- This is optimized to be fast for values of result_offset near zero.
+CREATE OR REPLACE FUNCTION metabib.browse(
+    search_field            INT[],
+    browse_term             TEXT,
+    context_org             INT DEFAULT NULL,
+    context_loc_group       INT DEFAULT NULL,
+    staff                   BOOL DEFAULT FALSE,
+    pivot_id                BIGINT DEFAULT NULL,
+    force_backward          BOOL DEFAULT FALSE,
+    result_limit            INT DEFAULT 10,
+    result_offset           INT DEFAULT 0   -- Can be negative!
+) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
+DECLARE
+    core_query              TEXT;
+    whole_query             TEXT;
+    pivot_sort_value        TEXT;
+    pivot_sort_fallback     TEXT;
+    context_locations       INT[];
+    use_offset              INT;
+    browse_superpage_size   INT;
+    results_skipped         INT := 0;
+BEGIN
+    IF pivot_id IS NULL THEN
+        pivot_id := metabib.browse_pivot(search_field, browse_term);
+    END IF;
+
+    SELECT INTO pivot_sort_value, pivot_sort_fallback
+        sort_value, value FROM metabib.browse_entry WHERE id = pivot_id;
+
+    IF pivot_sort_value IS NULL THEN
+        RETURN;
+    END IF;
+
+    IF context_loc_group IS NOT NULL THEN
+        SELECT INTO context_locations ARRAY_AGG(location)
+            FROM asset.copy_location_group_map
+            WHERE lgroup = context_loc_group;
+    END IF;
+
+    SELECT INTO browse_superpage_size value     -- NULL ok
+        FROM config.global_flag
+        WHERE enabled AND name = 'opac.browse.holdings_visibility_test_limit';
+
+    core_query := '
+    SELECT
+        mbe.id,
+        mbe.value,
+        mbe.sort_value,
+        (SELECT ARRAY_AGG(src) FROM (
+            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.source)) AS src
+        ) ss) AS records,
+        (SELECT ARRAY_TO_STRING(ARRAY_AGG(authority), $$,$$) FROM (
+            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.authority)) AS authority
+        ) au) AS authorities,
+        (SELECT ARRAY_TO_STRING(ARRAY_AGG(field), $$,$$) FROM (
+            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.def)) AS field
+        ) fi) AS fields
+    FROM metabib.browse_entry mbe
+    JOIN metabib.browse_entry_def_map mbedm ON (
+        mbedm.entry = mbe.id AND
+        mbedm.def = ANY(' || quote_literal(search_field) || ')
+    )
+    WHERE ';
+
+    -- PostgreSQL is not magic. We can't actually pass a negative offset.
+    IF result_offset >= 0 AND NOT force_backward THEN
+        use_offset := result_offset;
+        core_query := core_query ||
+            ' mbe.sort_value >= ' || quote_literal(pivot_sort_value) ||
+        ' GROUP BY 1,2,3 ORDER BY mbe.sort_value, mbe.value ';
+
+        RETURN QUERY SELECT * FROM metabib.staged_browse(
+            core_query, context_org, context_locations,
+            staff, browse_superpage_size, result_limit, use_offset
+        );
+    ELSE
+        -- Part 1 of 2 to deliver what the user wants with a negative offset:
+        core_query := core_query ||
+            ' mbe.sort_value < ' || quote_literal(pivot_sort_value) ||
+        ' GROUP BY 1,2,3 ORDER BY mbe.sort_value DESC, mbe.value DESC ';
+
+        -- Part 2 of 2 to deliver what the user wants with a negative offset:
+        RETURN QUERY SELECT * FROM (SELECT * FROM metabib.staged_browse(
+            core_query, context_org, context_locations,
+            staff, browse_superpage_size, result_limit, use_offset
+        )) sb ORDER BY row_number DESC;
+
+    END IF;
+END;
+$p$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION metabib.browse(
+    search_class        TEXT,
+    browse_term         TEXT,
+    context_org         INT DEFAULT NULL,
+    context_loc_group   INT DEFAULT NULL,
+    staff               BOOL DEFAULT FALSE,
+    pivot_id            BIGINT DEFAULT NULL,
+    force_backward      BOOL DEFAULT FALSE,
+    result_limit        INT DEFAULT 10,
+    result_offset       INT DEFAULT 0   -- Can be negative, implying backward!
+) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
+BEGIN
+    RETURN QUERY SELECT * FROM metabib.browse(
+        (SELECT COALESCE(ARRAY_AGG(id), ARRAY[]::INT[])
+            FROM config.metabib_field WHERE field_class = search_class),
+        browse_term,
+        context_org,
+        context_loc_group,
+        staff,
+        pivot_id,
+        force_backward,
+        result_limit,
+        result_offset
+    );
+END;
+$p$ LANGUAGE PLPGSQL;
+
+
 COMMIT;
diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
index 1aa746c..2b6772d 100644
--- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql
+++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
@@ -110,37 +110,37 @@ INSERT INTO config.xml_transform VALUES ( 'mods33', 'http://www.loc.gov/mods/v3'
 INSERT INTO config.xml_transform VALUES ( 'marc21expand880', 'http://www.loc.gov/MARC21/slim', 'marc', '' );
 
 -- Index Definitions
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES 
-    (1, 'series', 'seriestitle', oils_i18n_gettext(1, 'Series Title', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:relatedItem[@type="series"]/mods32:titleInfo$$, TRUE );
-
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath ) VALUES 
-    (2, 'title', 'abbreviated', oils_i18n_gettext(2, 'Abbreviated Title', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='abbreviated')]$$ );
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath ) VALUES 
-    (3, 'title', 'translated', oils_i18n_gettext(3, 'Translated Title', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='translated')]$$ );
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath ) VALUES 
-    (4, 'title', 'alternative', oils_i18n_gettext(4, 'Alternate Title', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='alternative')]$$ );
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath ) VALUES 
-    (5, 'title', 'uniform', oils_i18n_gettext(5, 'Uniform Title', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='uniform')]$$ );
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath ) VALUES 
-    (6, 'title', 'proper', oils_i18n_gettext(6, 'Title Proper', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleNonfiling[mods32:title and not (@type)]$$ );
-
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field ) VALUES 
-    (7, 'author', 'corporate', oils_i18n_gettext(7, 'Corporate Author', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:name[@type='corporate' and (mods32:role/mods32:roleTerm[text()='creator'] or mods32:role/mods32:roleTerm[text()='aut'] or mods32:role/mods32:roleTerm[text()='cre'])]$$, $$//*[local-name()='namePart']$$, TRUE ); -- /* to fool vim */;
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field ) VALUES 
-    (8, 'author', 'personal', oils_i18n_gettext(8, 'Personal Author', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:name[@type='personal' and mods32:role/mods32:roleTerm[text()='creator']]$$, $$//*[local-name()='namePart']$$, TRUE ); -- /* to fool vim */;
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field ) VALUES 
-    (9, 'author', 'conference', oils_i18n_gettext(9, 'Conference Author', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:name[@type='conference' and mods32:role/mods32:roleTerm[text()='creator']]$$, $$//*[local-name()='namePart']$$, TRUE ); -- /* to fool vim */;
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field ) VALUES 
-    (10, 'author', 'other', oils_i18n_gettext(10, 'Other Author', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:name[@type='personal' and not(mods32:role/mods32:roleTerm[text()='creator'])]$$, $$//*[local-name()='namePart']$$, TRUE ); -- /* to fool vim */;
-
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES 
-    (11, 'subject', 'geographic', oils_i18n_gettext(11, 'Geographic Subject', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:subject/mods32:geographic$$, TRUE );
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field ) VALUES 
-    (12, 'subject', 'name', oils_i18n_gettext(12, 'Name Subject', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:subject/mods32:name$$, $$//*[local-name()='namePart']$$, TRUE ); -- /* to fool vim */;
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES 
-    (13, 'subject', 'temporal', oils_i18n_gettext(13, 'Temporal Subject', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:subject/mods32:temporal$$, TRUE );
-INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field ) VALUES 
-    (14, 'subject', 'topic', oils_i18n_gettext(14, 'Topic Subject', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:subject/mods32:topic$$, TRUE );
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field, authority_xpath, browse_sort_xpath ) VALUES 
+    (1, 'series', 'seriestitle', oils_i18n_gettext(1, 'Series Title', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:relatedItem[@type="series"]/mods32:titleInfo[@type="nfi"]$$, TRUE, '//@xlink:href', $$*[local-name() != "nonSort"]$$ );
+
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, authority_xpath ) VALUES 
+    (2, 'title', 'abbreviated', oils_i18n_gettext(2, 'Abbreviated Title', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='abbreviated')]$$, '//@xlink:href' );
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, authority_xpath, browse_sort_xpath ) VALUES 
+    (3, 'title', 'translated', oils_i18n_gettext(3, 'Translated Title', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='translated-nfi')]$$, '//@xlink:href', $$*[local-name() != "nonSort"]$$ );
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, authority_xpath, browse_sort_xpath ) VALUES 
+    (4, 'title', 'alternative', oils_i18n_gettext(4, 'Alternate Title', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='alternative-nfi')]$$, '//@xlink:href', $$*[local-name() != "nonSort"]$$ );
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, authority_xpath, browse_sort_xpath ) VALUES 
+    (5, 'title', 'uniform', oils_i18n_gettext(5, 'Uniform Title', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='uniform-nfi')]$$, '//@xlink:href', $$*[local-name() != "nonSort"]$$ );
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, authority_xpath, browse_field, browse_sort_xpath ) VALUES 
+    (6, 'title', 'proper', oils_i18n_gettext(6, 'Title Proper', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:titleNonfiling[mods32:title and not (@type)]$$, '//@xlink:href', TRUE, $$*[local-name() != "nonSort"]$$ );
+
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field , authority_xpath, browse_xpath) VALUES 
+    (7, 'author', 'corporate', oils_i18n_gettext(7, 'Corporate Author', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:name[@type='corporate' and (mods32:role/mods32:roleTerm[text()='creator'] or mods32:role/mods32:roleTerm[text()='aut'] or mods32:role/mods32:roleTerm[text()='cre'])]$$, $$//*[local-name()='namePart']$$, TRUE, '//@xlink:href',$$//*[local-name()='namePart']$$ ); -- /* to fool vim */;
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field, authority_xpath, browse_xpath ) VALUES 
+    (8, 'author', 'personal', oils_i18n_gettext(8, 'Personal Author', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:name[@type='personal' and mods32:role/mods32:roleTerm[text()='creator']]$$, $$//*[local-name()='namePart']$$, TRUE, '//@xlink:href',$$//*[local-name()='namePart']$$ ); -- /* to fool vim */;
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field, authority_xpath, browse_xpath ) VALUES 
+    (9, 'author', 'conference', oils_i18n_gettext(9, 'Conference Author', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:name[@type='conference' and mods32:role/mods32:roleTerm[text()='creator']]$$, $$//*[local-name()='namePart']$$, TRUE, '//@xlink:href',$$//*[local-name()='namePart']$$ ); -- /* to fool vim */;
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field, authority_xpath, browse_xpath ) VALUES 
+    (10, 'author', 'other', oils_i18n_gettext(10, 'Other Author', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:name[@type='personal' and not(mods32:role/mods32:roleTerm[text()='creator'])]$$, $$//*[local-name()='namePart']$$, TRUE, '//@xlink:href',$$//*[local-name()='namePart']$$ ); -- /* to fool vim */;
+
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field, authority_xpath ) VALUES 
+    (11, 'subject', 'geographic', oils_i18n_gettext(11, 'Geographic Subject', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:subject/mods32:geographic$$, TRUE, '//@xlink:href' );
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_xpath, facet_field, authority_xpath ) VALUES 
+    (12, 'subject', 'name', oils_i18n_gettext(12, 'Name Subject', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:subject/mods32:name$$, $$//*[local-name()='namePart']$$, TRUE, '//@xlink:href' ); -- /* to fool vim */;
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field, authority_xpath ) VALUES 
+    (13, 'subject', 'temporal', oils_i18n_gettext(13, 'Temporal Subject', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:subject/mods32:temporal$$, TRUE, '//@xlink:href' );
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, facet_field, authority_xpath ) VALUES 
+    (14, 'subject', 'topic', oils_i18n_gettext(14, 'Topic Subject', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:subject/mods32:topic$$, TRUE, '//@xlink:href' );
 --INSERT INTO config.metabib_field ( id, field_class, name, format, xpath ) VALUES 
 --  ( id, field_class, name, xpath ) VALUES ( 'subject', 'genre', 'mods32', $$//mods32:mods/mods32:genre$$ );
 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, browse_field ) VALUES 
@@ -176,6 +176,9 @@ INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath,
     (29, 'identifier', 'scn', oils_i18n_gettext(29, 'System Control Number', 'cmf', 'label'), 'marcxml', $$//marc:datafield[@tag='035']/marc:subfield[@code="a"]$$, FALSE);
 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, browse_field) VALUES
     (30, 'identifier', 'lccn', oils_i18n_gettext(30, 'LC Control Number', 'cmf', 'label'), 'marcxml', $$//marc:datafield[@tag='010']/marc:subfield[@code="a" or @code='z']$$, FALSE);
+INSERT INTO config.metabib_field ( id, field_class, name, label, xpath, format, search_field, facet_field, browse_field) VALUES
+    (31, 'title', 'browse', oils_i18n_gettext(31, 'Title Proper (Browse)', 'cmf', 'label'), $$//mods32:mods/mods32:titleInfo[not (@type)]/mods32:title$$, 'mods32', FALSE, FALSE, TRUE);
+
 
 SELECT SETVAL('config.metabib_field_id_seq'::TEXT, (SELECT MAX(id) FROM config.metabib_field), TRUE);
 
@@ -9180,6 +9183,30 @@ INSERT INTO config.global_flag (name, label)
         )
     );
 
+INSERT INTO config.global_flag (name, value, enabled, label)
+VALUES (
+    'opac.browse.warnable_regexp_per_class',
+    '{"title": "^(a|the|an)\\s"}',
+    FALSE,
+    oils_i18n_gettext(
+        'opac.browse.warnable_regexp_per_class',
+        'Map of search classes to regular expressions to warn user about leading articles.',
+        'cgf',
+        'label'
+    )
+),
+(
+    'opac.browse.holdings_visibility_test_limit',
+    '100',
+    TRUE,
+    oils_i18n_gettext(
+        'opac.browse.holdings_visibility_test_limit',
+        'Don''t look for more than this number of records with holdings when displaying browse headings with visible record counts.',
+        'cgf',
+        'label'
+    )
+);
+
 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
     VALUES (
         'history.circ.retention_age',
@@ -10332,65 +10359,76 @@ INSERT INTO authority.control_set (id, name, description) VALUES (
 );
 
 -- Entries that need to respect an NFI
-INSERT INTO authority.control_set_authority_field (id, control_set, main_entry, tag, sf_list, name, nfi) VALUES
-    (4, 1, NULL, '130', 'adfgklmnoprstvxyz', oils_i18n_gettext('4','Heading -- Uniform Title','acsaf','name'), '2'),
-    (24, 1, 4, '530', 'adfgiklmnoprstvwxyz4', oils_i18n_gettext('24','See Also From Tracing -- Uniform Title','acsaf','name'), '2'),
-    (44, 1, 4, '730', 'adfghklmnoprstvwxyz25', oils_i18n_gettext('44','Established Heading Linking Entry -- Uniform Title','acsaf','name'), '2'),
-    (64, 1, 4, '430', 'adfgiklmnoprstvwxyz4', oils_i18n_gettext('64','See From Tracing -- Uniform Title','acsaf','name'), '2');
+INSERT INTO authority.control_set_authority_field (id, control_set, main_entry, tag, sf_list, display_sf_list, name, nfi) VALUES
+    (4, 1, NULL, '130', 'adfgklmnoprstvxyz', 'adfgklmnoprstvxyz', oils_i18n_gettext('4','Heading -- Uniform Title','acsaf','name'), '2'),
+    (24, 1, 4, '530', 'adfgiklmnoprstvwxyz4', 'adfgiklmnoprstvxyz', oils_i18n_gettext('24','See Also From Tracing -- Uniform Title','acsaf','name'), '2'),
+    (44, 1, 4, '730', 'adfghklmnoprstvwxyz25', 'adfghklmnoprstvxyz', oils_i18n_gettext('44','Established Heading Linking Entry -- Uniform Title','acsaf','name'), '2'),
+    (64, 1, 4, '430', 'adfgiklmnoprstvwxyz4', 'adfgiklmnoprstvxyz', oils_i18n_gettext('64','See From Tracing -- Uniform Title','acsaf','name'), '2');
 
-INSERT INTO authority.control_set_authority_field (id, control_set, main_entry, tag, sf_list, name) VALUES
+INSERT INTO authority.control_set_authority_field (id, control_set, main_entry, tag, sf_list, display_sf_list, name) VALUES
 
 -- Main entries
-    (1, 1, NULL, '100', 'abcdefklmnopqrstvxyz', oils_i18n_gettext('1','Heading -- Personal Name','acsaf','name')),
-    (2, 1, NULL, '110', 'abcdefgklmnoprstvxyz', oils_i18n_gettext('2','Heading -- Corporate Name','acsaf','name')),
-    (3, 1, NULL, '111', 'acdefgklnpqstvxyz', oils_i18n_gettext('3','Heading -- Meeting Name','acsaf','name')),
-    (5, 1, NULL, '150', 'abvxyz', oils_i18n_gettext('5','Heading -- Topical Term','acsaf','name')),
-    (6, 1, NULL, '151', 'avxyz', oils_i18n_gettext('6','Heading -- Geographic Name','acsaf','name')),
-    (7, 1, NULL, '155', 'avxyz', oils_i18n_gettext('7','Heading -- Genre/Form Term','acsaf','name')),
-    (8, 1, NULL, '180', 'vxyz', oils_i18n_gettext('8','Heading -- General Subdivision','acsaf','name')),
-    (9, 1, NULL, '181', 'vxyz', oils_i18n_gettext('9','Heading -- Geographic Subdivision','acsaf','name')),
-    (10, 1, NULL, '182', 'vxyz', oils_i18n_gettext('10','Heading -- Chronological Subdivision','acsaf','name')),
-    (11, 1, NULL, '185', 'vxyz', oils_i18n_gettext('11','Heading -- Form Subdivision','acsaf','name')),
-    (12, 1, NULL, '148', 'avxyz', oils_i18n_gettext('12','Heading -- Chronological Term','acsaf','name')),
+    (1, 1, NULL, '100', 'abcdefklmnopqrstvxyz', 'abcdefklmnopqrstvxyz',
+        oils_i18n_gettext('1','Heading -- Personal Name','acsaf','name')),
+    (2, 1, NULL, '110', 'abcdefgklmnoprstvxyz', 'abcdefgklmnoprstvxyz',
+        oils_i18n_gettext('2','Heading -- Corporate Name','acsaf','name')),
+    (3, 1, NULL, '111', 'acdefgklnpqstvxyz', 'acdefgklnpqstvxyz',
+        oils_i18n_gettext('3','Heading -- Meeting Name','acsaf','name')),
+    (5, 1, NULL, '150', 'abvxyz', 'abvxyz',
+        oils_i18n_gettext('5','Heading -- Topical Term','acsaf','name')),
+    (6, 1, NULL, '151', 'avxyz', 'avxyz',
+        oils_i18n_gettext('6','Heading -- Geographic Name','acsaf','name')),
+    (7, 1, NULL, '155', 'avxyz', 'avxyz',
+        oils_i18n_gettext('7','Heading -- Genre/Form Term','acsaf','name')),
+    (8, 1, NULL, '180', 'vxyz', 'vxyz',
+        oils_i18n_gettext('8','Heading -- General Subdivision','acsaf','name')),
+    (9, 1, NULL, '181', 'vxyz', 'vxyz',
+        oils_i18n_gettext('9','Heading -- Geographic Subdivision','acsaf','name')),
+    (10, 1, NULL, '182', 'vxyz', 'vxyz',
+        oils_i18n_gettext('10','Heading -- Chronological Subdivision','acsaf','name')),
+    (11, 1, NULL, '185', 'vxyz', 'vxyz',
+        oils_i18n_gettext('11','Heading -- Form Subdivision','acsaf','name')),
+    (12, 1, NULL, '148', 'avxyz', 'avxyz',
+        oils_i18n_gettext('12','Heading -- Chronological Term','acsaf','name')),
 
 -- See Also From tracings
-    (21, 1, 1, '500', 'abcdefiklmnopqrstvwxyz4', oils_i18n_gettext('21','See Also From Tracing -- Personal Name','acsaf','name')),
-    (22, 1, 2, '510', 'abcdefgiklmnoprstvwxyz4', oils_i18n_gettext('22','See Also From Tracing -- Corporate Name','acsaf','name')),
-    (23, 1, 3, '511', 'acdefgiklnpqstvwxyz4', oils_i18n_gettext('23','See Also From Tracing -- Meeting Name','acsaf','name')),
-    (25, 1, 5, '550', 'abivwxyz4', oils_i18n_gettext('25','See Also From Tracing -- Topical Term','acsaf','name')),
-    (26, 1, 6, '551', 'aivwxyz4', oils_i18n_gettext('26','See Also From Tracing -- Geographic Name','acsaf','name')),
-    (27, 1, 7, '555', 'aivwxyz4', oils_i18n_gettext('27','See Also From Tracing -- Genre/Form Term','acsaf','name')),
-    (28, 1, 8, '580', 'ivwxyz4', oils_i18n_gettext('28','See Also From Tracing -- General Subdivision','acsaf','name')),
-    (29, 1, 9, '581', 'ivwxyz4', oils_i18n_gettext('29','See Also From Tracing -- Geographic Subdivision','acsaf','name')),
-    (30, 1, 10, '582', 'ivwxyz4', oils_i18n_gettext('30','See Also From Tracing -- Chronological Subdivision','acsaf','name')),
-    (31, 1, 11, '585', 'ivwxyz4', oils_i18n_gettext('31','See Also From Tracing -- Form Subdivision','acsaf','name')),
-    (32, 1, 12, '548', 'aivwxyz4', oils_i18n_gettext('32','See Also From Tracing -- Chronological Term','acsaf','name')),
+    (21, 1, 1, '500', 'abcdefiklmnopqrstvwxyz4', 'abcdefiklmnopqrstvxyz', oils_i18n_gettext('21','See Also From Tracing -- Personal Name','acsaf','name')),
+    (22, 1, 2, '510', 'abcdefgiklmnoprstvwxyz4', 'abcdefgiklmnoprstvxyz', oils_i18n_gettext('22','See Also From Tracing -- Corporate Name','acsaf','name')),
+    (23, 1, 3, '511', 'acdefgiklnpqstvwxyz4', 'acdefgiklnpqstvxyz', oils_i18n_gettext('23','See Also From Tracing -- Meeting Name','acsaf','name')),
+    (25, 1, 5, '550', 'abivwxyz4', 'abivxyz', oils_i18n_gettext('25','See Also From Tracing -- Topical Term','acsaf','name')),
+    (26, 1, 6, '551', 'aivwxyz4', 'aivxyz', oils_i18n_gettext('26','See Also From Tracing -- Geographic Name','acsaf','name')),
+    (27, 1, 7, '555', 'aivwxyz4', 'aivxyz', oils_i18n_gettext('27','See Also From Tracing -- Genre/Form Term','acsaf','name')),
+    (28, 1, 8, '580', 'ivwxyz4', 'ivxyz', oils_i18n_gettext('28','See Also From Tracing -- General Subdivision','acsaf','name')),
+    (29, 1, 9, '581', 'ivwxyz4', 'ivxyz', oils_i18n_gettext('29','See Also From Tracing -- Geographic Subdivision','acsaf','name')),
+    (30, 1, 10, '582', 'ivwxyz4', 'ivxyz', oils_i18n_gettext('30','See Also From Tracing -- Chronological Subdivision','acsaf','name')),
+    (31, 1, 11, '585', 'ivwxyz4', 'ivxyz', oils_i18n_gettext('31','See Also From Tracing -- Form Subdivision','acsaf','name')),
+    (32, 1, 12, '548', 'aivwxyz4', 'aivxyz', oils_i18n_gettext('32','See Also From Tracing -- Chronological Term','acsaf','name')),
 
 -- Linking entries
-    (41, 1, 1, '700', 'abcdefghjklmnopqrstvwxyz25', oils_i18n_gettext('41','Established Heading Linking Entry -- Personal Name','acsaf','name')),
-    (42, 1, 2, '710', 'abcdefghklmnoprstvwxyz25', oils_i18n_gettext('42','Established Heading Linking Entry -- Corporate Name','acsaf','name')),
-    (43, 1, 3, '711', 'acdefghklnpqstvwxyz25', oils_i18n_gettext('43','Established Heading Linking Entry -- Meeting Name','acsaf','name')),
-    (45, 1, 5, '750', 'abvwxyz25', oils_i18n_gettext('45','Established Heading Linking Entry -- Topical Term','acsaf','name')),
-    (46, 1, 6, '751', 'avwxyz25', oils_i18n_gettext('46','Established Heading Linking Entry -- Geographic Name','acsaf','name')),
-    (47, 1, 7, '755', 'avwxyz25', oils_i18n_gettext('47','Established Heading Linking Entry -- Genre/Form Term','acsaf','name')),
-    (48, 1, 8, '780', 'vwxyz25', oils_i18n_gettext('48','Subdivision Linking Entry -- General Subdivision','acsaf','name')),
-    (49, 1, 9, '781', 'vwxyz25', oils_i18n_gettext('49','Subdivision Linking Entry -- Geographic Subdivision','acsaf','name')),
-    (50, 1, 10, '782', 'vwxyz25', oils_i18n_gettext('50','Subdivision Linking Entry -- Chronological Subdivision','acsaf','name')),
-    (51, 1, 11, '785', 'vwxyz25', oils_i18n_gettext('51','Subdivision Linking Entry -- Form Subdivision','acsaf','name')),
-    (52, 1, 12, '748', 'avwxyz25', oils_i18n_gettext('52','Established Heading Linking Entry -- Chronological Term','acsaf','name')),
+    (41, 1, 1, '700', 'abcdefghjklmnopqrstvwxyz25', 'abcdefghjklmnopqrstvxyz', oils_i18n_gettext('41','Established Heading Linking Entry -- Personal Name','acsaf','name')),
+    (42, 1, 2, '710', 'abcdefghklmnoprstvwxyz25', 'abcdefghklmnoprstvxyz', oils_i18n_gettext('42','Established Heading Linking Entry -- Corporate Name','acsaf','name')),
+    (43, 1, 3, '711', 'acdefghklnpqstvwxyz25', 'acdefghklnpqstvxyz', oils_i18n_gettext('43','Established Heading Linking Entry -- Meeting Name','acsaf','name')),
+    (45, 1, 5, '750', 'abvwxyz25', 'abvxyz', oils_i18n_gettext('45','Established Heading Linking Entry -- Topical Term','acsaf','name')),
+    (46, 1, 6, '751', 'avwxyz25', 'avxyz', oils_i18n_gettext('46','Established Heading Linking Entry -- Geographic Name','acsaf','name')),
+    (47, 1, 7, '755', 'avwxyz25', 'avxyz', oils_i18n_gettext('47','Established Heading Linking Entry -- Genre/Form Term','acsaf','name')),
+    (48, 1, 8, '780', 'vwxyz25', 'vxyz', oils_i18n_gettext('48','Subdivision Linking Entry -- General Subdivision','acsaf','name')),
+    (49, 1, 9, '781', 'vwxyz25', 'vxyz', oils_i18n_gettext('49','Subdivision Linking Entry -- Geographic Subdivision','acsaf','name')),
+    (50, 1, 10, '782', 'vwxyz25', 'vxyz', oils_i18n_gettext('50','Subdivision Linking Entry -- Chronological Subdivision','acsaf','name')),
+    (51, 1, 11, '785', 'vwxyz25', 'vxyz', oils_i18n_gettext('51','Subdivision Linking Entry -- Form Subdivision','acsaf','name')),
+    (52, 1, 12, '748', 'avwxyz25', 'avxyz', oils_i18n_gettext('52','Established Heading Linking Entry -- Chronological Term','acsaf','name')),
 
 -- See From tracings
-    (61, 1, 1, '400', 'abcdefiklmnopqrstvwxyz4', oils_i18n_gettext('61','See From Tracing -- Personal Name','acsaf','name')),
-    (62, 1, 2, '410', 'abcdefgiklmnoprstvwxyz4', oils_i18n_gettext('62','See From Tracing -- Corporate Name','acsaf','name')),
-    (63, 1, 3, '411', 'acdefgiklnpqstvwxyz4', oils_i18n_gettext('63','See From Tracing -- Meeting Name','acsaf','name')),
-    (65, 1, 5, '450', 'abivwxyz4', oils_i18n_gettext('65','See From Tracing -- Topical Term','acsaf','name')),
-    (66, 1, 6, '451', 'aivwxyz4', oils_i18n_gettext('66','See From Tracing -- Geographic Name','acsaf','name')),
-    (67, 1, 7, '455', 'aivwxyz4', oils_i18n_gettext('67','See From Tracing -- Genre/Form Term','acsaf','name')),
-    (68, 1, 8, '480', 'ivwxyz4', oils_i18n_gettext('68','See From Tracing -- General Subdivision','acsaf','name')),
-    (69, 1, 9, '481', 'ivwxyz4', oils_i18n_gettext('69','See From Tracing -- Geographic Subdivision','acsaf','name')),
-    (70, 1, 10, '482', 'ivwxyz4', oils_i18n_gettext('70','See From Tracing -- Chronological Subdivision','acsaf','name')),
-    (71, 1, 11, '485', 'ivwxyz4', oils_i18n_gettext('71','See From Tracing -- Form Subdivision','acsaf','name')),
-    (72, 1, 12, '448', 'aivwxyz4', oils_i18n_gettext('72','See From Tracing -- Chronological Term','acsaf','name'));
+    (61, 1, 1, '400', 'abcdefiklmnopqrstvwxyz4', 'abcdefiklmnopqrstvxyz', oils_i18n_gettext('61','See From Tracing -- Personal Name','acsaf','name')),
+    (62, 1, 2, '410', 'abcdefgiklmnoprstvwxyz4', 'abcdefgiklmnoprstvxyz', oils_i18n_gettext('62','See From Tracing -- Corporate Name','acsaf','name')),
+    (63, 1, 3, '411', 'acdefgiklnpqstvwxyz4', 'acdefgiklnpqstvxyz', oils_i18n_gettext('63','See From Tracing -- Meeting Name','acsaf','name')),
+    (65, 1, 5, '450', 'abivwxyz4', 'abivxyz', oils_i18n_gettext('65','See From Tracing -- Topical Term','acsaf','name')),
+    (66, 1, 6, '451', 'aivwxyz4', 'aivxyz', oils_i18n_gettext('66','See From Tracing -- Geographic Name','acsaf','name')),
+    (67, 1, 7, '455', 'aivwxyz4', 'aivxyz', oils_i18n_gettext('67','See From Tracing -- Genre/Form Term','acsaf','name')),
+    (68, 1, 8, '480', 'ivwxyz4', 'ivxyz', oils_i18n_gettext('68','See From Tracing -- General Subdivision','acsaf','name')),
+    (69, 1, 9, '481', 'ivwxyz4', 'ivxyz', oils_i18n_gettext('69','See From Tracing -- Geographic Subdivision','acsaf','name')),
+    (70, 1, 10, '482', 'ivwxyz4', 'ivxyz', oils_i18n_gettext('70','See From Tracing -- Chronological Subdivision','acsaf','name')),
+    (71, 1, 11, '485', 'ivwxyz4', 'ivxyz', oils_i18n_gettext('71','See From Tracing -- Form Subdivision','acsaf','name')),
+    (72, 1, 12, '448', 'aivwxyz4', 'aivxyz', oils_i18n_gettext('72','See From Tracing -- Chronological Term','acsaf','name'));
 
 UPDATE authority.control_set_authority_field
     SET linking_subfield = '0' WHERE main_entry IS NOT NULL;
diff --git a/Open-ILS/src/sql/Pg/953.data.MODS32-xsl.sql b/Open-ILS/src/sql/Pg/953.data.MODS32-xsl.sql
index 542440a..64da844 100644
--- a/Open-ILS/src/sql/Pg/953.data.MODS32-xsl.sql
+++ b/Open-ILS/src/sql/Pg/953.data.MODS32-xsl.sql
@@ -182,6 +182,16 @@ Added Log Comment
 			</titleInfo>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='242']">
+			<xsl:variable name="titleChop">
+				<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>
 			<titleInfo type="translated">
 				<!--09/01/04 Added subfield $y-->
 				<xsl:for-each select="marc:subfield[@code='y']">
@@ -190,19 +200,36 @@ Added Log Comment
 					</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">a</xsl:with-param>
-							</xsl:call-template>
-						</xsl:with-param>
-					</xsl:call-template>
+					<xsl:value-of select="$titleChop" />
 				</title>
 				<!-- 1/04 fix -->
 				<xsl:call-template name="subtitle"/>
 				<xsl:call-template name="part"/>
 			</titleInfo>
+			<titleInfo type="translated-nfi">
+				<xsl:for-each select="marc:subfield[@code='y']">
+					<xsl:attribute name="lang">
+						<xsl:value-of select="text()"/>
+					</xsl:attribute>
+				</xsl:for-each>
+				<xsl:choose>
+					<xsl:when test="@ind2>0">
+						<nonSort>
+							<xsl:value-of select="substring($titleChop,1, at ind2)"/>
+						</nonSort>
+						<title>
+							<xsl:value-of select="substring($titleChop, at ind2+1)"/>
+						</title>
+					</xsl:when>
+					<xsl:otherwise>
+						<title>
+							<xsl:value-of select="$titleChop" />
+						</title>
+					</xsl:otherwise>
+				</xsl:choose>
+				<xsl:call-template name="subtitle"/>
+				<xsl:call-template name="part"/>
+			</titleInfo>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='246']">
 			<titleInfo type="alternative">
@@ -226,39 +253,91 @@ Added Log Comment
 			</titleInfo>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='130']|marc:datafield[@tag='240']|marc:datafield[@tag='730'][@ind2!='2']">
+			<xsl:variable name="nfi">
+				<xsl:choose>
+					<xsl:when test="@tag='240'">
+						<xsl:value-of select="@ind2"/>
+					</xsl:when>
+					<xsl:otherwise>
+						<xsl:value-of select="@ind1"/>
+					</xsl:otherwise>
+				</xsl:choose>
+			</xsl:variable>
+			<xsl:variable name="titleChop">
+				<xsl:call-template name="uri" />
+				<xsl:variable name="str">
+					<xsl:for-each select="marc:subfield">
+						<xsl:if test="(contains('adfklmor', at 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>
+			</xsl:variable>
 			<titleInfo type="uniform">
 				<title>
-					<xsl:call-template name="uri" />
-					<xsl:variable name="str">
-						<xsl:for-each select="marc:subfield">
-							<xsl:if test="(contains('adfklmor', at 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>
+					<xsl:value-of select="$titleChop"/>
 				</title>
 				<xsl:call-template name="part"/>
 			</titleInfo>
+			<titleInfo type="uniform-nfi">
+				<xsl:choose>
+					<xsl:when test="$nfi>0">
+						<nonSort>
+							<xsl:value-of select="substring($titleChop,1,$nfi)"/>
+						</nonSort>
+						<title>
+							<xsl:value-of select="substring($titleChop,$nfi+1)"/>
+						</title>
+					</xsl:when>
+					<xsl:otherwise>
+						<title>
+							<xsl:value-of select="$titleChop"/>
+						</title>
+					</xsl:otherwise>
+				</xsl:choose>
+				<xsl:call-template name="part"/>
+			</titleInfo>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='740'][@ind2!='2']">
+			<xsl:variable name="titleChop">
+				<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>
+			</xsl:variable>
 			<titleInfo type="alternative">
 				<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>
+					<xsl:value-of select="$titleChop" />
 				</title>
 				<xsl:call-template name="part"/>
 			</titleInfo>
+			<titleInfo type="alternative-nfi">
+				<xsl:choose>
+					<xsl:when test="@ind1>0">
+						<nonSort>
+							<xsl:value-of select="substring($titleChop,1, at ind1)"/>
+						</nonSort>
+						<title>
+							<xsl:value-of select="substring($titleChop, at ind1+1)"/>
+						</title>
+					</xsl:when>
+					<xsl:otherwise>
+						<title>
+							<xsl:value-of select="$titleChop" />
+						</title>
+					</xsl:otherwise>
+				</xsl:choose>
+				<xsl:call-template name="part"/>
+			</titleInfo>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='100']">
 			<name type="personal">
@@ -1591,18 +1670,40 @@ Added Log Comment
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag=440]">
 			<relatedItem type="series">
+				<xsl:variable name="titleChop">
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:call-template name="subfieldSelect">
+								<xsl:with-param name="codes">av</xsl:with-param>
+							</xsl:call-template>
+						</xsl:with-param>
+					</xsl:call-template>
+				</xsl:variable>
 				<titleInfo>
 					<title>
-						<xsl:call-template name="chopPunctuation">
-							<xsl:with-param name="chopString">
-								<xsl:call-template name="subfieldSelect">
-									<xsl:with-param name="codes">av</xsl:with-param>
-								</xsl:call-template>
-							</xsl:with-param>
-						</xsl:call-template>
+						<xsl:value-of select="$titleChop" />
 					</title>
 					<xsl:call-template name="part"></xsl:call-template>
 				</titleInfo>
+				<titleInfo type="nfi">
+					<xsl:choose>
+						<xsl:when test="@ind2>0">
+							<nonSort>
+								<xsl:value-of select="substring($titleChop,1, at ind2)"/>
+							</nonSort>
+							<title>
+								<xsl:value-of select="substring($titleChop, at ind2+1)"/>
+							</title>
+							<xsl:call-template name="part"/>
+						</xsl:when>
+						<xsl:otherwise>
+							<title>
+								<xsl:value-of select="$titleChop" />
+							</title>
+						</xsl:otherwise>
+					</xsl:choose>
+					<xsl:call-template name="part"></xsl:call-template>
+				</titleInfo>
 			</relatedItem>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag=490][@ind1=0]">
@@ -1788,16 +1889,37 @@ Added Log Comment
 		<xsl:for-each select="marc:datafield[@tag=740][@ind2=2]">
 			<relatedItem>
 				<xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
+				<xsl:variable name="titleChop">
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
+						</xsl:with-param>
+					</xsl:call-template>
+				</xsl:variable>
 				<titleInfo>
 					<title>
-						<xsl:call-template name="chopPunctuation">
-							<xsl:with-param name="chopString">
-								<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
-							</xsl:with-param>
-						</xsl:call-template>
+						<xsl:value-of select="$titleChop" />
 					</title>
 					<xsl:call-template name="part"></xsl:call-template>
 				</titleInfo>
+				<titleInfo type="nfi">
+					<xsl:choose>
+						<xsl:when test="@ind1>0">
+							<nonSort>
+								<xsl:value-of select="substring($titleChop,1, at ind1)"/>
+							</nonSort>
+							<title>
+								<xsl:value-of select="substring($titleChop, at ind1+1)"/>
+							</title>
+						</xsl:when>
+						<xsl:otherwise>
+							<title>
+								<xsl:value-of select="$titleChop" />
+							</title>
+						</xsl:otherwise>
+					</xsl:choose>
+					<xsl:call-template name="part"></xsl:call-template>
+				</titleInfo>
 				<xsl:call-template name="relatedForm"></xsl:call-template>
 			</relatedItem>
 		</xsl:for-each>
@@ -1951,18 +2073,39 @@ Added Log Comment
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='830']">
 			<relatedItem type="series">
+				<xsl:variable name="titleChop">
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:call-template name="subfieldSelect">
+								<xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
+							</xsl:call-template>
+						</xsl:with-param>
+					</xsl:call-template>
+				</xsl:variable>
 				<titleInfo>
 					<title>
-						<xsl:call-template name="chopPunctuation">
-							<xsl:with-param name="chopString">
-								<xsl:call-template name="subfieldSelect">
-									<xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
-								</xsl:call-template>
-							</xsl:with-param>
-						</xsl:call-template>
+						<xsl:value-of select="$titleChop" />
 					</title>
 					<xsl:call-template name="part"/>
 				</titleInfo>
+				<titleInfo type="nfi">
+					<xsl:choose>
+						<xsl:when test="@ind2>0">
+							<nonSort>
+								<xsl:value-of select="substring($titleChop,1, at ind2)"/>
+							</nonSort>
+							<title>
+								<xsl:value-of select="substring($titleChop, at ind2+1)"/>
+							</title>
+						</xsl:when>
+						<xsl:otherwise>
+							<title>
+								<xsl:value-of select="$titleChop" />
+							</title>
+						</xsl:otherwise>
+					</xsl:choose>
+					<xsl:call-template name="part"/>
+				</titleInfo>
 				<xsl:call-template name="relatedForm"/>
 			</relatedItem>
 		</xsl:for-each>
@@ -2629,6 +2772,7 @@ Added Log Comment
 		<subject>
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
 			<name type="personal">
+				<xsl:call-template name="uri" />
 				<xsl:call-template name="termsOfAddress"></xsl:call-template>
 				<namePart>
 					<xsl:call-template name="chopPunctuation">
@@ -2650,6 +2794,7 @@ Added Log Comment
 		<subject>
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
 			<name type="corporate">
+				<xsl:call-template name="uri" />
 				<xsl:for-each select="marc:subfield[@code='a']">
 					<namePart>
 						<xsl:value-of select="."></xsl:value-of>
@@ -2676,6 +2821,7 @@ Added Log Comment
 		<subject>
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
 			<name type="conference">
+				<xsl:call-template name="uri" />
 				<namePart>
 					<xsl:call-template name="subfieldSelect">
 						<xsl:with-param name="codes">abcdeqnp</xsl:with-param>
@@ -2695,17 +2841,39 @@ Added Log Comment
 	<xsl:template match="marc:datafield[@tag=630]">
 		<subject>
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
+			<xsl:variable name="titleChop">
+				<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>
+			</xsl:variable>
 			<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>
-					<xsl:call-template name="part"></xsl:call-template>
+					<xsl:value-of select="$titleChop" />
 				</title>
+				<xsl:call-template name="part"></xsl:call-template>
+			</titleInfo>
+			<titleInfo type="nfi">
+				<xsl:choose>
+					<xsl:when test="@ind1>0">
+						<nonSort>
+							<xsl:value-of select="substring($titleChop,1, at ind1)"/>
+						</nonSort>
+						<title>
+							<xsl:value-of select="substring($titleChop, at ind1+1)"/>
+						</title>
+						<xsl:call-template name="part"/>
+					</xsl:when>
+					<xsl:otherwise>
+						<title>
+							<xsl:value-of select="$titleChop" />
+						</title>
+					</xsl:otherwise>
+				</xsl:choose>
+				<xsl:call-template name="part"></xsl:call-template>
 			</titleInfo>
 			<xsl:call-template name="subjectAnyOrder"></xsl:call-template>
 		</subject>
@@ -2714,6 +2882,7 @@ Added Log Comment
 		<subject>
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
 			<topic>
+				<xsl:call-template name="uri" />
 				<xsl:call-template name="chopPunctuation">
 					<xsl:with-param name="chopString">
 						<xsl:call-template name="subfieldSelect">
@@ -2730,6 +2899,7 @@ Added Log Comment
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
 			<xsl:for-each select="marc:subfield[@code='a']">
 				<geographic>
+					<xsl:call-template name="uri" />
 					<xsl:call-template name="chopPunctuation">
 						<xsl:with-param name="chopString" select="."></xsl:with-param>
 					</xsl:call-template>
@@ -2742,6 +2912,7 @@ Added Log Comment
 		<subject>
 			<xsl:for-each select="marc:subfield[@code='a']">
 				<topic>
+					<xsl:call-template name="uri" />
 					<xsl:value-of select="."></xsl:value-of>
 				</topic>
 			</xsl:for-each>
@@ -2754,8 +2925,8 @@ Added Log Comment
 					<xsl:value-of select="marc:subfield[@code=2]"></xsl:value-of>
 				</xsl:attribute>
 			</xsl:if>
-			<xsl:call-template name="uri" />
 			<occupation>
+				<xsl:call-template name="uri" />
 				<xsl:call-template name="chopPunctuation">
 					<xsl:with-param name="chopString">
 						<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql
index 404480f..e419dae 100644
--- a/Open-ILS/src/sql/Pg/999.functions.global.sql
+++ b/Open-ILS/src/sql/Pg/999.functions.global.sql
@@ -1537,7 +1537,7 @@ BEGIN
             FROM authority.control_set_authority_field
             WHERE tag IN (
                 SELECT UNNEST(
-                    XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc::XML)::TEXT[]
+                    XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc_xml)::TEXT[]
                 )
             ) LIMIT 1;
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql
index 0424a77..7901876 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql
@@ -33,7 +33,7 @@ BEGIN
             FROM authority.control_set_authority_field
             WHERE tag IN (
                 SELECT UNNEST(
-                    XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc::XML)::TEXT[]
+                    XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc_xml::XML)::TEXT[]
                 )
             ) LIMIT 1;
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
index ba30e46..66c8fcb 100644
--- a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
@@ -3,11 +3,21 @@ BEGIN;
 -- check whether patch can be applied
 -- SELECT evergreen.upgrade_deps_block_check('YYYY', :eg_version);
 
+ALTER TABLE authority.control_set_authority_field
+    ADD COLUMN display_sf_list TEXT;
+
+UPDATE authority.control_set_authority_field
+    SET display_sf_list = REGEXP_REPLACE(sf_list, '[w254]', '', 'g');
+
+ALTER TABLE authority.control_set_authority_field
+    ALTER COLUMN display_sf_list SET NOT NULL;
+
 ALTER TABLE metabib.browse_entry_def_map
     ADD COLUMN authority BIGINT REFERENCES authority.record_entry (id)
         ON DELETE SET NULL;
 
 ALTER TABLE config.metabib_field ADD COLUMN authority_xpath TEXT;
+ALTER TABLE config.metabib_field ADD COLUMN browse_sort_xpath TEXT;
 
 UPDATE config.metabib_field
     SET authority_xpath = '//@xlink:href'
@@ -17,7 +27,7 @@ UPDATE config.metabib_field
         browse_field IS TRUE;
 
 ALTER TYPE metabib.field_entry_template ADD ATTRIBUTE authority BIGINT;
-
+ALTER TYPE metabib.field_entry_template ADD ATTRIBUTE sort_value TEXT;
 
 CREATE OR REPLACE FUNCTION metabib.reingest_metabib_field_entries( bib_id BIGINT, skip_facet BOOL DEFAULT FALSE, skip_browse BOOL DEFAULT FALSE, skip_search BOOL DEFAULT FALSE ) RETURNS VOID AS $func$
 DECLARE
@@ -28,6 +38,7 @@ DECLARE
     b_skip_facet    BOOL;
     b_skip_browse   BOOL;
     b_skip_search   BOOL;
+    value_prepped   TEXT;
 BEGIN
 
     SELECT COALESCE(NULLIF(skip_facet, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_facet_indexing' AND enabled)) INTO b_skip_facet;
@@ -67,12 +78,18 @@ BEGIN
             -- evergreen.oils_tsearch2()) changes.  It may or may not be
             -- expensive to add a comparison of index_vector to index_vector
             -- to the WHERE clause below.
-            SELECT INTO mbe_row * FROM metabib.browse_entry WHERE value = ind_data.value;
+
+            value_prepped := metabib.browse_normalize(ind_data.value, ind_data.field);
+            SELECT INTO mbe_row * FROM metabib.browse_entry
+                WHERE value = value_prepped AND sort_value = ind_data.sort_value;
+
             IF FOUND THEN
                 mbe_id := mbe_row.id;
             ELSE
-                INSERT INTO metabib.browse_entry (value) VALUES
-                    (metabib.browse_normalize(ind_data.value, ind_data.field));
+                INSERT INTO metabib.browse_entry
+                    ( value, sort_value ) VALUES
+                    ( value_prepped, ind_data.sort_value );
+
                 mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
             END IF;
 
@@ -112,6 +129,7 @@ DECLARE
     xml_node_list   TEXT[];
     facet_text  TEXT;
     browse_text TEXT;
+    sort_value  TEXT;
     raw_text    TEXT;
     curr_text   TEXT;
     joiner      TEXT := default_joiner; -- XXX will index defs supply a joiner?
@@ -180,10 +198,25 @@ BEGIN
                     browse_text := curr_text;
                 END IF;
 
+                IF idx.browse_sort_xpath IS NOT NULL AND
+                    idx.browse_sort_xpath <> '' THEN
+
+                    sort_value := oils_xpath_string(
+                        idx.browse_sort_xpath, xml_node, joiner,
+                        ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]]
+                    );
+                ELSE
+                    sort_value := browse_text;
+                END IF;
+
                 output_row.field_class = idx.field_class;
                 output_row.field = idx.id;
                 output_row.source = rid;
                 output_row.value = BTRIM(REGEXP_REPLACE(browse_text, E'\\s+', ' ', 'g'));
+                output_row.sort_value :=
+                    public.search_normalize(sort_value);
+
+                output_row.authority := NULL;
 
                 IF idx.authority_xpath IS NOT NULL AND idx.authority_xpath <> '' THEN
                     authority_text := oils_xpath_string(
@@ -207,6 +240,7 @@ BEGIN
                 output_row.browse_field = TRUE;
                 RETURN NEXT output_row;
                 output_row.browse_field = FALSE;
+                output_row.sort_value := NULL;
             END IF;
 
             -- insert raw node text for faceting
@@ -241,6 +275,7 @@ BEGIN
 
             output_row.search_field = TRUE;
             RETURN NEXT output_row;
+            output_row.search_field = FALSE;
         END IF;
 
     END LOOP;
@@ -435,6 +470,16 @@ Added Log Comment
 			</titleInfo>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='242']">
+			<xsl:variable name="titleChop">
+				<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>
 			<titleInfo type="translated">
 				<!--09/01/04 Added subfield $y-->
 				<xsl:for-each select="marc:subfield[@code='y']">
@@ -443,19 +488,36 @@ Added Log Comment
 					</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">a</xsl:with-param>
-							</xsl:call-template>
-						</xsl:with-param>
-					</xsl:call-template>
+					<xsl:value-of select="$titleChop" />
 				</title>
 				<!-- 1/04 fix -->
 				<xsl:call-template name="subtitle"/>
 				<xsl:call-template name="part"/>
 			</titleInfo>
+			<titleInfo type="translated-nfi">
+				<xsl:for-each select="marc:subfield[@code='y']">
+					<xsl:attribute name="lang">
+						<xsl:value-of select="text()"/>
+					</xsl:attribute>
+				</xsl:for-each>
+				<xsl:choose>
+					<xsl:when test="@ind2>0">
+						<nonSort>
+							<xsl:value-of select="substring($titleChop,1, at ind2)"/>
+						</nonSort>
+						<title>
+							<xsl:value-of select="substring($titleChop, at ind2+1)"/>
+						</title>
+					</xsl:when>
+					<xsl:otherwise>
+						<title>
+							<xsl:value-of select="$titleChop" />
+						</title>
+					</xsl:otherwise>
+				</xsl:choose>
+				<xsl:call-template name="subtitle"/>
+				<xsl:call-template name="part"/>
+			</titleInfo>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='246']">
 			<titleInfo type="alternative">
@@ -479,39 +541,91 @@ Added Log Comment
 			</titleInfo>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='130']|marc:datafield[@tag='240']|marc:datafield[@tag='730'][@ind2!='2']">
+			<xsl:variable name="nfi">
+				<xsl:choose>
+					<xsl:when test="@tag='240'">
+						<xsl:value-of select="@ind2"/>
+					</xsl:when>
+					<xsl:otherwise>
+						<xsl:value-of select="@ind1"/>
+					</xsl:otherwise>
+				</xsl:choose>
+			</xsl:variable>
+			<xsl:variable name="titleChop">
+				<xsl:call-template name="uri" />
+				<xsl:variable name="str">
+					<xsl:for-each select="marc:subfield">
+						<xsl:if test="(contains('adfklmor', at 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>
+			</xsl:variable>
 			<titleInfo type="uniform">
 				<title>
-					<xsl:call-template name="uri" />
-					<xsl:variable name="str">
-						<xsl:for-each select="marc:subfield">
-							<xsl:if test="(contains('adfklmor', at 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>
+					<xsl:value-of select="$titleChop"/>
 				</title>
 				<xsl:call-template name="part"/>
 			</titleInfo>
+			<titleInfo type="uniform-nfi">
+				<xsl:choose>
+					<xsl:when test="$nfi>0">
+						<nonSort>
+							<xsl:value-of select="substring($titleChop,1,$nfi)"/>
+						</nonSort>
+						<title>
+							<xsl:value-of select="substring($titleChop,$nfi+1)"/>
+						</title>
+					</xsl:when>
+					<xsl:otherwise>
+						<title>
+							<xsl:value-of select="$titleChop"/>
+						</title>
+					</xsl:otherwise>
+				</xsl:choose>
+				<xsl:call-template name="part"/>
+			</titleInfo>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='740'][@ind2!='2']">
+			<xsl:variable name="titleChop">
+				<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>
+			</xsl:variable>
 			<titleInfo type="alternative">
 				<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>
+					<xsl:value-of select="$titleChop" />
 				</title>
 				<xsl:call-template name="part"/>
 			</titleInfo>
+			<titleInfo type="alternative-nfi">
+				<xsl:choose>
+					<xsl:when test="@ind1>0">
+						<nonSort>
+							<xsl:value-of select="substring($titleChop,1, at ind1)"/>
+						</nonSort>
+						<title>
+							<xsl:value-of select="substring($titleChop, at ind1+1)"/>
+						</title>
+					</xsl:when>
+					<xsl:otherwise>
+						<title>
+							<xsl:value-of select="$titleChop" />
+						</title>
+					</xsl:otherwise>
+				</xsl:choose>
+				<xsl:call-template name="part"/>
+			</titleInfo>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='100']">
 			<name type="personal">
@@ -1844,18 +1958,40 @@ Added Log Comment
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag=440]">
 			<relatedItem type="series">
+				<xsl:variable name="titleChop">
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:call-template name="subfieldSelect">
+								<xsl:with-param name="codes">av</xsl:with-param>
+							</xsl:call-template>
+						</xsl:with-param>
+					</xsl:call-template>
+				</xsl:variable>
 				<titleInfo>
 					<title>
-						<xsl:call-template name="chopPunctuation">
-							<xsl:with-param name="chopString">
-								<xsl:call-template name="subfieldSelect">
-									<xsl:with-param name="codes">av</xsl:with-param>
-								</xsl:call-template>
-							</xsl:with-param>
-						</xsl:call-template>
+						<xsl:value-of select="$titleChop" />
 					</title>
 					<xsl:call-template name="part"></xsl:call-template>
 				</titleInfo>
+				<titleInfo type="nfi">
+					<xsl:choose>
+						<xsl:when test="@ind2>0">
+							<nonSort>
+								<xsl:value-of select="substring($titleChop,1, at ind2)"/>
+							</nonSort>
+							<title>
+								<xsl:value-of select="substring($titleChop, at ind2+1)"/>
+							</title>
+							<xsl:call-template name="part"/>
+						</xsl:when>
+						<xsl:otherwise>
+							<title>
+								<xsl:value-of select="$titleChop" />
+							</title>
+						</xsl:otherwise>
+					</xsl:choose>
+					<xsl:call-template name="part"></xsl:call-template>
+				</titleInfo>
 			</relatedItem>
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag=490][@ind1=0]">
@@ -2041,16 +2177,37 @@ Added Log Comment
 		<xsl:for-each select="marc:datafield[@tag=740][@ind2=2]">
 			<relatedItem>
 				<xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
+				<xsl:variable name="titleChop">
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
+						</xsl:with-param>
+					</xsl:call-template>
+				</xsl:variable>
 				<titleInfo>
 					<title>
-						<xsl:call-template name="chopPunctuation">
-							<xsl:with-param name="chopString">
-								<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
-							</xsl:with-param>
-						</xsl:call-template>
+						<xsl:value-of select="$titleChop" />
 					</title>
 					<xsl:call-template name="part"></xsl:call-template>
 				</titleInfo>
+				<titleInfo type="nfi">
+					<xsl:choose>
+						<xsl:when test="@ind1>0">
+							<nonSort>
+								<xsl:value-of select="substring($titleChop,1, at ind1)"/>
+							</nonSort>
+							<title>
+								<xsl:value-of select="substring($titleChop, at ind1+1)"/>
+							</title>
+						</xsl:when>
+						<xsl:otherwise>
+							<title>
+								<xsl:value-of select="$titleChop" />
+							</title>
+						</xsl:otherwise>
+					</xsl:choose>
+					<xsl:call-template name="part"></xsl:call-template>
+				</titleInfo>
 				<xsl:call-template name="relatedForm"></xsl:call-template>
 			</relatedItem>
 		</xsl:for-each>
@@ -2204,18 +2361,39 @@ Added Log Comment
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='830']">
 			<relatedItem type="series">
+				<xsl:variable name="titleChop">
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:call-template name="subfieldSelect">
+								<xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
+							</xsl:call-template>
+						</xsl:with-param>
+					</xsl:call-template>
+				</xsl:variable>
 				<titleInfo>
 					<title>
-						<xsl:call-template name="chopPunctuation">
-							<xsl:with-param name="chopString">
-								<xsl:call-template name="subfieldSelect">
-									<xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
-								</xsl:call-template>
-							</xsl:with-param>
-						</xsl:call-template>
+						<xsl:value-of select="$titleChop" />
 					</title>
 					<xsl:call-template name="part"/>
 				</titleInfo>
+				<titleInfo type="nfi">
+					<xsl:choose>
+						<xsl:when test="@ind2>0">
+							<nonSort>
+								<xsl:value-of select="substring($titleChop,1, at ind2)"/>
+							</nonSort>
+							<title>
+								<xsl:value-of select="substring($titleChop, at ind2+1)"/>
+							</title>
+						</xsl:when>
+						<xsl:otherwise>
+							<title>
+								<xsl:value-of select="$titleChop" />
+							</title>
+						</xsl:otherwise>
+					</xsl:choose>
+					<xsl:call-template name="part"/>
+				</titleInfo>
 				<xsl:call-template name="relatedForm"/>
 			</relatedItem>
 		</xsl:for-each>
@@ -2882,6 +3060,7 @@ Added Log Comment
 		<subject>
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
 			<name type="personal">
+				<xsl:call-template name="uri" />
 				<xsl:call-template name="termsOfAddress"></xsl:call-template>
 				<namePart>
 					<xsl:call-template name="chopPunctuation">
@@ -2903,6 +3082,7 @@ Added Log Comment
 		<subject>
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
 			<name type="corporate">
+				<xsl:call-template name="uri" />
 				<xsl:for-each select="marc:subfield[@code='a']">
 					<namePart>
 						<xsl:value-of select="."></xsl:value-of>
@@ -2929,6 +3109,7 @@ Added Log Comment
 		<subject>
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
 			<name type="conference">
+				<xsl:call-template name="uri" />
 				<namePart>
 					<xsl:call-template name="subfieldSelect">
 						<xsl:with-param name="codes">abcdeqnp</xsl:with-param>
@@ -2948,17 +3129,39 @@ Added Log Comment
 	<xsl:template match="marc:datafield[@tag=630]">
 		<subject>
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
+			<xsl:variable name="titleChop">
+				<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>
+			</xsl:variable>
 			<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>
-					<xsl:call-template name="part"></xsl:call-template>
+					<xsl:value-of select="$titleChop" />
 				</title>
+				<xsl:call-template name="part"></xsl:call-template>
+			</titleInfo>
+			<titleInfo type="nfi">
+				<xsl:choose>
+					<xsl:when test="@ind1>0">
+						<nonSort>
+							<xsl:value-of select="substring($titleChop,1, at ind1)"/>
+						</nonSort>
+						<title>
+							<xsl:value-of select="substring($titleChop, at ind1+1)"/>
+						</title>
+						<xsl:call-template name="part"/>
+					</xsl:when>
+					<xsl:otherwise>
+						<title>
+							<xsl:value-of select="$titleChop" />
+						</title>
+					</xsl:otherwise>
+				</xsl:choose>
+				<xsl:call-template name="part"></xsl:call-template>
 			</titleInfo>
 			<xsl:call-template name="subjectAnyOrder"></xsl:call-template>
 		</subject>
@@ -2967,6 +3170,7 @@ Added Log Comment
 		<subject>
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
 			<topic>
+				<xsl:call-template name="uri" />
 				<xsl:call-template name="chopPunctuation">
 					<xsl:with-param name="chopString">
 						<xsl:call-template name="subfieldSelect">
@@ -2983,6 +3187,7 @@ Added Log Comment
 			<xsl:call-template name="subjectAuthority"></xsl:call-template>
 			<xsl:for-each select="marc:subfield[@code='a']">
 				<geographic>
+					<xsl:call-template name="uri" />
 					<xsl:call-template name="chopPunctuation">
 						<xsl:with-param name="chopString" select="."></xsl:with-param>
 					</xsl:call-template>
@@ -2995,6 +3200,7 @@ Added Log Comment
 		<subject>
 			<xsl:for-each select="marc:subfield[@code='a']">
 				<topic>
+					<xsl:call-template name="uri" />
 					<xsl:value-of select="."></xsl:value-of>
 				</topic>
 			</xsl:for-each>
@@ -3007,8 +3213,8 @@ Added Log Comment
 					<xsl:value-of select="marc:subfield[@code=2]"></xsl:value-of>
 				</xsl:attribute>
 			</xsl:if>
-			<xsl:call-template name="uri" />
 			<occupation>
+				<xsl:call-template name="uri" />
 				<xsl:call-template name="chopPunctuation">
 					<xsl:with-param name="chopString">
 						<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
@@ -6882,4 +7088,342 @@ Revision 1.2 - Added Log Comment  2003/03/24 19:37:42  ckeith
 	</xsl:template>
 </xsl:stylesheet>$$ WHERE name = 'mods33';
 
+
+INSERT INTO config.global_flag (name, value, enabled, label) VALUES
+(
+    'opac.browse.warnable_regexp_per_class',
+    '{"title": "^(a|the|an)\\s"}',
+    FALSE,
+    oils_i18n_gettext(
+        'opac.browse.warnable_regexp_per_class',
+        'Map of search classes to regular expressions to warn user about leading articles.',
+        'cgf',
+        'label'
+    )
+),
+(
+    'opac.browse.holdings_visibility_test_limit',
+    '100',
+    TRUE,
+    oils_i18n_gettext(
+        'opac.browse.holdings_visibility_test_limit',
+        'Don''t look for more than this number of records with holdings when displaying browse headings with visible record counts.',
+        'cgf',
+        'label'
+    )
+);
+
+ALTER TABLE metabib.browse_entry DROP CONSTRAINT browse_entry_value_key;
+ALTER TABLE metabib.browse_entry ADD COLUMN sort_value TEXT;
+DELETE FROM metabib.browse_entry_def_map; -- Yeah.
+DELETE FROM metabib.browse_entry WHERE sort_value IS NULL;
+ALTER TABLE metabib.browse_entry ALTER COLUMN sort_value SET NOT NULL;
+ALTER TABLE metabib.browse_entry ADD UNIQUE (value, sort_value);
+DROP TRIGGER IF EXISTS mbe_sort_value ON metabib.browse_entry;
+
+CREATE INDEX browse_entry_sort_value_idx
+    ON metabib.browse_entry USING BTREE (sort_value);
+
+-- NOTE If I understand ordered indices correctly, an index on sort_value DESC
+-- is not actually needed, even though we do have a query that does ORDER BY
+-- on this column in that direction.  The previous index serves for both
+-- directions, and ordering in an index is only helpful for multi-column
+-- indices, I think. See http://www.postgresql.org/docs/9.1/static/indexes-ordering.html
+
+-- CREATE INDEX CONCURRENTLY browse_entry_sort_value_idx_desc
+--     ON metabib.browse_entry USING BTREE (sort_value DESC);
+
+CREATE TYPE metabib.flat_browse_entry_appearance AS (
+    browse_entry    BIGINT,
+    value           TEXT,
+    fields          TEXT,
+    authorities     TEXT,
+    sources         INT,        -- visible ones, that is
+    row_number      INT,        -- internal use, sort of
+    accurate        BOOL        -- Count in sources field is accurate? Not
+                                -- if we had more than a browse superpage
+                                -- of records to look at.
+);
+
+
+CREATE OR REPLACE FUNCTION metabib.browse_pivot(
+    search_field        INT[],
+    browse_term         TEXT
+) RETURNS BIGINT AS $p$
+DECLARE
+    id                  BIGINT;
+BEGIN
+    SELECT INTO id mbe.id FROM metabib.browse_entry mbe
+        JOIN metabib.browse_entry_def_map mbedm ON (
+            mbedm.entry = mbe.id AND
+            mbedm.def = ANY(search_field)
+        )
+        WHERE mbe.sort_value >= public.search_normalize(browse_term)
+        ORDER BY mbe.sort_value, mbe.value LIMIT 1;
+
+    RETURN id;
+END;
+$p$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION metabib.staged_browse(
+    core_query              TEXT,
+    context_org             INT,
+    context_locations       INT[],
+    staff                   BOOL,
+    browse_superpage_size   INT,
+    result_limit            INT,
+    use_offset              INT
+) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
+DECLARE
+    core_cursor             REFCURSOR;
+    core_record             RECORD;
+    qpfts_query             TEXT;
+    result_row              metabib.flat_browse_entry_appearance%ROWTYPE;
+    results_skipped         INT := 0;
+    results_returned        INT := 0;
+    slice_start             INT;
+    slice_end               INT;
+    full_end                INT;
+    superpage_of_records    BIGINT[];
+    superpage_size          INT;
+BEGIN
+    OPEN core_cursor FOR EXECUTE core_query;
+
+    LOOP
+        FETCH core_cursor INTO core_record;
+        EXIT WHEN NOT FOUND;
+
+        result_row.sources := 0;
+
+        full_end := ARRAY_LENGTH(core_record.records, 1);
+        superpage_size := COALESCE(browse_superpage_size, full_end);
+        slice_start := 1;
+        slice_end := superpage_size;
+
+        WHILE result_row.sources = 0 AND slice_start <= full_end LOOP
+            superpage_of_records := core_record.records[slice_start:slice_end];
+            qpfts_query :=
+                'SELECT NULL::BIGINT AS id, ARRAY[r] AS records, ' ||
+                '1::INT AS rel FROM (SELECT UNNEST(' ||
+                quote_literal(superpage_of_records) || '::BIGINT[]) AS r) rr';
+
+            -- We use search.query_parser_fts() for visibility testing.
+            -- We're calling it once per browse-superpage worth of records
+            -- out of the set of records related to a given mbe, until we've
+            -- either exhausted that set of records or found at least 1
+            -- visible record.
+
+            SELECT INTO result_row.sources visible
+                FROM search.query_parser_fts(
+                    context_org, NULL, qpfts_query, NULL,
+                    context_locations, 0, NULL, NULL, FALSE, staff, FALSE
+                ) qpfts
+                WHERE qpfts.rel IS NULL;
+
+            slice_start := slice_start + superpage_size;
+            slice_end := slice_end + superpage_size;
+        END LOOP;
+
+        -- Accurate?  Well, probably.
+        result_row.accurate := browse_superpage_size IS NULL OR
+            browse_superpage_size >= full_end;
+
+        IF result_row.sources > 0 THEN
+            IF results_skipped < use_offset THEN
+                results_skipped := results_skipped + 1;
+                CONTINUE;
+            END IF;
+
+            result_row.browse_entry := core_record.id;
+            result_row.authorities := core_record.authorities;
+            result_row.fields := core_record.fields;
+            result_row.value := core_record.value;
+
+            -- This is needed so our caller can flip it and reverse it.
+            result_row.row_number := results_returned;
+
+            RETURN NEXT result_row;
+
+            results_returned := results_returned + 1;
+
+            EXIT WHEN results_returned >= result_limit;
+        END IF;
+    END LOOP;
+END;
+$p$ LANGUAGE PLPGSQL;
+
+-- This is optimized to be fast for values of result_offset near zero.
+CREATE OR REPLACE FUNCTION metabib.browse(
+    search_field            INT[],
+    browse_term             TEXT,
+    context_org             INT DEFAULT NULL,
+    context_loc_group       INT DEFAULT NULL,
+    staff                   BOOL DEFAULT FALSE,
+    pivot_id                BIGINT DEFAULT NULL,
+    force_backward          BOOL DEFAULT FALSE,
+    result_limit            INT DEFAULT 10,
+    result_offset           INT DEFAULT 0   -- Can be negative!
+) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
+DECLARE
+    core_query              TEXT;
+    whole_query             TEXT;
+    pivot_sort_value        TEXT;
+    pivot_sort_fallback     TEXT;
+    context_locations       INT[];
+    use_offset              INT;
+    browse_superpage_size   INT;
+    results_skipped         INT := 0;
+BEGIN
+    IF pivot_id IS NULL THEN
+        pivot_id := metabib.browse_pivot(search_field, browse_term);
+    END IF;
+
+    SELECT INTO pivot_sort_value, pivot_sort_fallback
+        sort_value, value FROM metabib.browse_entry WHERE id = pivot_id;
+
+    IF pivot_sort_value IS NULL THEN
+        RETURN;
+    END IF;
+
+    IF context_loc_group IS NOT NULL THEN
+        SELECT INTO context_locations ARRAY_AGG(location)
+            FROM asset.copy_location_group_map
+            WHERE lgroup = context_loc_group;
+    END IF;
+
+    SELECT INTO browse_superpage_size value     -- NULL ok
+        FROM config.global_flag
+        WHERE enabled AND name = 'opac.browse.holdings_visibility_test_limit';
+
+    core_query := '
+    SELECT
+        mbe.id,
+        mbe.value,
+        mbe.sort_value,
+        (SELECT ARRAY_AGG(src) FROM (
+            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.source)) AS src
+        ) ss) AS records,
+        (SELECT ARRAY_TO_STRING(ARRAY_AGG(authority), $$,$$) FROM (
+            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.authority)) AS authority
+        ) au) AS authorities,
+        (SELECT ARRAY_TO_STRING(ARRAY_AGG(field), $$,$$) FROM (
+            SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.def)) AS field
+        ) fi) AS fields
+    FROM metabib.browse_entry mbe
+    JOIN metabib.browse_entry_def_map mbedm ON (
+        mbedm.entry = mbe.id AND
+        mbedm.def = ANY(' || quote_literal(search_field) || ')
+    )
+    WHERE ';
+
+    -- PostgreSQL is not magic. We can't actually pass a negative offset.
+    IF result_offset >= 0 AND NOT force_backward THEN
+        use_offset := result_offset;
+        core_query := core_query ||
+            ' mbe.sort_value >= ' || quote_literal(pivot_sort_value) ||
+        ' GROUP BY 1,2,3 ORDER BY mbe.sort_value, mbe.value ';
+
+        RETURN QUERY SELECT * FROM metabib.staged_browse(
+            core_query, context_org, context_locations,
+            staff, browse_superpage_size, result_limit, use_offset
+        );
+    ELSE
+        -- Part 1 of 2 to deliver what the user wants with a negative offset:
+        core_query := core_query ||
+            ' mbe.sort_value < ' || quote_literal(pivot_sort_value) ||
+        ' GROUP BY 1,2,3 ORDER BY mbe.sort_value DESC, mbe.value DESC ';
+
+        -- Part 2 of 2 to deliver what the user wants with a negative offset:
+        RETURN QUERY SELECT * FROM (SELECT * FROM metabib.staged_browse(
+            core_query, context_org, context_locations,
+            staff, browse_superpage_size, result_limit, use_offset
+        )) sb ORDER BY row_number DESC;
+
+    END IF;
+END;
+$p$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION metabib.browse(
+    search_class        TEXT,
+    browse_term         TEXT,
+    context_org         INT DEFAULT NULL,
+    context_loc_group   INT DEFAULT NULL,
+    staff               BOOL DEFAULT FALSE,
+    pivot_id            BIGINT DEFAULT NULL,
+    force_backward      BOOL DEFAULT FALSE,
+    result_limit        INT DEFAULT 10,
+    result_offset       INT DEFAULT 0   -- Can be negative, implying backward!
+) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
+BEGIN
+    RETURN QUERY SELECT * FROM metabib.browse(
+        (SELECT COALESCE(ARRAY_AGG(id), ARRAY[]::INT[])
+            FROM config.metabib_field WHERE field_class = search_class),
+        browse_term,
+        context_org,
+        context_loc_group,
+        staff,
+        pivot_id,
+        force_backward,
+        result_limit,
+        result_offset
+    );
+END;
+$p$ LANGUAGE PLPGSQL;
+
+UPDATE config.metabib_field
+SET
+    xpath = $$//mods32:mods/mods32:relatedItem[@type="series"]/mods32:titleInfo[@type="nfi"]$$,
+    browse_sort_xpath = $$*[local-name() != "nonSort"]$$,
+    browse_xpath = NULL
+WHERE
+    field_class = 'series' AND name = 'seriestitle' ;
+
+UPDATE config.metabib_field
+SET
+    xpath = $$//mods32:mods/mods32:titleInfo[mods32:title and not (@type)]$$,
+    browse_sort_xpath = $$*[local-name() != "nonSort"]$$,
+    browse_xpath = NULL,
+    browse_field = TRUE
+WHERE
+    field_class = 'title' AND name = 'proper' ;
+
+UPDATE config.metabib_field
+SET
+    xpath = $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='alternative-nfi')]$$,
+    browse_sort_xpath = $$*[local-name() != "nonSort"]$$,
+    browse_xpath = NULL
+WHERE
+    field_class = 'title' AND name = 'alternative' ;
+
+UPDATE config.metabib_field
+SET
+    xpath = $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='uniform-nfi')]$$,
+    browse_sort_xpath = $$*[local-name() != "nonSort"]$$,
+    browse_xpath = NULL
+WHERE
+    field_class = 'title' AND name = 'uniform' ;
+
+UPDATE config.metabib_field
+SET
+    xpath = $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='translated-nfi')]$$,
+    browse_sort_xpath = $$*[local-name() != "nonSort"]$$,
+    browse_xpath = NULL
+WHERE
+    field_class = 'title' AND name = 'translated' ;
+
+-- This keeps extra terms like "creator" out of browse headings.
+UPDATE config.metabib_field
+    SET browse_xpath = $$//*[local-name()='namePart']$$     -- vim */
+    WHERE
+        browse_field AND
+        browse_xpath IS NULL AND
+        field_class = 'author';
+
 COMMIT;
+
+\qecho This is a browse-only reingest of your bib records. It may take a while.
+\qecho You may cancel now without losing the effect of the rest of the
+\qecho upgrade script, and arrange the reingest later.
+\qecho .
+SELECT metabib.reingest_metabib_field_entries(id, TRUE, FALSE, TRUE)
+    FROM biblio.record_entry;
diff --git a/Open-ILS/src/templates/opac/advanced.tt2 b/Open-ILS/src/templates/opac/advanced.tt2
index 220c56f..38f01fb 100644
--- a/Open-ILS/src/templates/opac/advanced.tt2
+++ b/Open-ILS/src/templates/opac/advanced.tt2
@@ -8,9 +8,11 @@
     <div id="search-wrapper">
         <div id="search-box">
             <span class="search_catalog_lbl">[% l('Search the Catalog') %]</span>
-            <a href="[% mkurl(ctx.opac_root _ '/home') %]"
-                id="home_adv_search_link"><span
-                class="adv_search_font">[%l('Basic Search')%]</span></a>
+            <span><a href="[% mkurl(ctx.opac_root _ '/home') %]"
+                    id="home_adv_search_link">[%l('Basic Search')%]</a></span>
+
+            <span><a href="[% mkurl(ctx.opac_root _ '/browse') %]">[%
+                    l('Browse the Catalog')%]</a></span>
         </div>
         <div id="adv_search_parent">
             <div id="adv_search_tabs">
diff --git a/Open-ILS/src/templates/opac/browse.tt2 b/Open-ILS/src/templates/opac/browse.tt2
new file mode 100644
index 0000000..35a9d5a
--- /dev/null
+++ b/Open-ILS/src/templates/opac/browse.tt2
@@ -0,0 +1,174 @@
+[%- # This is the bib and authority combined record browser.
+
+    PROCESS "opac/parts/header.tt2";
+    PROCESS "opac/parts/misc_util.tt2";
+    PROCESS "opac/parts/org_selector.tt2";
+    WRAPPER "opac/parts/base.tt2";
+    INCLUDE "opac/parts/topnav.tt2";
+
+    ctx.page_title = l("Browse the Catalog");
+    blimit = CGI.param('blimit') || 10;
+    boffset = CGI.param('boffset') || 0;
+
+    depart_list = ['blimit', 'bterm', 'boffset', 'bpivot', 'bback'];
+%]
+
+    <div id="search-wrapper">
+        [%# XXX TODO Give searchbar.tt2 more smarts so we can just do:
+          # INCLUDE "opac/parts/searchbar.tt2" %]
+        <div id="search-box">
+            <span class="search_catalog_lbl"><a href="[% mkurl(ctx.opac_root _ '/home', {}, depart_list) %]">[% l('Search the Catalog') %]</a></span>
+            <span><a href="[% mkurl(ctx.opac_root _ '/advanced', {}, depart_list) %]"
+                    id="home_adv_search_link">[%l('Advanced Search')%]</a></span>
+            <span>[% l('Browse the Catalog') %]</span>
+        </div>
+    </div>
+    <div id="content-wrapper">
+        <div id="main-content">
+            <div id="browse-the-catalog">
+                <div id="browse-controls">
+                    <form method="get">
+                        <input type="hidden" name="blimit"
+                            value="[% blimit %]" />
+
+                        [% control_qtype = INCLUDE "opac/parts/qtype_selector.tt2"
+                            id="browse-search-class" browse_only=1 %]
+
+                        [% control_bterm = BLOCK %]<input type="text" name="bterm" id="browse-term"
+                            value="[% CGI.param('bterm') | html %]" />[% END %]
+                        [% control_locg = INCLUDE build_org_selector id='browse-context'
+                            show_loc_groups=1
+                            arialabel=l('Select holding library') %]
+                        [% l('Browse by [_1] for [_2] held under [_3]', control_qtype, control_bterm, control_locg) %]
+
+                        <input type="submit" value="[% l('Go') %]" />
+                    </form>
+                </div>
+
+                [% BLOCK browse_pager %]
+                <div class="browse-pager">
+                    [% IF ctx.more_back %]
+                    <a class="opac-button" href="[% mkurl('', {bpivot => ctx.back_pivot, bback => 1}) %]">&larr; [%l ('Back') %]</a>
+                    [% END %]
+                    [% IF browse.english_pager; # XXX how to apply i18n here?
+                        current_qtype = CGI.param('qtype') || 'title' %]
+                    <span class="browse-shortcuts">
+                        <a href="[% mkurl('', {qtype => current_qtype, bterm => '0'}, ['boffset','bpivot','bback']) %]">0-9</a>
+                        [% FOR letter IN ['A'..'Z'] %]
+                            <a href="[% mkurl('', {qtype => current_qtype, bterm => letter}, ['boffset','bpivot','bback']) %]">[% letter %]</a>
+                        [% END %]
+                    </span>
+                    [% END %]
+
+                    [% IF ctx.more_forward %]
+                    <a class="opac-button" href="[% mkurl('', {bpivot => ctx.forward_pivot}, ['bback']) %]">[%l ('Forward') %] &rarr;</a>
+                    [% END %]
+                </div>
+                [% END %]
+
+                [% PROCESS browse_pager %]
+
+                <div id="browse-results">
+                [% IF ctx.browse_error %]
+                    <span class="browse-error">
+                        [% l("An error occurred browsing records. " _
+                        "Please try again in a moment or report the issue " _
+                        "to library staff.") %]
+                    </span>
+                [% ELSE %]
+                    [% IF ctx.browse_leading_article_warning %]
+                    <div class="browse-leading-article-warning">
+                            [% l("Your browse term seems to begin with an article. You might get better results by omitting the article.") %]
+                    </div>
+                    [% END %]
+                    <ul class="browse-result-list">
+                    [% FOR result IN ctx.browse_results %]
+                        <li class="browse-result">
+                            <span class="browse-result-value">
+                                <a href="[% mkurl(
+                                    ctx.opac_root _ '/results', {
+                                        'fi:has_browse_entry' => (result.browse_entry _ ',' _ result.fields)
+                                    }) %]">[% result.value | html %]</a>
+                            </span>
+                            <span class="browse-result-sources">([%
+                                IF result.accurate == 'f';
+                                    l("At least"); " ";
+                                END;
+                                result.sources %])</span>
+                            [% IF result.authorities.size %]
+                            <ul class="browse-result-authority-headings">
+                                [% FOR a IN result.authorities;
+                                    PROCESS authority_notes authority=a;
+
+                                    # Other than displaying public general
+                                    # notes, we can go no further sans
+                                    # control_set.
+                                    NEXT UNLESS a.control_set;
+
+                                    # get_authority_fields is fast and cache-y.
+                                    acs = ctx.get_authority_fields(a.control_set);
+                                    FOR field_group IN a.headings;
+                                        field_id = field_group.keys.0;
+                                        field = acs.$field_id;
+                                        headings = field_group.values.0;
+                                        FOR h IN headings;
+                                            # We could display headings without
+                                            # links here when h.target is
+                                            # undef, if we wanted to, but note
+                                            # that h.target_count is only
+                                            # defined when h.target is.
+
+                                            IF h.target %]
+                                            <li><span class="browse-result-authority-field-name">[% field.name %]</span>
+                                            <a href="[% mkurl(ctx.opac_root _ '/results', {query => 'identifier|authority_id[' _ h.target _ ']'}) %]">[% h.heading | html %]</a>
+                                            <span class="browse-result-authority-bib-links">([% h.target_count %])</span>
+                                            </li>
+                                            [% END %]
+                                        [% END %]
+                                    [% END %]
+                                [% END %]
+                            </ul>
+                            [% END %]
+                        </li>
+                    [% END %]
+                    </ul>
+                [% END %]
+                </div>
+
+                [% PROCESS browse_pager %]
+            </div>
+
+            <div class="common-full-pad"></div>	
+        </div>
+    </div>
+
+    [% BLOCK authority_notes;
+        # Displays public general notes (sometimes called "scope notes" ?)
+        FOR note IN authority.notes %]
+            <div class="browse-public-general-note">
+                <span class="browse-public-general-note-label">
+                    [% l("Note:") %]
+                </span>
+                <span class="browse-public-general-note-body">
+            [% FOR piece IN note;
+                IF piece.heading;
+                    mkurl_args = {bterm => piece.bterm};
+                    IF piece.org_id;
+                        mkurl_args.locg = piece.org_id;
+                    END;
+                %]
+                <a href="[% mkurl('', mkurl_args, ['boffset','bpivot','bback']) %]">[% piece.heading | html %]</a>
+                [% ELSIF piece.institution %]
+                <span class="browse-public-general-note-institution">
+                    [% piece.institution | html %]
+                </span>
+                [% ELSE %]
+                    [% piece | html %]
+                [% END;
+            END %]
+                </span>
+            </div>
+        [% END;
+    END;    # end of BLOCK authority_notes %]
+
+[% END %]
diff --git a/Open-ILS/src/templates/opac/css/style.css.tt2 b/Open-ILS/src/templates/opac/css/style.css.tt2
index 00d90d9..3efc864 100644
--- a/Open-ILS/src/templates/opac/css/style.css.tt2
+++ b/Open-ILS/src/templates/opac/css/style.css.tt2
@@ -877,10 +877,6 @@ table.acct_notes th {
     padding-right: 5px;
 }
 
-.adv_search_font {
-    font-size: [% css_fonts.size_smaller %];
-}
-
 .search_catalog_lbl {
     font-size: [% css_fonts.size_bigger %];
 }
@@ -1536,3 +1532,42 @@ a.preflib_change {
     color: [% css_colors.text_invert %];
     text-align: center;
 }
+
+#search-box > span {
+    margin: 0 1em;
+}
+.browse-error {
+    font-weight: bold;
+    font-color: #c00;
+}
+.browse-result-sources, .browse-result-authority-bib-links {
+    margin-left: 1em;
+}
+.browse-pager {
+    margin: 2ex 0;
+}
+.browse-result-list {
+    list-style-type: square;
+}
+.browse-shortcuts {
+    font-size: 120%;
+}
+.browse-result-authority-field-name {
+    font-style: italic;
+    margin-right: 1em;
+}
+.browse-leading-article-warning {
+    font-style: italic;
+    font-size: 110%;
+}
+.browse-public-general-note {
+    font-size: 110%;
+}
+.browse-public-general-note-label { }
+.browse-public-general-note-institution {
+    font-style: normal;
+    font-weight: bold;
+}
+.browse-public-general-note-body {
+    font-style: italic;
+}
diff --git a/Open-ILS/src/templates/opac/parts/config.tt2 b/Open-ILS/src/templates/opac/parts/config.tt2
index 1ba05cc..a0be85b 100644
--- a/Open-ILS/src/templates/opac/parts/config.tt2
+++ b/Open-ILS/src/templates/opac/parts/config.tt2
@@ -150,8 +150,17 @@ search.basic_config = {
 ctx.google_books_preview = 0;
 
 ##############################################################################
+
 # Set a maintenance message to display in the catalogue
 #
 # ctx.maintenance_message = "The system will not be available February 29, 2104.";
 
+# Browse settings
+# Set to 1 or 'true' to enable.  This controls whether or not the
+# "0-9 A B C D ..." links appear on the browse page.  We don't yet have a
+# serviceable way to internationalize these links, so sites must choose to
+# turn on this feature.
+
+browse.english_pager = 0;
+
 %]
diff --git a/Open-ILS/src/templates/opac/parts/qtype_selector.tt2 b/Open-ILS/src/templates/opac/parts/qtype_selector.tt2
index eda10a3..30edbc6 100644
--- a/Open-ILS/src/templates/opac/parts/qtype_selector.tt2
+++ b/Open-ILS/src/templates/opac/parts/qtype_selector.tt2
@@ -1,16 +1,17 @@
 [%  query_types = [
     {value => "keyword", label => l("Keyword")},
-    {value => "title", label => l("Title")},
+    {value => "title", label => l("Title"), browse => 1},
     {value => "jtitle", label => l("Journal Title")},
-    {value => "author", label => l("Author")},
-    {value => "subject", label => l("Subject")},
-    {value => "series", label => l("Series")},
+    {value => "author", label => l("Author"), browse => 1},
+    {value => "subject", label => l("Subject"), browse => 1},
+    {value => "series", label => l("Series"), browse => 1},
     {value => "id|bibcn", label => l("Bib Call Number")}
 ] %]
-<select name="qtype"[% IF id; ' id="'; id ; '"' ; END -%]
+<select name="[% name || 'qtype' %]"[% IF id; ' id="'; id ; '"' ; END -%]
     aria-label="[% l('Select query type:') %]">
     [%  query_type = query_type || CGI.param('qtype') || search.default_qtypes.0;
-        FOR qt IN query_types -%]
+      FOR qt IN query_types;
+        NEXT IF browse_only AND NOT qt.browse -%]
     <option value='[% qt.value | html %]'[%
         query_type == qt.value ? ' selected="selected"' : ''
     %]>[% qt.label | html %]</option>
diff --git a/Open-ILS/src/templates/opac/parts/searchbar.tt2 b/Open-ILS/src/templates/opac/parts/searchbar.tt2
index 0359c83..84d6008 100644
--- a/Open-ILS/src/templates/opac/parts/searchbar.tt2
+++ b/Open-ILS/src/templates/opac/parts/searchbar.tt2
@@ -1,13 +1,13 @@
 [% PROCESS "opac/parts/org_selector.tt2" %]
-<div id="search-box">    
+<div id="search-wrapper">
     [% UNLESS took_care_of_form -%]
     <form action="[% ctx.opac_root %]/results" method="get">
     [%- END %]
-    <div>
+    <div id="search-box">
         <span class="search_catalog_lbl">[% l('Search the Catalog') %]</span>
         <a href="[% mkurl(ctx.opac_root _ '/advanced') %]"
-            id="home_adv_search_link"><span
-            class="adv_search_font">[% l('Advanced Search') %]</span></a>
+            id="home_adv_search_link">[% l('Advanced Search') %]</a>
+        <span class="browse_the_catalog_lbl"><a href="[% mkurl(ctx.opac_root _ '/browse', {}, ['fi:has_browse_entry']) %]">[% l('Browse the Catalog') %]</a></span>
     </div>
     <div class="searchbar">[%- l('Search ');
         IF search.basic_config.type == 'attr';
diff --git a/Open-ILS/web/css/skin/default/opac/semiauto.css b/Open-ILS/web/css/skin/default/opac/semiauto.css
index 88f3284..dfe8a6f 100644
--- a/Open-ILS/web/css/skin/default/opac/semiauto.css
+++ b/Open-ILS/web/css/skin/default/opac/semiauto.css
@@ -19,7 +19,6 @@
 #new_cat_link_holder a { display: block; width: 675px; height: 213px; }
 .pos-rel { position: relative; }
 #search-box table { position: relative; left: -10px; }
-#home_adv_search_link { position: relative; top: -1px; left: 10px; }
 #util_back_btn { position: relative; top: 1px; left: 10px; }
 #util_help_btn { position: relative; top: 2px; left: 40px; }
 #util_forw_btn { position: relative; top: 2px; left: 50px; }
diff --git a/docs/RELEASE_NOTES_NEXT/OPAC/BibAuthBrowse.txt b/docs/RELEASE_NOTES_NEXT/OPAC/BibAuthBrowse.txt
new file mode 100644
index 0000000..279bfbd
--- /dev/null
+++ b/docs/RELEASE_NOTES_NEXT/OPAC/BibAuthBrowse.txt
@@ -0,0 +1,45 @@
+Bib record browser with linked authorities
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+This feature provides a patron-oriented OPAC interface for browsing
+bibliographic records.
+
+Users choose to browse by Author, Title, Subject, or Series. They then
+enter a browse term, and the nearest match from a left-anchored search
+on the headings extracted for browse purposes will be displayed in a
+typical backwards/forwards paging display. Headings link to search
+results pages showing the related records. If the browse heading is
+linked to any authority records, and if any *other* authority records
+point to those with "See also" or other non-main entry headings, those
+alternative headings are displayed a linked to a search results page
+showing related bib records related to the alternate heading.
+
+The counts of holdings displayed next to headings from bibliographic
+records are subject to the same visiibility tests as search. This means
+that the org unit (and copy location group) dropdown on the browse
+interface affects counds, and it further means that whether or not
+you're looking at the browse interface through the staff client makes a
+difference.
+
+Configuration considerations for site administrators
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+There are two off-by-default features that site administrators may wish
+to enable.
+
+  * Quick paging links (English): By changing the
+    ''browse.english_pager'' setting to 1 in the
+    ''opac/parts/config.tt2'' file for a site's active OPAC templates,
+    you can make shortcut browsing links ''0-9 A B C D ...'' appear
+    between the Back and Forward buttons on the browse page. I haven't
+    figured out how to make this feature internationalizable, so it's
+    off by default.  You can turn it on if it works for your language,
+    or have a look at improving it if it doesn't.
+
+  * There is a global flag by the name
+    ''opac.browse.warnable_regexp_per_class'' to control what leading
+    articles in users' entered browse terms trigger a warning about how
+    it might be better to search for "Rolling Stones" instead of "The
+    Rolling Stones" (or whatever). This is off by default, but can be
+    enabled if it suits your catalog, and can even be customized per
+    search class (author, title, series, subject).
+

commit d2f4cac923668ff05854ffc9720cafe514b9b71c
Author: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
Date:   Thu Mar 28 18:02:32 2013 -0400

    Link browse entries to authority record when possible
    
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>

diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql
index 68d44fd..1cd740d 100644
--- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql
+++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql
@@ -390,7 +390,8 @@ CREATE TYPE metabib.field_entry_template AS (
         search_field    BOOL,
         browse_field   BOOL,
         source          BIGINT,
-        value           TEXT
+        value           TEXT,
+        authority       BIGINT
 );
 
 
@@ -408,6 +409,8 @@ DECLARE
     raw_text    TEXT;
     curr_text   TEXT;
     joiner      TEXT := default_joiner; -- XXX will index defs supply a joiner?
+    authority_text TEXT;
+    authority_link BIGINT;
     output_row  metabib.field_entry_template%ROWTYPE;
 BEGIN
 
@@ -481,6 +484,25 @@ BEGIN
                 output_row.source = rid;
                 output_row.value = BTRIM(REGEXP_REPLACE(browse_text, E'\\s+', ' ', 'g'));
 
+                IF idx.authority_xpath IS NOT NULL AND idx.authority_xpath <> '' THEN
+                    authority_text := oils_xpath_string(
+                        idx.authority_xpath, xml_node, joiner,
+                        ARRAY[
+                            ARRAY[xfrm.prefix, xfrm.namespace_uri],
+                            ARRAY['xlink','http://www.w3.org/1999/xlink']
+                        ]
+                    );
+
+                    IF authority_text ~ '^\d+$' THEN
+                        authority_link := authority_text::BIGINT;
+                        PERFORM * FROM authority.record_entry WHERE id = authority_link;
+                        IF FOUND THEN
+                            output_row.authority := authority_link;
+                        END IF;
+                    END IF;
+
+                END IF;
+
                 output_row.browse_field = TRUE;
                 RETURN NEXT output_row;
                 output_row.browse_field = FALSE;
@@ -637,8 +659,8 @@ BEGIN
                 mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
             END IF;
 
-            INSERT INTO metabib.browse_entry_def_map (entry, def, source)
-                VALUES (mbe_id, ind_data.field, ind_data.source);
+            INSERT INTO metabib.browse_entry_def_map (entry, def, source, authority)
+                VALUES (mbe_id, ind_data.field, ind_data.source, ind_data.authority);
         END IF;
 
         -- Avoid inserting duplicate rows, but retain granularity of being
diff --git a/Open-ILS/src/sql/Pg/953.data.MODS32-xsl.sql b/Open-ILS/src/sql/Pg/953.data.MODS32-xsl.sql
index e775b66..542440a 100644
--- a/Open-ILS/src/sql/Pg/953.data.MODS32-xsl.sql
+++ b/Open-ILS/src/sql/Pg/953.data.MODS32-xsl.sql
@@ -228,6 +228,7 @@ Added Log Comment
 		<xsl:for-each select="marc:datafield[@tag='130']|marc:datafield[@tag='240']|marc:datafield[@tag='730'][@ind2!='2']">
 			<titleInfo type="uniform">
 				<title>
+					<xsl:call-template name="uri" />
 					<xsl:variable name="str">
 						<xsl:for-each select="marc:subfield">
 							<xsl:if test="(contains('adfklmor', at code) and (not(../marc:subfield[@code='n' or @code='p']) or (following-sibling::marc:subfield[@code='n' or @code='p'])))">
@@ -261,6 +262,7 @@ Added Log Comment
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='100']">
 			<name type="personal">
+				<xsl:call-template name="uri" />
 				<xsl:call-template name="nameABCDQ"/>
 				<xsl:call-template name="affiliation"/>
 				<role>
@@ -271,6 +273,7 @@ Added Log Comment
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='110']">
 			<name type="corporate">
+				<xsl:call-template name="uri" />
 				<xsl:call-template name="nameABCDN"/>
 				<role>
 					<roleTerm authority="marcrelator" type="text">creator</roleTerm>
@@ -280,6 +283,7 @@ Added Log Comment
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='111']">
 			<name type="conference">
+				<xsl:call-template name="uri" />
 				<xsl:call-template name="nameACDEQ"/>
 				<role>
 					<roleTerm authority="marcrelator" type="text">creator</roleTerm>
@@ -289,6 +293,7 @@ Added Log Comment
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='700'][not(marc:subfield[@code='t'])]">
 			<name type="personal">
+				<xsl:call-template name="uri" />
 				<xsl:call-template name="nameABCDQ"/>
 				<xsl:call-template name="affiliation"/>
 				<xsl:call-template name="role"/>
@@ -296,12 +301,14 @@ Added Log Comment
 		</xsl:for-each>
 		<xsl:for-each select="marc:datafield[@tag='710'][not(marc:subfield[@code='t'])]">
 			<name type="corporate">
+				<xsl:call-template name="uri" />
 				<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="uri" />
 				<xsl:call-template name="nameACDEQ"/>
 				<xsl:call-template name="role"/>
 			</name>
@@ -2195,6 +2202,20 @@ Added Log Comment
 				<xsl:value-of select="."></xsl:value-of>
 			</xsl:attribute>
 		</xsl:for-each>
+		<xsl:for-each select="marc:subfield[@code='0']">
+			<xsl:choose>
+				<xsl:when test="contains(text(), ')')">
+					<xsl:attribute name="xlink:href">
+						<xsl:value-of select="substring-after(text(), ')')"></xsl:value-of>
+					</xsl:attribute>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:attribute name="xlink:href">
+						<xsl:value-of select="."></xsl:value-of>
+					</xsl:attribute>
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:for-each>
 	</xsl:template>
 	<xsl:template name="role">
 		<xsl:for-each select="marc:subfield[@code='e']">
@@ -2733,6 +2754,7 @@ Added Log Comment
 					<xsl:value-of select="marc:subfield[@code=2]"></xsl:value-of>
 				</xsl:attribute>
 			</xsl:if>
+			<xsl:call-template name="uri" />
 			<occupation>
 				<xsl:call-template name="chopPunctuation">
 					<xsl:with-param name="chopString">
diff --git a/Open-ILS/src/sql/Pg/954.data.MODS33-xsl.sql b/Open-ILS/src/sql/Pg/954.data.MODS33-xsl.sql
index 5e3adf1..b3670ff 100644
--- a/Open-ILS/src/sql/Pg/954.data.MODS33-xsl.sql
+++ b/Open-ILS/src/sql/Pg/954.data.MODS33-xsl.sql
@@ -17,8 +17,8 @@ UPDATE config.xml_transform SET xslt=$$<xsl:stylesheet xmlns="http://www.loc.gov
 
 	<xsl:variable name="hex">0123456789ABCDEF</xsl:variable>
 
+    <!-- Evergreen specific: revert Revision 1.23, so we can have those authority xlink attributes back. -->
 
-	
 	<!--MARC21slim2MODS3-3.xsl
 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
@@ -213,9 +213,7 @@ Revision 1.2 - Added Log Comment  2003/03/24 19:37:42  ckeith
 			select="marc:datafield[@tag='130']|marc:datafield[@tag='240']|marc:datafield[@tag='730'][@ind2!='2']">
 			<titleInfo type="uniform">
 				<title>
-					<!-- deleted uri for subfield 0
 						<xsl:call-template name="uri"/>
-					-->
 
 					<xsl:variable name="str">
 						<xsl:for-each select="marc:subfield">
@@ -252,9 +250,7 @@ Revision 1.2 - Added Log Comment  2003/03/24 19:37:42  ckeith
 		<xsl:for-each select="marc:datafield[@tag='100']">
 			<name type="personal">
 
-				<!-- deleted uri for subfield 0
 				<xsl:call-template name="uri"/>
-				-->
 
 				<xsl:call-template name="nameABCDQ"/>
 				<xsl:call-template name="affiliation"/>
@@ -267,9 +263,7 @@ Revision 1.2 - Added Log Comment  2003/03/24 19:37:42  ckeith
 		<xsl:for-each select="marc:datafield[@tag='110']">
 			<name type="corporate">
 
-				<!-- deleted uri for subfield 0
 					<xsl:call-template name="uri"/>
-				-->
 
 				<xsl:call-template name="nameABCDN"/>
 				<role>
@@ -281,9 +275,7 @@ Revision 1.2 - Added Log Comment  2003/03/24 19:37:42  ckeith
 		<xsl:for-each select="marc:datafield[@tag='111']">
 			<name type="conference">
 
-				<!-- deleted uri for subfield 0
 					<xsl:call-template name="uri"/>
-				-->
 
 				<xsl:call-template name="nameACDEQ"/>
 				<role>
@@ -295,9 +287,7 @@ Revision 1.2 - Added Log Comment  2003/03/24 19:37:42  ckeith
 		<xsl:for-each select="marc:datafield[@tag='700'][not(marc:subfield[@code='t'])]">
 			<name type="personal">
 
-				<!-- deleted uri for subfield 0
 					<xsl:call-template name="uri"/>
-				-->
 
 				<xsl:call-template name="nameABCDQ"/>
 				<xsl:call-template name="affiliation"/>
@@ -307,9 +297,7 @@ Revision 1.2 - Added Log Comment  2003/03/24 19:37:42  ckeith
 		<xsl:for-each select="marc:datafield[@tag='710'][not(marc:subfield[@code='t'])]">
 			<name type="corporate">
 
-				<!-- deleted uri for subfield 0
 					<xsl:call-template name="uri"/>
-				-->
 
 				<xsl:call-template name="nameABCDN"/>
 				<xsl:call-template name="role"/>
@@ -318,9 +306,7 @@ Revision 1.2 - Added Log Comment  2003/03/24 19:37:42  ckeith
 		<xsl:for-each select="marc:datafield[@tag='711'][not(marc:subfield[@code='t'])]">
 			<name type="conference">
 
-				<!-- deleted uri for subfield 0
 					<xsl:call-template name="uri"/>
-				-->
 
 				<xsl:call-template name="nameACDEQ"/>
 				<xsl:call-template name="role"/>
@@ -2441,11 +2427,25 @@ Revision 1.2 - Added Log Comment  2003/03/24 19:37:42  ckeith
 		</xsl:for-each>
 	</xsl:template>
 	<xsl:template name="uri">
-		<xsl:for-each select="marc:subfield[@code='u']|marc:subfield[@code='0']">
+		<xsl:for-each select="marc:subfield[@code='u']">
 			<xsl:attribute name="xlink:href">
 				<xsl:value-of select="."/>
 			</xsl:attribute>
 		</xsl:for-each>
+		<xsl:for-each select="marc:subfield[@code='0']">
+			<xsl:choose>
+				<xsl:when test="contains(text(), ')')">
+					<xsl:attribute name="xlink:href">
+						<xsl:value-of select="substring-after(text(), ')')"></xsl:value-of>
+					</xsl:attribute>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:attribute name="xlink:href">
+						<xsl:value-of select="."></xsl:value-of>
+					</xsl:attribute>
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:for-each>
 	</xsl:template>
 	<xsl:template name="role">
 		<xsl:for-each select="marc:subfield[@code='e']">
diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
new file mode 100644
index 0000000..ba30e46
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
@@ -0,0 +1,6885 @@
+BEGIN;
+
+-- check whether patch can be applied
+-- SELECT evergreen.upgrade_deps_block_check('YYYY', :eg_version);
+
+ALTER TABLE metabib.browse_entry_def_map
+    ADD COLUMN authority BIGINT REFERENCES authority.record_entry (id)
+        ON DELETE SET NULL;
+
+ALTER TABLE config.metabib_field ADD COLUMN authority_xpath TEXT;
+
+UPDATE config.metabib_field
+    SET authority_xpath = '//@xlink:href'
+    WHERE
+        format = 'mods32' AND
+        field_class IN ('subject','series','title','author') AND
+        browse_field IS TRUE;
+
+ALTER TYPE metabib.field_entry_template ADD ATTRIBUTE authority BIGINT;
+
+
+CREATE OR REPLACE FUNCTION metabib.reingest_metabib_field_entries( bib_id BIGINT, skip_facet BOOL DEFAULT FALSE, skip_browse BOOL DEFAULT FALSE, skip_search BOOL DEFAULT FALSE ) RETURNS VOID AS $func$
+DECLARE
+    fclass          RECORD;
+    ind_data        metabib.field_entry_template%ROWTYPE;
+    mbe_row         metabib.browse_entry%ROWTYPE;
+    mbe_id          BIGINT;
+    b_skip_facet    BOOL;
+    b_skip_browse   BOOL;
+    b_skip_search   BOOL;
+BEGIN
+
+    SELECT COALESCE(NULLIF(skip_facet, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_facet_indexing' AND enabled)) INTO b_skip_facet;
+    SELECT COALESCE(NULLIF(skip_browse, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_browse_indexing' AND enabled)) INTO b_skip_browse;
+    SELECT COALESCE(NULLIF(skip_search, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_search_indexing' AND enabled)) INTO b_skip_search;
+
+    PERFORM * FROM config.internal_flag WHERE name = 'ingest.assume_inserts_only' AND enabled;
+    IF NOT FOUND THEN
+        IF NOT b_skip_search THEN
+            FOR fclass IN SELECT * FROM config.metabib_class LOOP
+                -- RAISE NOTICE 'Emptying out %', fclass.name;
+                EXECUTE $$DELETE FROM metabib.$$ || fclass.name || $$_field_entry WHERE source = $$ || bib_id;
+            END LOOP;
+        END IF;
+        IF NOT b_skip_facet THEN
+            DELETE FROM metabib.facet_entry WHERE source = bib_id;
+        END IF;
+        IF NOT b_skip_browse THEN
+            DELETE FROM metabib.browse_entry_def_map WHERE source = bib_id;
+        END IF;
+    END IF;
+
+    FOR ind_data IN SELECT * FROM biblio.extract_metabib_field_entry( bib_id ) LOOP
+        IF ind_data.field < 0 THEN
+            ind_data.field = -1 * ind_data.field;
+        END IF;
+
+        IF ind_data.facet_field AND NOT b_skip_facet THEN
+            INSERT INTO metabib.facet_entry (field, source, value)
+                VALUES (ind_data.field, ind_data.source, ind_data.value);
+        END IF;
+
+        IF ind_data.browse_field AND NOT b_skip_browse THEN
+            -- A caveat about this SELECT: this should take care of replacing
+            -- old mbe rows when data changes, but not if normalization (by
+            -- which I mean specifically the output of
+            -- evergreen.oils_tsearch2()) changes.  It may or may not be
+            -- expensive to add a comparison of index_vector to index_vector
+            -- to the WHERE clause below.
+            SELECT INTO mbe_row * FROM metabib.browse_entry WHERE value = ind_data.value;
+            IF FOUND THEN
+                mbe_id := mbe_row.id;
+            ELSE
+                INSERT INTO metabib.browse_entry (value) VALUES
+                    (metabib.browse_normalize(ind_data.value, ind_data.field));
+                mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
+            END IF;
+
+            INSERT INTO metabib.browse_entry_def_map (entry, def, source, authority)
+                VALUES (mbe_id, ind_data.field, ind_data.source, ind_data.authority);
+        END IF;
+
+        IF ind_data.search_field AND NOT b_skip_search THEN
+            EXECUTE $$
+                INSERT INTO metabib.$$ || ind_data.field_class || $$_field_entry (field, source, value)
+                    VALUES ($$ ||
+                        quote_literal(ind_data.field) || $$, $$ ||
+                        quote_literal(ind_data.source) || $$, $$ ||
+                        quote_literal(ind_data.value) ||
+                    $$);$$;
+        END IF;
+
+    END LOOP;
+
+    IF NOT b_skip_search THEN
+        PERFORM metabib.update_combined_index_vectors(bib_id);
+    END IF;
+
+    RETURN;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+
+CREATE OR REPLACE FUNCTION biblio.extract_metabib_field_entry ( rid BIGINT, default_joiner TEXT ) RETURNS SETOF metabib.field_entry_template AS $func$
+DECLARE
+    bib     biblio.record_entry%ROWTYPE;
+    idx     config.metabib_field%ROWTYPE;
+    xfrm        config.xml_transform%ROWTYPE;
+    prev_xfrm   TEXT;
+    transformed_xml TEXT;
+    xml_node    TEXT;
+    xml_node_list   TEXT[];
+    facet_text  TEXT;
+    browse_text TEXT;
+    raw_text    TEXT;
+    curr_text   TEXT;
+    joiner      TEXT := default_joiner; -- XXX will index defs supply a joiner?
+    authority_text TEXT;
+    authority_link BIGINT;
+    output_row  metabib.field_entry_template%ROWTYPE;
+BEGIN
+
+    -- Get the record
+    SELECT INTO bib * FROM biblio.record_entry WHERE id = rid;
+
+    -- Loop over the indexing entries
+    FOR idx IN SELECT * FROM config.metabib_field ORDER BY format LOOP
+
+        SELECT INTO xfrm * from config.xml_transform WHERE name = idx.format;
+
+        -- See if we can skip the XSLT ... it's expensive
+        IF prev_xfrm IS NULL OR prev_xfrm <> xfrm.name THEN
+            -- Can't skip the transform
+            IF xfrm.xslt <> '---' THEN
+                transformed_xml := oils_xslt_process(bib.marc,xfrm.xslt);
+            ELSE
+                transformed_xml := bib.marc;
+            END IF;
+
+            prev_xfrm := xfrm.name;
+        END IF;
+
+        xml_node_list := oils_xpath( idx.xpath, transformed_xml, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
+
+        raw_text := NULL;
+        FOR xml_node IN SELECT x FROM unnest(xml_node_list) AS x LOOP
+            CONTINUE WHEN xml_node !~ E'^\\s*<';
+
+            curr_text := ARRAY_TO_STRING(
+                oils_xpath( '//text()',
+                    REGEXP_REPLACE( -- This escapes all &s not followed by "amp;".  Data ise returned from oils_xpath (above) in UTF-8, not entity encoded
+                        REGEXP_REPLACE( -- This escapes embeded <s
+                            xml_node,
+                            $re$(>[^<]+)(<)([^>]+<)$re$,
+                            E'\\1&lt;\\3',
+                            'g'
+                        ),
+                        '&(?!amp;)',
+                        '&amp;',
+                        'g'
+                    )
+                ),
+                ' '
+            );
+
+            CONTINUE WHEN curr_text IS NULL OR curr_text = '';
+
+            IF raw_text IS NOT NULL THEN
+                raw_text := raw_text || joiner;
+            END IF;
+
+            raw_text := COALESCE(raw_text,'') || curr_text;
+
+            -- autosuggest/metabib.browse_entry
+            IF idx.browse_field THEN
+
+                IF idx.browse_xpath IS NOT NULL AND idx.browse_xpath <> '' THEN
+                    browse_text := oils_xpath_string( idx.browse_xpath, xml_node, joiner, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
+                ELSE
+                    browse_text := curr_text;
+                END IF;
+
+                output_row.field_class = idx.field_class;
+                output_row.field = idx.id;
+                output_row.source = rid;
+                output_row.value = BTRIM(REGEXP_REPLACE(browse_text, E'\\s+', ' ', 'g'));
+
+                IF idx.authority_xpath IS NOT NULL AND idx.authority_xpath <> '' THEN
+                    authority_text := oils_xpath_string(
+                        idx.authority_xpath, xml_node, joiner,
+                        ARRAY[
+                            ARRAY[xfrm.prefix, xfrm.namespace_uri],
+                            ARRAY['xlink','http://www.w3.org/1999/xlink']
+                        ]
+                    );
+
+                    IF authority_text ~ '^\d+$' THEN
+                        authority_link := authority_text::BIGINT;
+                        PERFORM * FROM authority.record_entry WHERE id = authority_link;
+                        IF FOUND THEN
+                            output_row.authority := authority_link;
+                        END IF;
+                    END IF;
+
+                END IF;
+
+                output_row.browse_field = TRUE;
+                RETURN NEXT output_row;
+                output_row.browse_field = FALSE;
+            END IF;
+
+            -- insert raw node text for faceting
+            IF idx.facet_field THEN
+
+                IF idx.facet_xpath IS NOT NULL AND idx.facet_xpath <> '' THEN
+                    facet_text := oils_xpath_string( idx.facet_xpath, xml_node, joiner, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
+                ELSE
+                    facet_text := curr_text;
+                END IF;
+
+                output_row.field_class = idx.field_class;
+                output_row.field = -1 * idx.id;
+                output_row.source = rid;
+                output_row.value = BTRIM(REGEXP_REPLACE(facet_text, E'\\s+', ' ', 'g'));
+
+                output_row.facet_field = TRUE;
+                RETURN NEXT output_row;
+                output_row.facet_field = FALSE;
+            END IF;
+
+        END LOOP;
+
+        CONTINUE WHEN raw_text IS NULL OR raw_text = '';
+
+        -- insert combined node text for searching
+        IF idx.search_field THEN
+            output_row.field_class = idx.field_class;
+            output_row.field = idx.id;
+            output_row.source = rid;
+            output_row.value = BTRIM(REGEXP_REPLACE(raw_text, E'\\s+', ' ', 'g'));
+
+            output_row.search_field = TRUE;
+            RETURN NEXT output_row;
+        END IF;
+
+    END LOOP;
+
+END;
+
+$func$ LANGUAGE PLPGSQL;
+
+
+-- 953.data.MODS32-xsl.sql
+UPDATE config.xml_transform SET xslt=$$<?xml version="1.0" encoding="UTF-8"?>
+<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:output encoding="UTF-8" indent="yes" method="xml"/>
+<!--
+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.9 subfield $y was added to field 242 2004/09/02 10:57 jrad
+
+Revision 1.8 Subject chopPunctuation expanded and attribute fixes 2004/08/12 jrad
+
+Revision 1.7 2004/03/25 08:29 jrad
+
+Revision 1.6 various validation fixes 2004/02/20 ntra
+
+Revision 1.5  2003/10/02 16:18:58  ntra
+MODS2 to MODS3 updates, language unstacking and 
+de-duping, chopPunctuation expanded
+
+Revision 1.3  2003/04/03 00:07:19  ntra
+Revision 1.3 Additional Changes not related to MODS Version 2.0 by ntra
+
+Revision 1.2  2003/03/24 19:37:42  ckeith
+Added Log Comment
+
+-->
+	<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-2.xsd">
+					<xsl:for-each select="//marc:collection/marc:record">
+						<mods version="3.2">
+							<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.2" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.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="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>
+		<xsl:for-each select="marc:datafield[@tag='245']">
+			<titleInfo>
+				<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">afgk</xsl:with-param>
+							</xsl:call-template>
+						</xsl:when>
+						<xsl:otherwise>
+							<xsl:call-template name="subfieldSelect">
+								<xsl:with-param name="codes">abfgk</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>
+					<xsl:when test="@ind2>0">
+						<nonSort>
+							<xsl:value-of select="substring($titleChop,1, at ind2)"/>
+						</nonSort>
+						<title>
+							<xsl:value-of select="substring($titleChop, at 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">afgk</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</subTitle>
+				</xsl:if>
+				<xsl:call-template name="part"></xsl:call-template>
+			</titleInfo>
+			<!-- A form of title that ignores non-filing characters; useful
+				 for not converting "L'Oreal" into "L' Oreal" at index time -->
+			<titleNonfiling>
+				<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">afgk</xsl:with-param>
+							</xsl:call-template>
+						</xsl:when>
+						<xsl:otherwise>
+							<xsl:call-template name="subfieldSelect">
+								<xsl:with-param name="codes">abfgk</xsl:with-param>
+							</xsl:call-template>
+						</xsl:otherwise>
+					</xsl:choose>
+				</xsl:variable>
+				<title>
+					<xsl:value-of select="$title"/>
+				</title>
+				<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">afgk</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</subTitle>
+				</xsl:if>
+				<xsl:call-template name="part"></xsl:call-template>
+			</titleNonfiling>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='210']">
+			<titleInfo type="abbreviated">
+				<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: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>
+				<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>
+				</title>
+				<!-- 1/04 fix -->
+				<xsl:call-template name="subtitle"/>
+				<xsl:call-template name="part"/>
+			</titleInfo>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='246']">
+			<titleInfo type="alternative">
+				<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:for-each>
+		<xsl:for-each select="marc:datafield[@tag='130']|marc:datafield[@tag='240']|marc:datafield[@tag='730'][@ind2!='2']">
+			<titleInfo type="uniform">
+				<title>
+					<xsl:call-template name="uri" />
+					<xsl:variable name="str">
+						<xsl:for-each select="marc:subfield">
+							<xsl:if test="(contains('adfklmor', at 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:for-each>
+		<xsl:for-each select="marc:datafield[@tag='740'][@ind2!='2']">
+			<titleInfo type="alternative">
+				<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:for-each>
+		<xsl:for-each select="marc:datafield[@tag='100']">
+			<name type="personal">
+				<xsl:call-template name="uri" />
+				<xsl:call-template name="nameABCDQ"/>
+				<xsl:call-template name="affiliation"/>
+				<role>
+					<roleTerm authority="marcrelator" type="text">creator</roleTerm>
+				</role>
+				<xsl:call-template name="role"/>
+			</name>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='110']">
+			<name type="corporate">
+				<xsl:call-template name="uri" />
+				<xsl:call-template name="nameABCDN"/>
+				<role>
+					<roleTerm authority="marcrelator" type="text">creator</roleTerm>
+				</role>
+				<xsl:call-template name="role"/>
+			</name>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='111']">
+			<name type="conference">
+				<xsl:call-template name="uri" />
+				<xsl:call-template name="nameACDEQ"/>
+				<role>
+					<roleTerm authority="marcrelator" type="text">creator</roleTerm>
+				</role>
+				<xsl:call-template name="role"/>
+			</name>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='700'][not(marc:subfield[@code='t'])]">
+			<name type="personal">
+				<xsl:call-template name="uri" />
+				<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="uri" />
+				<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="uri" />
+				<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="marc">globe</genre>
+		</xsl:if>
+		<xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
+			<genre authority="marc">remote sensing image</genre>
+		</xsl:if>
+		<xsl:if test="$typeOf008='MP'">
+			<xsl:variable name="controlField008-25" select="substring($controlField008,26,1)"></xsl:variable>
+			<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="marc">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="marc">atlas</genre>
+				</xsl:when>
+			</xsl:choose>
+		</xsl:if>
+		<xsl:if test="$typeOf008='SE'">
+			<xsl:variable name="controlField008-21" select="substring($controlField008,22,1)"></xsl:variable>
+			<xsl:choose>
+				<xsl:when test="$controlField008-21='d'">
+					<genre authority="marc">database</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-21='l'">
+					<genre authority="marc">loose-leaf</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-21='m'">
+					<genre authority="marc">series</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-21='n'">
+					<genre authority="marc">newspaper</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-21='p'">
+					<genre authority="marc">periodical</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-21='w'">
+					<genre authority="marc">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:variable>
+			<xsl:choose>
+				<xsl:when test="contains($controlField008-24,'a')">
+					<genre authority="marc">abstract or summary</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'b')">
+					<genre authority="marc">bibliography</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'c')">
+					<genre authority="marc">catalog</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'d')">
+					<genre authority="marc">dictionary</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'e')">
+					<genre authority="marc">encyclopedia</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'f')">
+					<genre authority="marc">handbook</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'g')">
+					<genre authority="marc">legal article</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'i')">
+					<genre authority="marc">index</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'k')">
+					<genre authority="marc">discography</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'l')">
+					<genre authority="marc">legislation</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'m')">
+					<genre authority="marc">theses</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'n')">
+					<genre authority="marc">survey of literature</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'o')">
+					<genre authority="marc">review</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'p')">
+					<genre authority="marc">programmed text</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'q')">
+					<genre authority="marc">filmography</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'r')">
+					<genre authority="marc">directory</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'s')">
+					<genre authority="marc">statistics</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'t')">
+					<genre authority="marc">technical report</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'v')">
+					<genre authority="marc">legal case and case notes</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'w')">
+					<genre authority="marc">law report or digest</genre>
+				</xsl:when>
+				<xsl:when test="contains($controlField008-24,'z')">
+					<genre authority="marc">treaty</genre>
+				</xsl:when>
+			</xsl:choose>
+			<xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"></xsl:variable>
+			<xsl:choose>
+				<xsl:when test="$controlField008-29='1'">
+					<genre authority="marc">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:variable>
+			<xsl:choose>
+				<xsl:when test="$controlField008-26='a'">
+					<genre authority="marc">numeric data</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-26='e'">
+					<genre authority="marc">database</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-26='f'">
+					<genre authority="marc">font</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-26='g'">
+					<genre authority="marc">game</genre>
+				</xsl:when>
+			</xsl:choose>
+		</xsl:if>
+		<xsl:if test="$typeOf008='BK'">
+			<xsl:if test="substring($controlField008,25,1)='j'">
+				<genre authority="marc">patent</genre>
+			</xsl:if>
+			<xsl:if test="substring($controlField008,31,1)='1'">
+				<genre authority="marc">festschrift</genre>
+			</xsl:if>
+			<xsl:variable name="controlField008-34" select="substring($controlField008,35,1)"></xsl:variable>
+			<xsl:if test="$controlField008-34='a' or $controlField008-34='b' or $controlField008-34='c' or $controlField008-34='d'">
+				<genre authority="marc">biography</genre>
+			</xsl:if>
+			<xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"></xsl:variable>
+			<xsl:choose>
+				<xsl:when test="$controlField008-33='e'">
+					<genre authority="marc">essay</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='d'">
+					<genre authority="marc">drama</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='c'">
+					<genre authority="marc">comic strip</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='l'">
+					<genre authority="marc">fiction</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='h'">
+					<genre authority="marc">humor, satire</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='i'">
+					<genre authority="marc">letter</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='f'">
+					<genre authority="marc">novel</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='j'">
+					<genre authority="marc">short story</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='s'">
+					<genre authority="marc">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:variable>
+			<xsl:if test="contains($controlField008-30-31,'b')">
+				<genre authority="marc">biography</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'c')">
+				<genre authority="marc">conference publication</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'d')">
+				<genre authority="marc">drama</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'e')">
+				<genre authority="marc">essay</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'f')">
+				<genre authority="marc">fiction</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'o')">
+				<genre authority="marc">folktale</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'h')">
+				<genre authority="marc">history</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'k')">
+				<genre authority="marc">humor, satire</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'m')">
+				<genre authority="marc">memoir</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'p')">
+				<genre authority="marc">poetry</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'r')">
+				<genre authority="marc">rehearsal</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'g')">
+				<genre authority="marc">reporting</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'s')">
+				<genre authority="marc">sound</genre>
+			</xsl:if>
+			<xsl:if test="contains($controlField008-30-31,'l')">
+				<genre authority="marc">speech</genre>
+			</xsl:if>
+		</xsl:if>
+		<xsl:if test="$typeOf008='VM'">
+			<xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"></xsl:variable>
+			<xsl:choose>
+				<xsl:when test="$controlField008-33='a'">
+					<genre authority="marc">art original</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='b'">
+					<genre authority="marc">kit</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='c'">
+					<genre authority="marc">art reproduction</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='d'">
+					<genre authority="marc">diorama</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='f'">
+					<genre authority="marc">filmstrip</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='g'">
+					<genre authority="marc">legal article</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='i'">
+					<genre authority="marc">picture</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='k'">
+					<genre authority="marc">graphic</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='l'">
+					<genre authority="marc">technical drawing</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='m'">
+					<genre authority="marc">motion picture</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='n'">
+					<genre authority="marc">chart</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='o'">
+					<genre authority="marc">flash card</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='p'">
+					<genre authority="marc">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="marc">model</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='r'">
+					<genre authority="marc">realia</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='s'">
+					<genre authority="marc">slide</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='t'">
+					<genre authority="marc">transparency</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='v'">
+					<genre authority="marc">videorecording</genre>
+				</xsl:when>
+				<xsl:when test="$controlField008-33='w'">
+					<genre authority="marc">toy</genre>
+				</xsl:when>
+			</xsl:choose>
+		</xsl:if>
+		<xsl:for-each select="marc:datafield[@tag=655]">
+			<genre authority="marc">
+				<xsl:attribute name="authority">
+					<xsl:value-of select="marc:subfield[@code='2']"/>
+				</xsl:attribute>
+				<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:for-each>
+		<originInfo>
+			<xsl:variable name="MARCpublicationCode" select="normalize-space(substring($controlField008,16,3))"></xsl:variable>
+			<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>
+			<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'">
+						<dateIssued>
+							<xsl:call-template name="chopPunctuation">
+								<xsl:with-param name="chopString" select="."/>
+							</xsl:call-template>
+						</dateIssued>
+					</xsl:when>
+					<xsl:when test="@code='g'">
+						<dateCreated>
+							<xsl:value-of select="."/>
+						</dateCreated>
+					</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:with-param>
+				</xsl:call-template>
+			</xsl:variable>
+			<xsl:variable name="controlField008-7-10" select="normalize-space(substring($controlField008, 8, 4))"></xsl:variable>
+			<xsl:variable name="controlField008-11-14" select="normalize-space(substring($controlField008, 12, 4))"></xsl:variable>
+			<xsl:variable name="controlField008-6" select="normalize-space(substring($controlField008, 7, 1))"></xsl:variable>
+			<xsl:if test="$controlField008-6='e' or $controlField008-6='p' or $controlField008-6='r' or $controlField008-6='t' or $controlField008-6='s'">
+				<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='q' 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='q' 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: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">
+				<issuance>
+					<xsl:choose>
+						<xsl:when test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'">monographic</xsl:when>
+						<xsl:when test="$leader7='b' or $leader7='i' or $leader7='s'">continuing</xsl:when>
+					</xsl:choose>
+				</issuance>
+			</xsl:for-each>
+			<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>
+		</originInfo>
+		<xsl:variable name="controlField008-35-37" select="normalize-space(translate(substring($controlField008,36,3),'|#',''))"></xsl:variable>
+		<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:text>
+							</xsl:with-param>
+							<xsl:with-param name="controlField008-35-37">
+								<xsl:value-of select="$controlField008-35-37"></xsl:value-of>
+							</xsl:with-param>
+						</xsl:call-template>
+					</xsl:when>
+					<xsl:otherwise>
+						<!-- iso -->
+						<xsl:variable name="allLanguages">
+							<xsl:copy-of select="$langCodes"></xsl:copy-of>
+						</xsl:variable>
+						<xsl:variable name="currentLanguage">
+							<xsl:value-of select="substring($allLanguages,1,3)"></xsl:value-of>
+						</xsl:variable>
+						<xsl:call-template name="isoLanguage">
+							<xsl:with-param name="currentLanguage">
+								<xsl:value-of select="substring($allLanguages,1,3)"></xsl:value-of>
+							</xsl:with-param>
+							<xsl:with-param name="remainingLanguages">
+								<xsl:value-of select="substring($allLanguages,4,string-length($allLanguages)-3)"></xsl:value-of>
+							</xsl:with-param>
+							<xsl:with-param name="usedLanguages">
+								<xsl:if test="$controlField008-35-37">
+									<xsl:value-of select="$controlField008-35-37"></xsl:value-of>
+								</xsl:if>
+							</xsl:with-param>
+						</xsl:call-template>
+					</xsl:otherwise>
+				</xsl:choose>
+			</xsl:for-each>
+		</xsl:for-each>
+		<xsl:variable name="physicalDescription">
+			<!--3.2 change tmee 007/11 -->
+			<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:variable name="controlField008-23" select="substring($controlField008,24,1)"></xsl:variable>
+			<xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"></xsl:variable>
+			<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:value-of>
+				</xsl:if>
+			</xsl:variable>
+			<xsl:variable name="check008-29">
+				<xsl:if test="$typeOf008='MP' or $typeOf008='VM'">
+					<xsl:value-of select="true()"></xsl:value-of>
+				</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="($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>
+			<!-- 1/04 fix -->
+			<xsl:if test="marc:datafield[@tag=130]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=130]/marc:subfield[@code='h']"></xsl:value-of>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:if test="marc:datafield[@tag=240]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=240]/marc:subfield[@code='h']"></xsl:value-of>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:if test="marc:datafield[@tag=242]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=242]/marc:subfield[@code='h']"></xsl:value-of>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:if test="marc:datafield[@tag=245]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=245]/marc:subfield[@code='h']"></xsl:value-of>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:if test="marc:datafield[@tag=246]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=246]/marc:subfield[@code='h']"></xsl:value-of>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:if test="marc:datafield[@tag=730]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=730]/marc:subfield[@code='h']"></xsl:value-of>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:for-each select="marc:datafield[@tag=256]/marc:subfield[@code='a']">
+				<form>
+					<xsl:value-of select="."></xsl:value-of>
+				</form>
+			</xsl:for-each>
+			<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>
+			<!--3.2 change tmee 007/01 -->
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='b']">
+				<form authority="smd">chip cartridge</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='c']">
+				<form authority="smd">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="smd">magnetic disc</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='m']">
+				<form authority="smd">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="smd">optical disc</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='r']">
+				<form authority="smd">remote</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='a']">
+				<form authority="smd">tape cartridge</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='f']">
+				<form authority="smd">tape cassette</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='h']">
+				<form authority="smd">tape reel</form>
+			</xsl:if>
+			
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='a']">
+				<form authority="smd">celestial globe</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='e']">
+				<form authority="smd">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="smd">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="smd">terrestrial globe</form>
+			</xsl:if>
+			
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='o'][substring(text(),2,1)='o']">
+				<form authority="smd">kit</form>
+			</xsl:if>
+			
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
+				<form authority="smd">atlas</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='g']">
+				<form authority="smd">diagram</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='j']">
+				<form authority="smd">map</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
+				<form authority="smd">model</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='k']">
+				<form authority="smd">profile</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
+				<form authority="smd">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="smd">section</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='y']">
+				<form authority="smd">view</form>
+			</xsl:if>
+			
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='a']">
+				<form authority="smd">aperture card</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='e']">
+				<form authority="smd">microfiche</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='f']">
+				<form authority="smd">microfiche cassette</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='b']">
+				<form authority="smd">microfilm cartridge</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='c']">
+				<form authority="smd">microfilm cassette</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='d']">
+				<form authority="smd">microfilm reel</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='g']">
+				<form authority="smd">microopaque</form>
+			</xsl:if>
+			
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='c']">
+				<form authority="smd">film cartridge</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='f']">
+				<form authority="smd">film cassette</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='r']">
+				<form authority="smd">film reel</form>
+			</xsl:if>
+			
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='n']">
+				<form authority="smd">chart</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='c']">
+				<form authority="smd">collage</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='d']">
+				<form authority="smd">drawing</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='o']">
+				<form authority="smd">flash card</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='e']">
+				<form authority="smd">painting</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='f']">
+				<form authority="smd">photomechanical print</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='g']">
+				<form authority="smd">photonegative</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='h']">
+				<form authority="smd">photoprint</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='i']">
+				<form authority="smd">picture</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='j']">
+				<form authority="smd">print</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='l']">
+				<form authority="smd">technical drawing</form>
+			</xsl:if>
+			
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='q'][substring(text(),2,1)='q']">
+				<form authority="smd">notated music</form>
+			</xsl:if>
+			
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='d']">
+				<form authority="smd">filmslip</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='c']">
+				<form authority="smd">filmstrip cartridge</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='o']">
+				<form authority="smd">filmstrip roll</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='f']">
+				<form authority="smd">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="smd">slide</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='t']">
+				<form authority="smd">transparency</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='r'][substring(text(),2,1)='r']">
+				<form authority="smd">remote-sensing image</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='e']">
+				<form authority="smd">cylinder</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='q']">
+				<form authority="smd">roll</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='g']">
+				<form authority="smd">sound cartridge</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='s']">
+				<form authority="smd">sound cassette</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='d']">
+				<form authority="smd">sound disc</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='t']">
+				<form authority="smd">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="smd">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="smd">wire recording</form>
+			</xsl:if>
+			
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='c']">
+				<form authority="smd">braille</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='b']">
+				<form authority="smd">combination</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='a']">
+				<form authority="smd">moon</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='d']">
+				<form authority="smd">tactile, with no writing system</form>
+			</xsl:if>
+			
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='c']">
+				<form authority="smd">braille</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='b']">
+				<form authority="smd">large print</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='a']">
+				<form authority="smd">regular print</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='d']">
+				<form authority="smd">text in looseleaf binder</form>
+			</xsl:if>
+			
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='c']">
+				<form authority="smd">videocartridge</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='f']">
+				<form authority="smd">videocassette</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='d']">
+				<form authority="smd">videodisc</form>
+			</xsl:if>
+			<xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='r']">
+				<form authority="smd">videoreel</form>
+			</xsl:if>
+			
+			<xsl:for-each select="marc:datafield[@tag=856]/marc:subfield[@code='q'][string-length(.)>1]">
+				<internetMediaType>
+					<xsl:value-of select="."></xsl:value-of>
+				</internetMediaType>
+			</xsl:for-each>
+			<xsl:for-each select="marc:datafield[@tag=300]">
+				<extent>
+					<xsl:call-template name="subfieldSelect">
+						<xsl:with-param name="codes">abce</xsl:with-param>
+					</xsl:call-template>
+				</extent>
+			</xsl:for-each>
+		</xsl:variable>
+		<xsl:if test="string-length(normalize-space($physicalDescription))">
+			<physicalDescription>
+				<xsl:copy-of select="$physicalDescription"></xsl:copy-of>
+			</physicalDescription>
+		</xsl:if>
+		<xsl:for-each select="marc:datafield[@tag=520]">
+			<abstract>
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</abstract>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=505]">
+			<tableOfContents>
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">agrt</xsl:with-param>
+				</xsl:call-template>
+			</tableOfContents>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=521]">
+			<targetAudience>
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</targetAudience>
+		</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:variable>
+			<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>
+		<xsl:for-each select="marc:datafield[@tag=245]/marc:subfield[@code='c']">
+			<note type="statement of responsibility">
+				<xsl:value-of select="."></xsl:value-of>
+			</note>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=500]">
+			<note>
+				<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
+				<xsl:call-template name="uri"></xsl:call-template>
+			</note>
+		</xsl:for-each>
+		
+		<!--3.2 change tmee additional note fields-->
+		
+		<xsl:for-each select="marc:datafield[@tag=506]">
+			<note type="restrictions">
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:variable name="str">
+					<xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
+						<xsl:value-of select="."></xsl:value-of>
+						<xsl:text> </xsl:text>
+					</xsl:for-each>
+				</xsl:variable>
+				<xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
+			</note>
+		</xsl:for-each>
+		
+		<xsl:for-each select="marc:datafield[@tag=510]">
+			<note  type="citation/reference">
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:variable name="str">
+					<xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
+						<xsl:value-of select="."></xsl:value-of>
+						<xsl:text> </xsl:text>
+					</xsl:for-each>
+				</xsl:variable>
+				<xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
+			</note>
+		</xsl:for-each>
+		
+			
+		<xsl:for-each select="marc:datafield[@tag=511]">
+			<note type="performers">
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
+			</note>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=518]">
+			<note type="venue">
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
+			</note>
+		</xsl:for-each>
+		
+		<xsl:for-each select="marc:datafield[@tag=530]">
+			<note  type="additional physical form">
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:variable name="str">
+					<xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
+						<xsl:value-of select="."></xsl:value-of>
+						<xsl:text> </xsl:text>
+					</xsl:for-each>
+				</xsl:variable>
+				<xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
+			</note>
+		</xsl:for-each>
+		
+		<xsl:for-each select="marc:datafield[@tag=533]">
+			<note  type="reproduction">
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:variable name="str">
+					<xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
+						<xsl:value-of select="."></xsl:value-of>
+						<xsl:text> </xsl:text>
+					</xsl:for-each>
+				</xsl:variable>
+				<xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
+			</note>
+		</xsl:for-each>
+		
+		<xsl:for-each select="marc:datafield[@tag=534]">
+			<note  type="original version">
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:variable name="str">
+					<xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
+						<xsl:value-of select="."></xsl:value-of>
+						<xsl:text> </xsl:text>
+					</xsl:for-each>
+				</xsl:variable>
+				<xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
+			</note>
+		</xsl:for-each>
+		
+		<xsl:for-each select="marc:datafield[@tag=538]">
+			<note  type="system details">
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:variable name="str">
+					<xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
+						<xsl:value-of select="."></xsl:value-of>
+						<xsl:text> </xsl:text>
+					</xsl:for-each>
+				</xsl:variable>
+				<xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
+			</note>
+		</xsl:for-each>
+		
+		<xsl:for-each select="marc:datafield[@tag=583]">
+			<note type="action">
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:variable name="str">
+					<xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
+						<xsl:value-of select="."></xsl:value-of>
+						<xsl:text> </xsl:text>
+					</xsl:for-each>
+				</xsl:variable>
+				<xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
+			</note>
+		</xsl:for-each>
+		
+
+		
+		
+		
+		<xsl:for-each select="marc:datafield[@tag=501 or @tag=502 or @tag=504 or @tag=507 or @tag=508 or  @tag=513 or @tag=514 or @tag=515 or @tag=516 or @tag=522 or @tag=524 or @tag=525 or @tag=526 or @tag=535 or @tag=536 or @tag=540 or @tag=541 or @tag=544 or @tag=545 or @tag=546 or @tag=547 or @tag=550 or @tag=552 or @tag=555 or @tag=556 or @tag=561 or @tag=562 or @tag=565 or @tag=567 or @tag=580 or @tag=581 or @tag=584 or @tag=585 or @tag=586]">
+			<note>
+				<xsl:call-template name="uri"></xsl:call-template>
+				<xsl:variable name="str">
+					<xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
+						<xsl:value-of select="."></xsl:value-of>
+						<xsl:text> </xsl:text>
+					</xsl:for-each>
+				</xsl:variable>
+				<xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
+			</note>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=034][marc:subfield[@code='d' or @code='e' or @code='f' or @code='g']]">
+			<subject>
+				<cartographics>
+					<coordinates>
+						<xsl:call-template name="subfieldSelect">
+							<xsl:with-param name="codes">defg</xsl:with-param>
+						</xsl:call-template>
+					</coordinates>
+				</cartographics>
+			</subject>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=043]">
+			<subject>
+				<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:value-of>
+							</xsl:if>
+							<xsl:if test="@code='c'">
+								<xsl:text>iso3166</xsl:text>
+							</xsl:if>
+						</xsl:attribute>
+						<xsl:value-of select="self::marc:subfield"></xsl:value-of>
+					</geographicCode>
+				</xsl:for-each>
+			</subject>
+		</xsl:for-each>
+		<!-- tmee 2006/11/27 -->
+		<xsl:for-each select="marc:datafield[@tag=255]">
+			<subject>
+				<xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
+				<cartographics>
+					<xsl:if test="@code='a'">
+						<scale>
+							<xsl:value-of select="."></xsl:value-of>
+						</scale>
+					</xsl:if>
+					<xsl:if test="@code='b'">
+						<projection>
+							<xsl:value-of select="."></xsl:value-of>
+						</projection>
+					</xsl:if>
+					<xsl:if test="@code='c'">
+						<coordinates>
+							<xsl:value-of select="."></xsl:value-of>
+						</coordinates>
+					</xsl:if>
+				</cartographics>
+				</xsl:for-each>
+			</subject>
+		</xsl:for-each>
+				
+		<xsl:apply-templates select="marc:datafield[653 >= @tag and @tag >= 600]"></xsl:apply-templates>
+		<xsl:apply-templates select="marc:datafield[@tag=656]"></xsl:apply-templates>
+		<xsl:for-each select="marc:datafield[@tag=752]">
+			<subject>
+				<hierarchicalGeographic>
+					<xsl:for-each select="marc:subfield[@code='a']">
+						<country>
+							<xsl:call-template name="chopPunctuation">
+								<xsl:with-param name="chopString" select="."></xsl:with-param>
+							</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:with-param>
+							</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:with-param>
+							</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:with-param>
+							</xsl:call-template>
+						</city>
+					</xsl:for-each>
+				</hierarchicalGeographic>
+			</subject>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=045][marc:subfield[@code='b']]">
+			<subject>
+				<xsl:choose>
+					<xsl:when test="@ind1=2">
+						<temporal encoding="iso8601" point="start">
+							<xsl:call-template name="chopPunctuation">
+								<xsl:with-param name="chopString">
+									<xsl:value-of select="marc:subfield[@code='b'][1]"></xsl:value-of>
+								</xsl:with-param>
+							</xsl:call-template>
+						</temporal>
+						<temporal encoding="iso8601" point="end">
+							<xsl:call-template name="chopPunctuation">
+								<xsl:with-param name="chopString">
+									<xsl:value-of select="marc:subfield[@code='b'][2]"></xsl:value-of>
+								</xsl:with-param>
+							</xsl:call-template>
+						</temporal>
+					</xsl:when>
+					<xsl:otherwise>
+						<xsl:for-each select="marc:subfield[@code='b']">
+							<temporal encoding="iso8601">
+								<xsl:call-template name="chopPunctuation">
+									<xsl:with-param name="chopString" select="."></xsl:with-param>
+								</xsl:call-template>
+							</temporal>
+						</xsl:for-each>
+					</xsl:otherwise>
+				</xsl:choose>
+			</subject>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=050]">
+			<xsl:for-each select="marc:subfield[@code='b']">
+				<classification authority="lcc">
+					<xsl:if test="../marc:subfield[@code='3']">
+						<xsl:attribute name="displayLabel">
+							<xsl:value-of select="../marc:subfield[@code='3']"></xsl:value-of>
+						</xsl:attribute>
+					</xsl:if>
+					<xsl:value-of select="preceding-sibling::marc:subfield[@code='a'][1]"></xsl:value-of>
+					<xsl:text> </xsl:text>
+					<xsl:value-of select="text()"></xsl:value-of>
+				</classification>
+			</xsl:for-each>
+			<xsl:for-each select="marc:subfield[@code='a'][not(following-sibling::marc:subfield[@code='b'])]">
+				<classification authority="lcc">
+					<xsl:if test="../marc:subfield[@code='3']">
+						<xsl:attribute name="displayLabel">
+							<xsl:value-of select="../marc:subfield[@code='3']"></xsl:value-of>
+						</xsl:attribute>
+					</xsl:if>
+					<xsl:value-of select="text()"></xsl:value-of>
+				</classification>
+			</xsl:for-each>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=082]">
+			<classification authority="ddc">
+				<xsl:if test="marc:subfield[@code='2']">
+					<xsl:attribute name="edition">
+						<xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
+					</xsl:attribute>
+				</xsl:if>
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</classification>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=080]">
+			<classification authority="udc">
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">abx</xsl:with-param>
+				</xsl:call-template>
+			</classification>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=060]">
+			<classification authority="nlm">
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</classification>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=086][@ind1=0]">
+			<classification authority="sudocs">
+				<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
+			</classification>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=086][@ind1=1]">
+			<classification authority="candoc">
+				<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
+			</classification>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=086]">
+			<classification>
+				<xsl:attribute name="authority">
+					<xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
+				</xsl:attribute>
+				<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
+			</classification>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=084]">
+			<classification>
+				<xsl:attribute name="authority">
+					<xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
+				</xsl:attribute>
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</classification>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=440]">
+			<relatedItem type="series">
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="subfieldSelect">
+									<xsl:with-param name="codes">av</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="part"></xsl:call-template>
+				</titleInfo>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=490][@ind1=0]">
+			<relatedItem type="series">
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="subfieldSelect">
+									<xsl:with-param name="codes">av</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="part"></xsl:call-template>
+				</titleInfo>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=510]">
+			<relatedItem type="isReferencedBy">
+				<note>
+					<xsl:call-template name="subfieldSelect">
+						<xsl:with-param name="codes">abcx3</xsl:with-param>
+					</xsl:call-template>
+				</note>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=534]">
+			<relatedItem type="original">
+				<xsl:call-template name="relatedTitle"></xsl:call-template>
+				<xsl:call-template name="relatedName"></xsl:call-template>
+				<xsl:if test="marc:subfield[@code='b' or @code='c']">
+					<originInfo>
+						<xsl:for-each select="marc:subfield[@code='c']">
+							<publisher>
+								<xsl:value-of select="."></xsl:value-of>
+							</publisher>
+						</xsl:for-each>
+						<xsl:for-each select="marc:subfield[@code='b']">
+							<edition>
+								<xsl:value-of select="."></xsl:value-of>
+							</edition>
+						</xsl:for-each>
+					</originInfo>
+				</xsl:if>
+				<xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
+				<xsl:for-each select="marc:subfield[@code='z']">
+					<identifier type="isbn">
+						<xsl:value-of select="."></xsl:value-of>
+					</identifier>
+				</xsl:for-each>
+				<xsl:call-template name="relatedNote"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=700][marc:subfield[@code='t']]">
+			<relatedItem>
+				<xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
+				<titleInfo>
+					<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"></xsl:call-template>
+				</titleInfo>
+				<name type="personal">
+					<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>
+					<xsl:call-template name="nameDate"></xsl:call-template>
+					<xsl:call-template name="role"></xsl:call-template>
+				</name>
+				<xsl:call-template name="relatedForm"></xsl:call-template>
+				<xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=710][marc:subfield[@code='t']]">
+			<relatedItem>
+				<xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
+				<titleInfo>
+					<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">dg</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="relatedPartNumName"></xsl:call-template>
+				</titleInfo>
+				<name type="corporate">
+					<xsl:for-each select="marc:subfield[@code='a']">
+						<namePart>
+							<xsl:value-of select="."></xsl:value-of>
+						</namePart>
+					</xsl:for-each>
+					<xsl:for-each select="marc:subfield[@code='b']">
+						<namePart>
+							<xsl:value-of select="."></xsl:value-of>
+						</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"></xsl:value-of>
+						</namePart>
+					</xsl:if>
+					<xsl:call-template name="role"></xsl:call-template>
+				</name>
+				<xsl:call-template name="relatedForm"></xsl:call-template>
+				<xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=711][marc:subfield[@code='t']]">
+			<relatedItem>
+				<xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="specialSubfieldSelect">
+									<xsl:with-param name="anyCodes">tfklsv</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="relatedPartNumName"></xsl:call-template>
+				</titleInfo>
+				<name type="conference">
+					<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>
+				</name>
+				<xsl:call-template name="relatedForm"></xsl:call-template>
+				<xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=730][@ind2=2]">
+			<relatedItem>
+				<xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="subfieldSelect">
+									<xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="part"></xsl:call-template>
+				</titleInfo>
+				<xsl:call-template name="relatedForm"></xsl:call-template>
+				<xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=740][@ind2=2]">
+			<relatedItem>
+				<xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="part"></xsl:call-template>
+				</titleInfo>
+				<xsl:call-template name="relatedForm"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=760]|marc:datafield[@tag=762]">
+			<relatedItem type="series">
+				<xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=765]|marc:datafield[@tag=767]|marc:datafield[@tag=777]|marc:datafield[@tag=787]">
+			<relatedItem>
+				<xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=775]">
+			<relatedItem type="otherVersion">
+				<xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=770]|marc:datafield[@tag=774]">
+			<relatedItem type="constituent">
+				<xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=772]|marc:datafield[@tag=773]">
+			<relatedItem type="host">
+				<xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=776]">
+			<relatedItem type="otherFormat">
+				<xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=780]">
+			<relatedItem type="preceding">
+				<xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=785]">
+			<relatedItem type="succeeding">
+				<xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=786]">
+			<relatedItem type="original">
+				<xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=800]">
+			<relatedItem type="series">
+				<titleInfo>
+					<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"></xsl:call-template>
+				</titleInfo>
+				<name type="personal">
+					<namePart>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<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>
+							</xsl:with-param>
+						</xsl:call-template>
+					</namePart>
+					<xsl:call-template name="termsOfAddress"></xsl:call-template>
+					<xsl:call-template name="nameDate"></xsl:call-template>
+					<xsl:call-template name="role"></xsl:call-template>
+				</name>
+				<xsl:call-template name="relatedForm"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=810]">
+			<relatedItem type="series">
+				<titleInfo>
+					<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">dg</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="relatedPartNumName"></xsl:call-template>
+				</titleInfo>
+				<name type="corporate">
+					<xsl:for-each select="marc:subfield[@code='a']">
+						<namePart>
+							<xsl:value-of select="."></xsl:value-of>
+						</namePart>
+					</xsl:for-each>
+					<xsl:for-each select="marc:subfield[@code='b']">
+						<namePart>
+							<xsl:value-of select="."></xsl:value-of>
+						</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"></xsl:call-template>
+				</name>
+				<xsl:call-template name="relatedForm"></xsl:call-template>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=811]">
+			<relatedItem type="series">
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="specialSubfieldSelect">
+									<xsl:with-param name="anyCodes">tfklsv</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="relatedPartNumName"/>
+				</titleInfo>
+				<name type="conference">
+					<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"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='830']">
+			<relatedItem type="series">
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="subfieldSelect">
+									<xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="part"/>
+				</titleInfo>
+				<xsl:call-template name="relatedForm"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='856'][@ind2='2']/marc:subfield[@code='q']">
+			<relatedItem>
+				<internetMediaType>
+					<xsl:value-of select="."/>
+				</internetMediaType>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='020']">
+			<xsl:call-template name="isInvalid">
+				<xsl:with-param name="type">isbn</xsl:with-param>
+			</xsl:call-template>
+			<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='024'][@ind1='0']">
+			<xsl:call-template name="isInvalid">
+				<xsl:with-param name="type">isrc</xsl:with-param>
+			</xsl:call-template>
+			<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:call-template name="isInvalid">
+				<xsl:with-param name="type">ismn</xsl:with-param>
+			</xsl:call-template>
+			<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']">
+			<xsl:call-template name="isInvalid">
+				<xsl:with-param name="type">sici</xsl:with-param>
+			</xsl:call-template>
+			<identifier type="sici">
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</identifier>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='022']">
+			<xsl:call-template name="isInvalid">
+				<xsl:with-param name="type">issn</xsl:with-param>
+			</xsl:call-template>
+			<identifier type="issn">
+				<xsl:value-of select="marc:subfield[@code='a']"/>
+			</identifier>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='010']">
+			<xsl:call-template name="isInvalid">
+				<xsl:with-param name="type">lccn</xsl:with-param>
+			</xsl:call-template>
+			<identifier type="lccn">
+				<xsl:value-of select="normalize-space(marc:subfield[@code='a'])"/>
+			</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="isInvalid"/>--> <!-- no $z in 028 -->
+				<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='037']">
+			<identifier type="stock number">
+				<!--<xsl:call-template name="isInvalid"/>--> <!-- no $z in 037 -->
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</identifier>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='856'][marc:subfield[@code='u']]">
+			<identifier>
+				<xsl:attribute name="type">
+					<xsl:choose>
+						<xsl:when test="starts-with(marc:subfield[@code='u'],'urn:doi') or starts-with(marc:subfield[@code='u'],'doi')">doi</xsl:when>
+						<xsl:when 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:when>
+						<xsl:otherwise>uri</xsl:otherwise>
+					</xsl:choose>
+				</xsl:attribute>
+				<xsl:choose>
+					<xsl:when 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') ">
+						<xsl:value-of select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"></xsl:value-of>
+					</xsl:when>
+					<xsl:otherwise>
+						<xsl:value-of select="marc:subfield[@code='u']"></xsl:value-of>
+					</xsl:otherwise>
+				</xsl:choose>
+			</identifier>
+			<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/'))"></xsl:value-of>
+				</identifier>
+			</xsl:if>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=024][@ind1=1]">
+			<identifier type="upc">
+				<xsl:call-template name="isInvalid"/>
+				<xsl:value-of select="marc:subfield[@code='a']"/>
+			</identifier>
+		</xsl:for-each>
+		<!-- 1/04 fix added $y -->
+		<xsl:for-each select="marc:datafield[@tag=856][marc:subfield[@code='u']]">
+			<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']"></xsl:value-of>
+
+				</url>
+			</location>
+		</xsl:for-each>
+			
+			<!-- 3.2 change tmee 856z  -->
+
+		
+		<xsl:for-each select="marc:datafield[@tag=852]">
+			<location>
+				<physicalLocation>
+					<xsl:call-template name="displayLabel"></xsl:call-template>
+					<xsl:call-template name="subfieldSelect">
+						<xsl:with-param name="codes">abje</xsl:with-param>
+					</xsl:call-template>
+				</physicalLocation>
+			</location>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=506]">
+			<accessCondition type="restrictionOnAccess">
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">abcd35</xsl:with-param>
+				</xsl:call-template>
+			</accessCondition>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=540]">
+			<accessCondition type="useAndReproduction">
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">abcde35</xsl:with-param>
+				</xsl:call-template>
+			</accessCondition>
+		</xsl:for-each>
+		<recordInfo>
+			<xsl:for-each select="marc:datafield[@tag=040]">
+				<recordContentSource authority="marcorg">
+					<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
+				</recordContentSource>
+			</xsl:for-each>
+			<xsl:for-each select="marc:controlfield[@tag=008]">
+				<recordCreationDate encoding="marc">
+					<xsl:value-of select="substring(.,1,6)"></xsl:value-of>
+				</recordCreationDate>
+			</xsl:for-each>
+			<xsl:for-each select="marc:controlfield[@tag=005]">
+				<recordChangeDate encoding="iso8601">
+					<xsl:value-of select="."></xsl:value-of>
+				</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:value-of>
+						</xsl:attribute>
+					</xsl:if>
+					<xsl:value-of select="."></xsl:value-of>
+				</recordIdentifier>
+			</xsl:for-each>
+			<xsl:for-each select="marc:datafield[@tag=040]/marc:subfield[@code='b']">
+				<languageOfCataloging>
+					<languageTerm authority="iso639-2b" type="code">
+						<xsl:value-of select="."></xsl:value-of>
+					</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="."></xsl:value-of>
+			</displayForm>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="affiliation">
+		<xsl:for-each select="marc:subfield[@code='u']">
+			<affiliation>
+				<xsl:value-of select="."></xsl:value-of>
+			</affiliation>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="uri">
+		<xsl:for-each select="marc:subfield[@code='u']">
+			<xsl:attribute name="xlink:href">
+				<xsl:value-of select="."></xsl:value-of>
+			</xsl:attribute>
+		</xsl:for-each>
+		<xsl:for-each select="marc:subfield[@code='0']">
+			<xsl:choose>
+				<xsl:when test="contains(text(), ')')">
+					<xsl:attribute name="xlink:href">
+						<xsl:value-of select="substring-after(text(), ')')"></xsl:value-of>
+					</xsl:attribute>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:attribute name="xlink:href">
+						<xsl:value-of select="."></xsl:value-of>
+					</xsl:attribute>
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="role">
+		<xsl:for-each select="marc:subfield[@code='e']">
+			<role>
+				<roleTerm type="text">
+					<xsl:value-of select="."></xsl:value-of>
+				</roleTerm>
+			</role>
+		</xsl:for-each>
+		<xsl:for-each select="marc:subfield[@code='4']">
+			<role>
+				<roleTerm authority="marcrelator" type="code">
+					<xsl:value-of select="."></xsl:value-of>
+				</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: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:call-template name="chopPunctuation">
+					<xsl:with-param name="chopString" select="$partNumber"></xsl:with-param>
+				</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:with-param>
+				</xsl:call-template>
+			</partName>
+		</xsl:if>
+	</xsl:template>
+	<xsl:template name="relatedPart">
+		<xsl:if test="@tag=773">
+			<xsl:for-each select="marc:subfield[@code='g']">
+				<part>
+					<text>
+						<xsl:value-of select="."></xsl:value-of>
+					</text>
+				</part>
+			</xsl:for-each>
+			<xsl:for-each select="marc:subfield[@code='q']">
+				<part>
+					<xsl:call-template name="parsePart"></xsl:call-template>
+				</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"></xsl:value-of>
+			</partNumber>
+		</xsl:if>
+		<xsl:if test="string-length(normalize-space($partName))">
+			<partName>
+				<xsl:value-of select="$partName"></xsl:value-of>
+			</partName>
+		</xsl:if>
+	</xsl:template>
+	<xsl:template name="relatedName">
+		<xsl:for-each select="marc:subfield[@code='a']">
+			<name>
+				<namePart>
+					<xsl:value-of select="."></xsl:value-of>
+				</namePart>
+			</name>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="relatedForm">
+		<xsl:for-each select="marc:subfield[@code='h']">
+			<physicalDescription>
+				<form>
+					<xsl:value-of select="."></xsl:value-of>
+				</form>
+			</physicalDescription>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="relatedExtent">
+		<xsl:for-each select="marc:subfield[@code='h']">
+			<physicalDescription>
+				<extent>
+					<xsl:value-of select="."></xsl:value-of>
+				</extent>
+			</physicalDescription>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="relatedNote">
+		<xsl:for-each select="marc:subfield[@code='n']">
+			<note>
+				<xsl:value-of select="."></xsl:value-of>
+			</note>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="relatedSubject">
+		<xsl:for-each select="marc:subfield[@code='j']">
+			<subject>
+				<temporal encoding="iso8601">
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString" select="."></xsl:with-param>
+					</xsl:call-template>
+				</temporal>
+			</subject>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="relatedIdentifierISSN">
+		<xsl:for-each select="marc:subfield[@code='x']">
+			<identifier type="issn">
+				<xsl:value-of select="."></xsl:value-of>
+			</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="."></xsl:value-of>
+			</identifier>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="relatedIdentifier">
+		<xsl:for-each select="marc:subfield[@code='o']">
+			<identifier>
+				<xsl:value-of select="."></xsl:value-of>
+			</identifier>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="relatedItem76X-78X">
+		<xsl:call-template name="displayLabel"></xsl:call-template>
+		<xsl:call-template name="relatedTitle76X-78X"></xsl:call-template>
+		<xsl:call-template name="relatedName"></xsl:call-template>
+		<xsl:call-template name="relatedOriginInfo"></xsl:call-template>
+		<xsl:call-template name="relatedLanguage"></xsl:call-template>
+		<xsl:call-template name="relatedExtent"></xsl:call-template>
+		<xsl:call-template name="relatedNote"></xsl:call-template>
+		<xsl:call-template name="relatedSubject"></xsl:call-template>
+		<xsl:call-template name="relatedIdentifier"></xsl:call-template>
+		<xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
+		<xsl:call-template name="relatedIdentifierLocal"></xsl:call-template>
+		<xsl:call-template name="relatedPart"></xsl:call-template>
+	</xsl:template>
+	<xsl:template name="subjectGeographicZ">
+		<geographic>
+			<xsl:call-template name="chopPunctuation">
+				<xsl:with-param name="chopString" select="."></xsl:with-param>
+			</xsl:call-template>
+		</geographic>
+	</xsl:template>
+	<xsl:template name="subjectTemporalY">
+		<temporal>
+			<xsl:call-template name="chopPunctuation">
+				<xsl:with-param name="chopString" select="."></xsl:with-param>
+			</xsl:call-template>
+		</temporal>
+	</xsl:template>
+	<xsl:template name="subjectTopic">
+		<topic>
+			<xsl:call-template name="chopPunctuation">
+				<xsl:with-param name="chopString" select="."></xsl:with-param>
+			</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:with-param>
+			</xsl:call-template>
+		</genre>
+	</xsl:template>
+	
+	<xsl:template name="nameABCDN">
+		<xsl:for-each select="marc:subfield[@code='a']">
+			<namePart>
+				<xsl:call-template name="chopPunctuation">
+					<xsl:with-param name="chopString" select="."></xsl:with-param>
+				</xsl:call-template>
+			</namePart>
+		</xsl:for-each>
+		<xsl:for-each select="marc:subfield[@code='b']">
+			<namePart>
+				<xsl:value-of select="."></xsl:value-of>
+			</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>
+			<xsl:call-template name="chopPunctuation">
+				<xsl:with-param name="chopString">
+					<xsl:call-template name="subfieldSelect">
+						<xsl:with-param name="codes">aq</xsl:with-param>
+					</xsl:call-template>
+				</xsl:with-param>
+				<xsl:with-param name="punctuation">
+					<xsl:text>:,;/ </xsl:text>
+				</xsl:with-param>
+			</xsl:call-template>
+		</namePart>
+		<xsl:call-template name="termsOfAddress"></xsl:call-template>
+		<xsl:call-template name="nameDate"></xsl:call-template>
+	</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>
+	<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>
+				<title>
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="."></xsl:value-of>
+						</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>
+				<title>
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="."></xsl:value-of>
+						</xsl:with-param>
+					</xsl:call-template>
+				</title>
+				<xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
+					<xsl:call-template name="relatedPartNumName"></xsl:call-template>
+				</xsl:if>
+			</titleInfo>
+		</xsl:for-each>
+		<xsl:for-each select="marc:subfield[@code='p']">
+			<titleInfo type="abbreviated">
+				<title>
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="."></xsl:value-of>
+						</xsl:with-param>
+					</xsl:call-template>
+				</title>
+				<xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
+					<xsl:call-template name="relatedPartNumName"></xsl:call-template>
+				</xsl:if>
+			</titleInfo>
+		</xsl:for-each>
+		<xsl:for-each select="marc:subfield[@code='s']">
+			<titleInfo type="uniform">
+				<title>
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="."></xsl:value-of>
+						</xsl:with-param>
+					</xsl:call-template>
+				</title>
+				<xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
+					<xsl:call-template name="relatedPartNumName"></xsl:call-template>
+				</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="."></xsl:value-of>
+							</placeTerm>
+						</place>
+					</xsl:for-each>
+				</xsl:if>
+				<xsl:for-each select="marc:subfield[@code='d']">
+					<publisher>
+						<xsl:value-of select="."></xsl:value-of>
+					</publisher>
+				</xsl:for-each>
+				<xsl:for-each select="marc:subfield[@code='b']">
+					<edition>
+						<xsl:value-of select="."></xsl:value-of>
+					</edition>
+				</xsl:for-each>
+			</originInfo>
+		</xsl:if>
+	</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:value-of>
+				</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">
+				<xsl:call-template name="chopPunctuation">
+					<xsl:with-param name="chopString" 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:value-of>
+								</xsl:when>
+							</xsl:choose>
+						</xsl:attribute>
+					</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:call-template>
+				</xsl:when>
+				<xsl:when test="@code='x'">
+					<xsl:call-template name="subjectTopic"></xsl:call-template>
+				</xsl:when>
+				<xsl:when test="@code='y'">
+					<xsl:call-template name="subjectTemporalY"></xsl:call-template>
+				</xsl:when>
+				<xsl:when test="@code='z'">
+					<xsl:call-template name="subjectGeographicZ"></xsl:call-template>
+				</xsl:when>
+			</xsl:choose>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="specialSubfieldSelect">
+		<xsl:param name="anyCodes"></xsl:param>
+		<xsl:param name="axis"></xsl:param>
+		<xsl:param name="beforeCodes"></xsl:param>
+		<xsl:param name="afterCodes"></xsl:param>
+		<xsl:variable name="str">
+			<xsl:for-each select="marc:subfield">
+				<xsl:if test="contains($anyCodes, @code)      or (contains($beforeCodes, at code) and following-sibling::marc:subfield[@code=$axis])      or (contains($afterCodes, at code) and preceding-sibling::marc:subfield[@code=$axis])">
+					<xsl:value-of select="text()"></xsl:value-of>
+					<xsl:text> </xsl:text>
+				</xsl:if>
+			</xsl:for-each>
+		</xsl:variable>
+		<xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
+	</xsl:template>
+	
+	<!-- 3.2 change tmee 6xx $v genre -->
+	<xsl:template match="marc:datafield[@tag=600]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"></xsl:call-template>
+			<name type="personal">
+				<xsl:call-template name="termsOfAddress"></xsl:call-template>
+				<namePart>
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:call-template name="subfieldSelect">
+								<xsl:with-param name="codes">aq</xsl:with-param>
+							</xsl:call-template>
+						</xsl:with-param>
+					</xsl:call-template>
+				</namePart>
+				<xsl:call-template name="nameDate"></xsl:call-template>
+				<xsl:call-template name="affiliation"></xsl:call-template>
+				<xsl:call-template name="role"></xsl:call-template>
+			</name>
+			<xsl:call-template name="subjectAnyOrder"></xsl:call-template>
+		</subject>
+	</xsl:template>
+	<xsl:template match="marc:datafield[@tag=610]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"></xsl:call-template>
+			<name type="corporate">
+				<xsl:for-each select="marc:subfield[@code='a']">
+					<namePart>
+						<xsl:value-of select="."></xsl:value-of>
+					</namePart>
+				</xsl:for-each>
+				<xsl:for-each select="marc:subfield[@code='b']">
+					<namePart>
+						<xsl:value-of select="."></xsl:value-of>
+					</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"></xsl:call-template>
+			</name>
+			<xsl:call-template name="subjectAnyOrder"></xsl:call-template>
+		</subject>
+	</xsl:template>
+	<xsl:template match="marc:datafield[@tag=611]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"></xsl:call-template>
+			<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="."></xsl:value-of>
+						</roleTerm>
+					</role>
+				</xsl:for-each>
+			</name>
+			<xsl:call-template name="subjectAnyOrder"></xsl:call-template>
+		</subject>
+	</xsl:template>
+	<xsl:template match="marc:datafield[@tag=630]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"></xsl:call-template>
+			<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>
+					<xsl:call-template name="part"></xsl:call-template>
+				</title>
+			</titleInfo>
+			<xsl:call-template name="subjectAnyOrder"></xsl:call-template>
+		</subject>
+	</xsl:template>
+	<xsl:template match="marc:datafield[@tag=650]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"></xsl:call-template>
+			<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"></xsl:call-template>
+		</subject>
+	</xsl:template>
+	<xsl:template match="marc:datafield[@tag=651]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"></xsl:call-template>
+			<xsl:for-each select="marc:subfield[@code='a']">
+				<geographic>
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString" select="."></xsl:with-param>
+					</xsl:call-template>
+				</geographic>
+			</xsl:for-each>
+			<xsl:call-template name="subjectAnyOrder"></xsl:call-template>
+		</subject>
+	</xsl:template>
+	<xsl:template match="marc:datafield[@tag=653]">
+		<subject>
+			<xsl:for-each select="marc:subfield[@code='a']">
+				<topic>
+					<xsl:value-of select="."></xsl:value-of>
+				</topic>
+			</xsl:for-each>
+		</subject>
+	</xsl:template>
+	<xsl:template match="marc:datafield[@tag=656]">
+		<subject>
+			<xsl:if test="marc:subfield[@code=2]">
+				<xsl:attribute name="authority">
+					<xsl:value-of select="marc:subfield[@code=2]"></xsl:value-of>
+				</xsl:attribute>
+			</xsl:if>
+			<xsl:call-template name="uri" />
+			<occupation>
+				<xsl:call-template name="chopPunctuation">
+					<xsl:with-param name="chopString">
+						<xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
+					</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">
+				<xsl:call-template name="chopPunctuation">
+					<xsl:with-param name="chopString">
+						<xsl:call-template name="subfieldSelect">
+							<xsl:with-param name="codes">bc</xsl:with-param>
+						</xsl:call-template>
+					</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:value-of>
+			</xsl:attribute>
+		</xsl:if>
+		<xsl:if test="marc:subfield[@code='3']">
+			<xsl:attribute name="displayLabel">
+				<xsl:value-of select="marc:subfield[@code='3']"></xsl:value-of>
+			</xsl:attribute>
+		</xsl:if>
+	</xsl:template>
+	<xsl:template name="isInvalid">
+		<xsl:param name="type"/>
+		<xsl:if test="marc:subfield[@code='z'] or marc:subfield[@code='y']">
+			<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>
+			</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:param>
+		<xsl:attribute name="script">
+			<xsl:choose>
+				<xsl:when test="$scriptCode='(3'">Arabic</xsl:when>
+				<xsl:when test="$scriptCode='(B'">Latin</xsl:when>
+				<xsl:when test="$scriptCode='$1'">Chinese, Japanese, Korean</xsl:when>
+				<xsl:when test="$scriptCode='(N'">Cyrillic</xsl:when>
+				<xsl:when test="$scriptCode='(2'">Hebrew</xsl:when>
+				<xsl:when test="$scriptCode='(S'">Greek</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:value-of>
+				</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:value-of>
+					</xsl:if>
+					<xsl:if test="not(contains(text(),'&lt;'))">
+						<!-- 1 -->
+						<xsl:value-of select="text()"></xsl:value-of>
+					</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:value-of>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:value-of select="substring-after(text(),$level1)"></xsl:value-of>
+				</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:value-of>
+				</xsl:when>
+				<xsl:when test="contains($sici2,'&lt;')">
+					<!-- 1: 2<4 -->
+					<xsl:value-of select="substring-before($sici2,'&lt;')"></xsl:value-of>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:value-of select="$sici2"></xsl:value-of>
+					<!-- 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:value-of>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:value-of select="substring-after($sici2,$level2)"></xsl:value-of>
+				</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:value-of>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:value-of select="$sici3"></xsl:value-of>
+					<!-- 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:value-of>
+			</xsl:if>
+		</xsl:variable>
+		<xsl:if test="$level1">
+			<detail level="1">
+				<number>
+					<xsl:value-of select="$level1"></xsl:value-of>
+				</number>
+			</detail>
+		</xsl:if>
+		<xsl:if test="$level2">
+			<detail level="2">
+				<number>
+					<xsl:value-of select="$level2"></xsl:value-of>
+				</number>
+			</detail>
+		</xsl:if>
+		<xsl:if test="$level3">
+			<detail level="3">
+				<number>
+					<xsl:value-of select="$level3"></xsl:value-of>
+				</number>
+			</detail>
+		</xsl:if>
+		<xsl:if test="$page">
+			<extent unit="page">
+				<start>
+					<xsl:value-of select="$page"></xsl:value-of>
+				</start>
+			</extent>
+		</xsl:if>
+	</xsl:template>
+	<xsl:template name="getLanguage">
+		<xsl:param name="langString"></xsl:param>
+		<xsl:param name="controlField008-35-37"></xsl:param>
+		<xsl:variable name="length" select="string-length($langString)"></xsl:variable>
+		<xsl:choose>
+			<xsl:when test="$length=0"></xsl:when>
+			<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>
+					<xsl:with-param name="controlField008-35-37" select="$controlField008-35-37"></xsl:with-param>
+				</xsl:call-template>
+			</xsl:when>
+			<xsl:otherwise>
+				<language>
+					<languageTerm authority="iso639-2b" type="code">
+						<xsl:value-of select="substring($langString,1,3)"></xsl:value-of>
+					</languageTerm>
+				</language>
+				<xsl:call-template name="getLanguage">
+					<xsl:with-param name="langString" select="substring($langString,4,$length)"></xsl:with-param>
+					<xsl:with-param name="controlField008-35-37" select="$controlField008-35-37"></xsl:with-param>
+				</xsl:call-template>
+			</xsl:otherwise>
+		</xsl:choose>
+	</xsl:template>
+	<xsl:template name="isoLanguage">
+		<xsl:param name="currentLanguage"></xsl:param>
+		<xsl:param name="usedLanguages"></xsl:param>
+		<xsl:param name="remainingLanguages"></xsl:param>
+		<xsl:choose>
+			<xsl:when test="string-length($currentLanguage)=0"></xsl:when>
+			<xsl:when 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="iso639-2b" type="code">
+						<xsl:value-of select="$currentLanguage"></xsl:value-of>
+					</languageTerm>
+				</language>
+				<xsl:call-template name="isoLanguage">
+					<xsl:with-param name="currentLanguage">
+						<xsl:value-of select="substring($remainingLanguages,1,3)"></xsl:value-of>
+					</xsl:with-param>
+					<xsl:with-param name="usedLanguages">
+						<xsl:value-of select="concat($usedLanguages,$currentLanguage)"></xsl:value-of>
+					</xsl:with-param>
+					<xsl:with-param name="remainingLanguages">
+						<xsl:value-of select="substring($remainingLanguages,4,string-length($remainingLanguages))"></xsl:value-of>
+					</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:value-of>
+					</xsl:with-param>
+					<xsl:with-param name="usedLanguages">
+						<xsl:value-of select="concat($usedLanguages,$currentLanguage)"></xsl:value-of>
+					</xsl:with-param>
+					<xsl:with-param name="remainingLanguages">
+						<xsl:value-of select="substring($remainingLanguages,4,string-length($remainingLanguages))"></xsl:value-of>
+					</xsl:with-param>
+				</xsl:call-template>
+			</xsl:otherwise>
+		</xsl:choose>
+	</xsl:template>
+	<xsl:template name="chopBrackets">
+		<xsl:param name="chopString"></xsl:param>
+		<xsl:variable name="string">
+			<xsl:call-template name="chopPunctuation">
+				<xsl:with-param name="chopString" select="$chopString"></xsl:with-param>
+			</xsl:call-template>
+		</xsl:variable>
+		<xsl:if test="substring($string, 1,1)='['">
+			<xsl:value-of select="substring($string,2, string-length($string)-2)"></xsl:value-of>
+		</xsl:if>
+		<xsl:if test="substring($string, 1,1)!='['">
+			<xsl:value-of select="$string"></xsl:value-of>
+		</xsl:if>
+	</xsl:template>
+	<xsl:template name="rfcLanguages">
+		<xsl:param name="nodeNum"></xsl:param>
+		<xsl:param name="usedLanguages"></xsl:param>
+		<xsl:param name="controlField008-35-37"></xsl:param>
+		<xsl:variable name="currentLanguage" select="."></xsl:variable>
+		<xsl:choose>
+			<xsl:when test="not($currentLanguage)"></xsl:when>
+			<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>
+	<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"/>
+		<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:stylesheet>$$ WHERE name = 'mods32';
+
+
+-- 954.data.MODS33-xsl.sql
+UPDATE config.xml_transform SET xslt=$$<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:output encoding="UTF-8" indent="yes" method="xml"/>
+
+	<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>
+
+    <!-- Evergreen specific: revert Revision 1.23, so we can have those authority xlink attributes back. -->
+
+	<!--MARC21slim2MODS3-3.xsl
+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.9 - Subfield $y was added to field 242 2004/09/02 10:57 jrad
+Revision 1.8 - Subject chopPunctuation expanded and attribute fixes 2004/08/12 jrad
+Revision 1.7 - 2004/03/25 08:29 jrad
+Revision 1.6 - Various validation fixes 2004/02/20 ntra
+Revision 1.5 - MODS2 to MODS3 updates, language unstacking and de-duping, chopPunctuation expanded  2003/10/02 16:18:58  ntra
+Revision 1.3 - Additional Changes not related to MODS Version 2.0 by ntra
+Revision 1.2 - 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-2.xsd">
+					<xsl:for-each select="//marc:collection/marc:record">
+						<mods version="3.3">
+							<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.3"
+					xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.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="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>
+		<xsl:for-each select="marc:datafield[@tag='245']">
+			<titleInfo>
+				<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">afgk</xsl:with-param>
+							</xsl:call-template>
+						</xsl:when>
+						<xsl:otherwise>
+							<xsl:call-template name="subfieldSelect">
+								<xsl:with-param name="codes">abfgk</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>
+					<xsl:when test="@ind2&gt;0">
+						<nonSort>
+							<xsl:value-of select="substring($titleChop,1, at ind2)"/>
+						</nonSort>
+						<title>
+							<xsl:value-of select="substring($titleChop, at 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">afgk</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</subTitle>
+				</xsl:if>
+				<xsl:call-template name="part"/>
+			</titleInfo>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='210']">
+			<titleInfo type="abbreviated">
+				<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: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>
+				<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">a</xsl:with-param>
+							</xsl:call-template>
+						</xsl:with-param>
+					</xsl:call-template>
+				</title>
+				<!-- 1/04 fix -->
+				<xsl:call-template name="subtitle"/>
+				<xsl:call-template name="part"/>
+			</titleInfo>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='246']">
+			<titleInfo type="alternative">
+				<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:for-each>
+		<xsl:for-each
+			select="marc:datafield[@tag='130']|marc:datafield[@tag='240']|marc:datafield[@tag='730'][@ind2!='2']">
+			<titleInfo type="uniform">
+				<title>
+						<xsl:call-template name="uri"/>
+
+					<xsl:variable name="str">
+						<xsl:for-each select="marc:subfield">
+							<xsl:if
+								test="(contains('adfklmors', at 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:for-each>
+		<xsl:for-each select="marc:datafield[@tag='740'][@ind2!='2']">
+			<titleInfo type="alternative">
+				<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:for-each>
+		<xsl:for-each select="marc:datafield[@tag='100']">
+			<name type="personal">
+
+				<xsl:call-template name="uri"/>
+
+				<xsl:call-template name="nameABCDQ"/>
+				<xsl:call-template name="affiliation"/>
+				<role>
+					<roleTerm authority="marcrelator" type="text">creator</roleTerm>
+				</role>
+				<xsl:call-template name="role"/>
+			</name>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='110']">
+			<name type="corporate">
+
+					<xsl:call-template name="uri"/>
+
+				<xsl:call-template name="nameABCDN"/>
+				<role>
+					<roleTerm authority="marcrelator" type="text">creator</roleTerm>
+				</role>
+				<xsl:call-template name="role"/>
+			</name>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='111']">
+			<name type="conference">
+
+					<xsl:call-template name="uri"/>
+
+				<xsl:call-template name="nameACDEQ"/>
+				<role>
+					<roleTerm authority="marcrelator" type="text">creator</roleTerm>
+				</role>
+				<xsl:call-template name="role"/>
+			</name>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='700'][not(marc:subfield[@code='t'])]">
+			<name type="personal">
+
+					<xsl:call-template name="uri"/>
+
+				<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="uri"/>
+
+				<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="uri"/>
+
+				<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>
+
+		<!-- 1.20 047 genre tmee-->
+
+		<xsl:for-each select="marc:datafield[@tag=047]">
+			<genre authority="marcgt">
+				<xsl:attribute name="authority">
+					<xsl:value-of select="marc:subfield[@code='2']"/>
+				</xsl:attribute>
+				<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:for-each>
+		<xsl:for-each select="marc:datafield[@tag=655]">
+			<genre authority="marcgt">
+				<xsl:attribute name="authority">
+					<xsl:value-of select="marc:subfield[@code='2']"/>
+				</xsl:attribute>
+				<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:for-each>
+		<originInfo>
+			<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>
+			<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'">
+						<dateIssued>
+							<xsl:call-template name="chopPunctuation">
+								<xsl:with-param name="chopString" select="."/>
+							</xsl:call-template>
+						</dateIssued>
+					</xsl:when>
+					<xsl:when test="@code='g'">
+						<dateCreated>
+							<xsl:value-of select="."/>
+						</dateCreated>
+					</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))"/>
+			<xsl:if
+				test="$controlField008-6='e' or $controlField008-6='p' or $controlField008-6='r' or $controlField008-6='t' or $controlField008-6='s'">
+				<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='q' 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='q' 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: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">
+				<issuance>
+					<xsl:choose>
+						<xsl:when
+							test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'"
+							>monographic</xsl:when>
+						<xsl:when test="$leader7='b' or $leader7='i' or $leader7='s'"
+						>continuing</xsl:when>
+					</xsl:choose>
+				</issuance>
+			</xsl:for-each>
+			<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>
+		</originInfo>
+		<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>
+		<xsl:variable name="physicalDescription">
+			<!--3.2 change tmee 007/11 -->
+			<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: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="($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>
+			<!-- 1/04 fix -->
+			<xsl:if test="marc:datafield[@tag=130]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=130]/marc:subfield[@code='h']"
+							/>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:if test="marc:datafield[@tag=240]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=240]/marc:subfield[@code='h']"
+							/>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:if test="marc:datafield[@tag=242]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=242]/marc:subfield[@code='h']"
+							/>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:if test="marc:datafield[@tag=245]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=245]/marc:subfield[@code='h']"
+							/>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:if test="marc:datafield[@tag=246]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=246]/marc:subfield[@code='h']"
+							/>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:if test="marc:datafield[@tag=730]/marc:subfield[@code='h']">
+				<form authority="gmd">
+					<xsl:call-template name="chopBrackets">
+						<xsl:with-param name="chopString">
+							<xsl:value-of select="marc:datafield[@tag=730]/marc:subfield[@code='h']"
+							/>
+						</xsl:with-param>
+					</xsl:call-template>
+				</form>
+			</xsl:if>
+			<xsl:for-each select="marc:datafield[@tag=256]/marc:subfield[@code='a']">
+				<form>
+					<xsl:value-of select="."/>
+				</form>
+			</xsl:for-each>
+			<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>
+			<!--3.2 change tmee 007/01 -->
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='b']">
+				<form authority="smd">chip cartridge</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='c']">
+				<form authority="smd">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="smd">magnetic disc</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='m']">
+				<form authority="smd">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="smd">optical disc</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='r']">
+				<form authority="smd">remote</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='a']">
+				<form authority="smd">tape cartridge</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='f']">
+				<form authority="smd">tape cassette</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='h']">
+				<form authority="smd">tape reel</form>
+			</xsl:if>
+
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='a']">
+				<form authority="smd">celestial globe</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='e']">
+				<form authority="smd">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="smd">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="smd">terrestrial globe</form>
+			</xsl:if>
+
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='o'][substring(text(),2,1)='o']">
+				<form authority="smd">kit</form>
+			</xsl:if>
+
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
+				<form authority="smd">atlas</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='g']">
+				<form authority="smd">diagram</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='j']">
+				<form authority="smd">map</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
+				<form authority="smd">model</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='k']">
+				<form authority="smd">profile</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
+				<form authority="smd">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="smd">section</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='y']">
+				<form authority="smd">view</form>
+			</xsl:if>
+
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='a']">
+				<form authority="smd">aperture card</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='e']">
+				<form authority="smd">microfiche</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='f']">
+				<form authority="smd">microfiche cassette</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='b']">
+				<form authority="smd">microfilm cartridge</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='c']">
+				<form authority="smd">microfilm cassette</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='d']">
+				<form authority="smd">microfilm reel</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='g']">
+				<form authority="smd">microopaque</form>
+			</xsl:if>
+
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='c']">
+				<form authority="smd">film cartridge</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='f']">
+				<form authority="smd">film cassette</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='r']">
+				<form authority="smd">film reel</form>
+			</xsl:if>
+
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='n']">
+				<form authority="smd">chart</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='c']">
+				<form authority="smd">collage</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='d']">
+				<form authority="smd">drawing</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='o']">
+				<form authority="smd">flash card</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='e']">
+				<form authority="smd">painting</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='f']">
+				<form authority="smd">photomechanical print</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='g']">
+				<form authority="smd">photonegative</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='h']">
+				<form authority="smd">photoprint</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='i']">
+				<form authority="smd">picture</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='j']">
+				<form authority="smd">print</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='l']">
+				<form authority="smd">technical drawing</form>
+			</xsl:if>
+
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='q'][substring(text(),2,1)='q']">
+				<form authority="smd">notated music</form>
+			</xsl:if>
+
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='d']">
+				<form authority="smd">filmslip</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='c']">
+				<form authority="smd">filmstrip cartridge</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='o']">
+				<form authority="smd">filmstrip roll</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='f']">
+				<form authority="smd">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="smd">slide</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='t']">
+				<form authority="smd">transparency</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='r'][substring(text(),2,1)='r']">
+				<form authority="smd">remote-sensing image</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='e']">
+				<form authority="smd">cylinder</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='q']">
+				<form authority="smd">roll</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='g']">
+				<form authority="smd">sound cartridge</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='s']">
+				<form authority="smd">sound cassette</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='d']">
+				<form authority="smd">sound disc</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='t']">
+				<form authority="smd">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="smd">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="smd">wire recording</form>
+			</xsl:if>
+
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='c']">
+				<form authority="smd">braille</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='b']">
+				<form authority="smd">combination</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='a']">
+				<form authority="smd">moon</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='d']">
+				<form authority="smd">tactile, with no writing system</form>
+			</xsl:if>
+
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='c']">
+				<form authority="smd">braille</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='b']">
+				<form authority="smd">large print</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='a']">
+				<form authority="smd">regular print</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='d']">
+				<form authority="smd">text in looseleaf binder</form>
+			</xsl:if>
+
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='c']">
+				<form authority="smd">videocartridge</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='f']">
+				<form authority="smd">videocassette</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='d']">
+				<form authority="smd">videodisc</form>
+			</xsl:if>
+			<xsl:if
+				test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='r']">
+				<form authority="smd">videoreel</form>
+			</xsl:if>
+
+			<xsl:for-each
+				select="marc:datafield[@tag=856]/marc:subfield[@code='q'][string-length(.)&gt;1]">
+				<internetMediaType>
+					<xsl:value-of select="."/>
+				</internetMediaType>
+			</xsl:for-each>
+			<xsl:for-each select="marc:datafield[@tag=300]">
+				<extent>
+					<xsl:call-template name="subfieldSelect">
+						<xsl:with-param name="codes">abce</xsl:with-param>
+					</xsl:call-template>
+				</extent>
+			</xsl:for-each>
+		</xsl:variable>
+		<xsl:if test="string-length(normalize-space($physicalDescription))">
+			<physicalDescription>
+				<xsl:copy-of select="$physicalDescription"/>
+			</physicalDescription>
+		</xsl:if>
+		<xsl:for-each select="marc:datafield[@tag=520]">
+			<abstract>
+				<xsl:call-template name="uri"/>
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</abstract>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=505]">
+			<tableOfContents>
+				<xsl:call-template name="uri"/>
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">agrt</xsl:with-param>
+				</xsl:call-template>
+			</tableOfContents>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=521]">
+			<targetAudience>
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</targetAudience>
+		</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>
+		<xsl:for-each select="marc:datafield[@tag=245]/marc:subfield[@code='c']">
+			<note type="statement of responsibility">
+				<xsl:value-of select="."/>
+			</note>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=500]">
+			<note>
+				<xsl:value-of select="marc:subfield[@code='a']"/>
+				<xsl:call-template name="uri"/>
+			</note>
+		</xsl:for-each>
+
+		<!--3.2 change tmee additional note fields-->
+
+		<xsl:for-each select="marc:datafield[@tag=506]">
+			<note type="restrictions">
+				<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>
+
+		<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>
+
+
+		<xsl:for-each select="marc:datafield[@tag=511]">
+			<note type="performers">
+				<xsl:call-template name="uri"/>
+				<xsl:value-of select="marc:subfield[@code='a']"/>
+			</note>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=518]">
+			<note type="venue">
+				<xsl:call-template name="uri"/>
+				<xsl:value-of select="marc:subfield[@code='a']"/>
+			</note>
+		</xsl:for-each>
+
+		<xsl:for-each select="marc:datafield[@tag=530]">
+			<note type="additional physical form">
+				<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>
+
+		<xsl:for-each select="marc:datafield[@tag=533]">
+			<note type="reproduction">
+				<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>
+
+		<xsl:for-each select="marc:datafield[@tag=534]">
+			<note type="original version">
+				<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>
+
+		<xsl:for-each select="marc:datafield[@tag=538]">
+			<note type="system details">
+				<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>
+
+		<xsl:for-each select="marc:datafield[@tag=583]">
+			<note type="action">
+				<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>
+
+		<xsl:for-each
+			select="marc:datafield[@tag=501 or @tag=502 or @tag=504 or @tag=507 or @tag=508 or  @tag=513 or @tag=514 or @tag=515 or @tag=516 or @tag=522 or @tag=524 or @tag=525 or @tag=526 or @tag=535 or @tag=536 or @tag=540 or @tag=541 or @tag=544 or @tag=545 or @tag=546 or @tag=547 or @tag=550 or @tag=552 or @tag=555 or @tag=556 or @tag=561 or @tag=562 or @tag=565 or @tag=567 or @tag=580 or @tag=581 or @tag=584 or @tag=585 or @tag=586]">
+			<note>
+				<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>
+		<xsl:for-each
+			select="marc:datafield[@tag=034][marc:subfield[@code='d' or @code='e' or @code='f' or @code='g']]">
+			<subject>
+				<cartographics>
+					<coordinates>
+						<xsl:call-template name="subfieldSelect">
+							<xsl:with-param name="codes">defg</xsl:with-param>
+						</xsl:call-template>
+					</coordinates>
+				</cartographics>
+			</subject>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=043]">
+			<subject>
+				<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:for-each>
+		<!-- tmee 2006/11/27 -->
+		<xsl:for-each select="marc:datafield[@tag=255]">
+			<subject>
+				<xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
+					<cartographics>
+						<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>
+					</cartographics>
+				</xsl:for-each>
+			</subject>
+		</xsl:for-each>
+
+		<xsl:apply-templates select="marc:datafield[653 &gt;= @tag and @tag &gt;= 600]"/>
+		<xsl:apply-templates select="marc:datafield[@tag=656]"/>
+		<xsl:for-each select="marc:datafield[@tag=752 or @tag=662]">
+			<subject>
+				<hierarchicalGeographic>
+					<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']">
+						<region>
+							<xsl:call-template name="chopPunctuation">
+								<xsl:with-param name="chopString" select="."/>
+							</xsl:call-template>
+						</region>
+					</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:for-each>
+		<xsl:for-each select="marc:datafield[@tag=045][marc:subfield[@code='b']]">
+			<subject>
+				<xsl:choose>
+					<xsl:when test="@ind1=2">
+						<temporal encoding="iso8601" point="start">
+							<xsl:call-template name="chopPunctuation">
+								<xsl:with-param name="chopString">
+									<xsl:value-of select="marc:subfield[@code='b'][1]"/>
+								</xsl:with-param>
+							</xsl:call-template>
+						</temporal>
+						<temporal encoding="iso8601" point="end">
+							<xsl:call-template name="chopPunctuation">
+								<xsl:with-param name="chopString">
+									<xsl:value-of select="marc:subfield[@code='b'][2]"/>
+								</xsl:with-param>
+							</xsl:call-template>
+						</temporal>
+					</xsl:when>
+					<xsl:otherwise>
+						<xsl:for-each select="marc:subfield[@code='b']">
+							<temporal encoding="iso8601">
+								<xsl:call-template name="chopPunctuation">
+									<xsl:with-param name="chopString" select="."/>
+								</xsl:call-template>
+							</temporal>
+						</xsl:for-each>
+					</xsl:otherwise>
+				</xsl:choose>
+			</subject>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=050]">
+			<xsl:for-each select="marc:subfield[@code='b']">
+				<classification authority="lcc">
+					<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: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:for-each>
+		<xsl:for-each select="marc:datafield[@tag=082]">
+			<classification authority="ddc">
+				<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:for-each>
+		<xsl:for-each select="marc:datafield[@tag=080]">
+			<classification authority="udc">
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">abx</xsl:with-param>
+				</xsl:call-template>
+			</classification>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=060]">
+			<classification authority="nlm">
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</classification>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=086][@ind1=0]">
+			<classification authority="sudocs">
+				<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:value-of select="marc:subfield[@code='a']"/>
+			</classification>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=086]">
+			<classification>
+				<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:for-each select="marc:datafield[@tag=084]">
+			<classification>
+				<xsl:attribute name="authority">
+					<xsl:value-of select="marc:subfield[@code='2']"/>
+				</xsl:attribute>
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</classification>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=440]">
+			<relatedItem type="series">
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="subfieldSelect">
+									<xsl:with-param name="codes">av</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="part"/>
+				</titleInfo>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=490][@ind1=0]">
+			<relatedItem type="series">
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="subfieldSelect">
+									<xsl:with-param name="codes">av</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="part"/>
+				</titleInfo>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=510]">
+			<relatedItem type="isReferencedBy">
+				<note>
+					<xsl:call-template name="subfieldSelect">
+						<xsl:with-param name="codes">abcx3</xsl:with-param>
+					</xsl:call-template>
+				</note>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=534]">
+			<relatedItem type="original">
+				<xsl:call-template name="relatedTitle"/>
+				<xsl:call-template name="relatedName"/>
+				<xsl:if test="marc:subfield[@code='b' or @code='c']">
+					<originInfo>
+						<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>
+				<xsl:call-template name="relatedIdentifierISSN"/>
+				<xsl:for-each select="marc:subfield[@code='z']">
+					<identifier type="isbn">
+						<xsl:value-of select="."/>
+					</identifier>
+				</xsl:for-each>
+				<xsl:call-template name="relatedNote"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=700][marc:subfield[@code='t']]">
+			<relatedItem>
+				<xsl:call-template name="constituentOrRelatedType"/>
+				<titleInfo>
+					<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">
+					<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"/>
+				<xsl:call-template name="relatedIdentifierISSN"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=710][marc:subfield[@code='t']]">
+			<relatedItem>
+				<xsl:call-template name="constituentOrRelatedType"/>
+				<titleInfo>
+					<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">dg</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="relatedPartNumName"/>
+				</titleInfo>
+				<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: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"/>
+				<xsl:call-template name="relatedIdentifierISSN"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=711][marc:subfield[@code='t']]">
+			<relatedItem>
+				<xsl:call-template name="constituentOrRelatedType"/>
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="specialSubfieldSelect">
+									<xsl:with-param name="anyCodes">tfklsv</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="relatedPartNumName"/>
+				</titleInfo>
+				<name type="conference">
+					<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>
+				</name>
+				<xsl:call-template name="relatedForm"/>
+				<xsl:call-template name="relatedIdentifierISSN"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=730][@ind2=2]">
+			<relatedItem>
+				<xsl:call-template name="constituentOrRelatedType"/>
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="subfieldSelect">
+									<xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="part"/>
+				</titleInfo>
+				<xsl:call-template name="relatedForm"/>
+				<xsl:call-template name="relatedIdentifierISSN"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=740][@ind2=2]">
+			<relatedItem>
+				<xsl:call-template name="constituentOrRelatedType"/>
+				<titleInfo>
+					<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"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=760]|marc:datafield[@tag=762]">
+			<relatedItem type="series">
+				<xsl:call-template name="relatedItem76X-78X"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each
+			select="marc:datafield[@tag=765]|marc:datafield[@tag=767]|marc:datafield[@tag=777]|marc:datafield[@tag=787]">
+			<relatedItem>
+				<xsl:call-template name="relatedItem76X-78X"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=775]">
+			<relatedItem type="otherVersion">
+				<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">
+				<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">
+				<xsl:call-template name="relatedItem76X-78X"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=776]">
+			<relatedItem type="otherFormat">
+				<xsl:call-template name="relatedItem76X-78X"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=780]">
+			<relatedItem type="preceding">
+				<xsl:call-template name="relatedItem76X-78X"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=785]">
+			<relatedItem type="succeeding">
+				<xsl:call-template name="relatedItem76X-78X"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=786]">
+			<relatedItem type="original">
+				<xsl:call-template name="relatedItem76X-78X"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=800]">
+			<relatedItem type="series">
+				<titleInfo>
+					<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">
+					<namePart>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<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>
+							</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"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=810]">
+			<relatedItem type="series">
+				<titleInfo>
+					<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">dg</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="relatedPartNumName"/>
+				</titleInfo>
+				<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>
+					<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"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=811]">
+			<relatedItem type="series">
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="specialSubfieldSelect">
+									<xsl:with-param name="anyCodes">tfklsv</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="relatedPartNumName"/>
+				</titleInfo>
+				<name type="conference">
+					<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"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='830']">
+			<relatedItem type="series">
+				<titleInfo>
+					<title>
+						<xsl:call-template name="chopPunctuation">
+							<xsl:with-param name="chopString">
+								<xsl:call-template name="subfieldSelect">
+									<xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
+								</xsl:call-template>
+							</xsl:with-param>
+						</xsl:call-template>
+					</title>
+					<xsl:call-template name="part"/>
+				</titleInfo>
+				<xsl:call-template name="relatedForm"/>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='856'][@ind2='2']/marc:subfield[@code='q']">
+			<relatedItem>
+				<internetMediaType>
+					<xsl:value-of select="."/>
+				</internetMediaType>
+			</relatedItem>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='020']">
+			<xsl:call-template name="isInvalid">
+				<xsl:with-param name="type">isbn</xsl:with-param>
+			</xsl:call-template>
+			<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='024'][@ind1='0']">
+			<xsl:call-template name="isInvalid">
+				<xsl:with-param name="type">isrc</xsl:with-param>
+			</xsl:call-template>
+			<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:call-template name="isInvalid">
+				<xsl:with-param name="type">ismn</xsl:with-param>
+			</xsl:call-template>
+			<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']">
+			<xsl:call-template name="isInvalid">
+				<xsl:with-param name="type">sici</xsl:with-param>
+			</xsl:call-template>
+			<identifier type="sici">
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</identifier>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='022']">
+			<xsl:if test="marc:subfield[@code='a']">
+				<xsl:call-template name="isInvalid">
+					<xsl:with-param name="type">issn</xsl:with-param>
+				</xsl:call-template>
+				<identifier type="issn">
+					<xsl:value-of select="marc:subfield[@code='a']"/>
+				</identifier>
+			</xsl:if>
+			<xsl:if test="marc:subfield[@code='l']">
+				<xsl:call-template name="isInvalid">
+					<xsl:with-param name="type">issn-l</xsl:with-param>
+				</xsl:call-template>
+				<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='010']">
+			<xsl:call-template name="isInvalid">
+				<xsl:with-param name="type">lccn</xsl:with-param>
+			</xsl:call-template>
+			<identifier type="lccn">
+				<xsl:value-of select="normalize-space(marc:subfield[@code='a'])"/>
+			</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="isInvalid"/>-->
+				<!-- no $z in 028 -->
+				<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='037']">
+			<identifier type="stock number">
+				<!--<xsl:call-template name="isInvalid"/>-->
+				<!-- no $z in 037 -->
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">ab</xsl:with-param>
+				</xsl:call-template>
+			</identifier>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag='856'][marc:subfield[@code='u']]">
+			<identifier>
+				<xsl:attribute name="type">
+					<xsl:choose>
+						<xsl:when
+							test="starts-with(marc:subfield[@code='u'],'urn:doi') or starts-with(marc:subfield[@code='u'],'doi')"
+							>doi</xsl:when>
+						<xsl:when
+							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:when>
+						<xsl:otherwise>uri</xsl:otherwise>
+					</xsl:choose>
+				</xsl:attribute>
+				<xsl:choose>
+					<xsl:when
+						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') ">
+						<xsl:value-of
+							select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"
+						/>
+					</xsl:when>
+					<xsl:otherwise>
+						<xsl:value-of select="marc:subfield[@code='u']"/>
+					</xsl:otherwise>
+				</xsl:choose>
+			</identifier>
+			<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:call-template name="isInvalid"/>
+				<xsl:value-of select="marc:subfield[@code='a']"/>
+			</identifier>
+		</xsl:for-each>
+
+		<!-- 1/04 fix added $y -->
+
+		<!-- 1.21  tmee-->
+		<xsl:for-each select="marc:datafield[@tag=856][@ind2=1][marc:subfield[@code='u']]">
+			<relatedItem type="otherVersion">
+				<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:for-each>
+		<xsl:for-each select="marc:datafield[@tag=856][@ind2=2][marc:subfield[@code='u']]">
+			<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:for-each>
+
+		<!-- 3.2 change tmee 856z  -->
+
+		<!-- 1.24  tmee  -->
+		<xsl:for-each select="marc:datafield[@tag=852]">
+			<location>
+				<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>
+
+				<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']">
+					<shelfLocation>
+						<xsl:call-template name="subfieldSelect">
+							<xsl:with-param name="codes">hijklmt</xsl:with-param>
+						</xsl:call-template>
+					</shelfLocation>
+				</xsl:if>
+			</location>
+		</xsl:for-each>
+
+		<xsl:for-each select="marc:datafield[@tag=506]">
+			<accessCondition type="restrictionOnAccess">
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">abcd35</xsl:with-param>
+				</xsl:call-template>
+			</accessCondition>
+		</xsl:for-each>
+		<xsl:for-each select="marc:datafield[@tag=540]">
+			<accessCondition type="useAndReproduction">
+				<xsl:call-template name="subfieldSelect">
+					<xsl:with-param name="codes">abcde35</xsl:with-param>
+				</xsl:call-template>
+			</accessCondition>
+		</xsl:for-each>
+
+		<recordInfo>
+			<!-- 1.25  tmee-->
+
+
+			<xsl:for-each select="marc:leader[substring($leader,19,1)='a']">
+				<descriptionStandard>aacr2</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>
+			<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']">
+			<xsl:attribute name="xlink:href">
+				<xsl:value-of select="."/>
+			</xsl:attribute>
+		</xsl:for-each>
+		<xsl:for-each select="marc:subfield[@code='0']">
+			<xsl:choose>
+				<xsl:when test="contains(text(), ')')">
+					<xsl:attribute name="xlink:href">
+						<xsl:value-of select="substring-after(text(), ')')"></xsl:value-of>
+					</xsl:attribute>
+				</xsl:when>
+				<xsl:otherwise>
+					<xsl:attribute name="xlink:href">
+						<xsl:value-of select="."></xsl:value-of>
+					</xsl:attribute>
+				</xsl:otherwise>
+			</xsl:choose>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="role">
+		<xsl:for-each select="marc:subfield[@code='e']">
+			<role>
+				<roleTerm type="text">
+					<xsl:value-of select="."/>
+				</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: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: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>
+	<xsl:template name="relatedPart">
+		<xsl:if test="@tag=773">
+			<xsl:for-each select="marc:subfield[@code='g']">
+				<part>
+					<text>
+						<xsl:value-of select="."/>
+					</text>
+				</part>
+			</xsl:for-each>
+			<xsl:for-each select="marc:subfield[@code='q']">
+				<part>
+					<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>
+	<xsl:template name="relatedName">
+		<xsl:for-each select="marc:subfield[@code='a']">
+			<name>
+				<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>
+				<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>
+				<extent>
+					<xsl:value-of select="."/>
+				</extent>
+			</physicalDescription>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="relatedNote">
+		<xsl:for-each select="marc:subfield[@code='n']">
+			<note>
+				<xsl:value-of select="."/>
+			</note>
+		</xsl:for-each>
+	</xsl:template>
+	<xsl:template name="relatedSubject">
+		<xsl:for-each select="marc:subfield[@code='j']">
+			<subject>
+				<temporal encoding="iso8601">
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString" select="."/>
+					</xsl:call-template>
+				</temporal>
+			</subject>
+		</xsl:for-each>
+	</xsl:template>
+	<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>
+	<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>
+				<xsl:call-template name="chopPunctuation">
+					<xsl:with-param name="chopString" select="."/>
+				</xsl:call-template>
+			</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>
+			<xsl:call-template name="chopPunctuation">
+				<xsl:with-param name="chopString">
+					<xsl:call-template name="subfieldSelect">
+						<xsl:with-param name="codes">aq</xsl:with-param>
+					</xsl:call-template>
+				</xsl:with-param>
+				<xsl:with-param name="punctuation">
+					<xsl:text>:,;/ </xsl:text>
+				</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>
+	<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>
+				<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>
+				<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="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
+					<xsl:call-template name="relatedPartNumName"/>
+				</xsl:if>
+			</titleInfo>
+		</xsl:for-each>
+		<xsl:for-each select="marc:subfield[@code='p']">
+			<titleInfo type="abbreviated">
+				<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="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
+					<xsl:call-template name="relatedPartNumName"/>
+				</xsl:if>
+			</titleInfo>
+		</xsl:for-each>
+		<xsl:for-each select="marc:subfield[@code='s']">
+			<titleInfo type="uniform">
+				<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="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
+					<xsl:call-template name="relatedPartNumName"/>
+				</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>
+	<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">
+				<xsl:call-template name="chopPunctuation">
+					<xsl:with-param name="chopString" select="."/>
+				</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>
+	<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, at code) and following-sibling::marc:subfield[@code=$axis])      or (contains($afterCodes, at 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>
+
+	<!-- 3.2 change tmee 6xx $v genre -->
+	<xsl:template match="marc:datafield[@tag=600]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"/>
+			<name type="personal">
+				<xsl:call-template name="termsOfAddress"/>
+				<namePart>
+					<xsl:call-template name="chopPunctuation">
+						<xsl:with-param name="chopString">
+							<xsl:call-template name="subfieldSelect">
+								<xsl:with-param name="codes">aq</xsl:with-param>
+							</xsl:call-template>
+						</xsl:with-param>
+					</xsl:call-template>
+				</namePart>
+				<xsl:call-template name="nameDate"/>
+				<xsl:call-template name="affiliation"/>
+				<xsl:call-template name="role"/>
+			</name>
+			<xsl:call-template name="subjectAnyOrder"/>
+		</subject>
+	</xsl:template>
+	<xsl:template match="marc:datafield[@tag=610]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"/>
+			<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:call-template name="subjectAnyOrder"/>
+		</subject>
+	</xsl:template>
+	<xsl:template match="marc:datafield[@tag=611]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"/>
+			<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:call-template name="subjectAnyOrder"/>
+		</subject>
+	</xsl:template>
+	<xsl:template match="marc:datafield[@tag=630]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"/>
+			<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>
+	<!-- 1.27 648 tmee-->
+	<xsl:template match="marc:datafield[@tag=648]">
+		<subject>
+			<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 match="marc:datafield[@tag=650]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"/>
+			<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 match="marc:datafield[@tag=651]">
+		<subject>
+			<xsl:call-template name="subjectAuthority"/>
+			<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 match="marc:datafield[@tag=653]">
+		<subject>
+			<xsl:for-each select="marc:subfield[@code='a']">
+				<topic>
+					<xsl:value-of select="."/>
+				</topic>
+			</xsl:for-each>
+		</subject>
+	</xsl:template>
+	<xsl:template match="marc:datafield[@tag=656]">
+		<subject>
+			<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">
+				<xsl:call-template name="chopPunctuation">
+					<xsl:with-param name="chopString">
+						<xsl:call-template name="subfieldSelect">
+							<xsl:with-param name="codes">bc</xsl:with-param>
+						</xsl:call-template>
+					</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>
+	<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>
+				<xsl:when test="$scriptCode='(3'">Arabic</xsl:when>
+				<xsl:when test="$scriptCode='(B'">Latin</xsl:when>
+				<xsl:when test="$scriptCode='$1'">Chinese, Japanese, Korean</xsl:when>
+				<xsl:when test="$scriptCode='(N'">Cyrillic</xsl:when>
+				<xsl:when test="$scriptCode='(2'">Hebrew</xsl:when>
+				<xsl:when test="$scriptCode='(S'">Greek</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>
+								<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="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>
+
+    <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>$$ WHERE name = 'mods33';
+
+COMMIT;

commit 3eb616e56c82a5106e14f5a446f1d875015db7f0
Author: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
Date:   Fri Mar 22 17:11:50 2013 -0400

    Inter-authority linking
    
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>

diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml
index 5053070..a439d6d 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -2119,6 +2119,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 			<field reporter:label="Non-filing Indicator" name="nfi" reporter:datatype="text" />
 			<field reporter:label="Name" name="name" reporter:datatype="text" oils_persist:i18n="true" oils_obj:required="true" />
 			<field reporter:label="Description" name="description" reporter:datatype="text" oils_persist:i18n="true" />
+			<field reporter:label="Linking Subfield" name="linking_subfield" reporter:datatype="text" />
 			<field reporter:label="Subordinate Entries" name="sub_entries" reporter:datatype="link" oils_persist:virtual="true"/>
 			<field reporter:label="Controlled Bib Fields" name="bib_fields" reporter:datatype="link" oils_persist:virtual="true"/>
 			<field reporter:label="Thesauri" name="thesauri" reporter:datatype="link" oils_persist:virtual="true"/>
diff --git a/Open-ILS/src/sql/Pg/011.schema.authority.sql b/Open-ILS/src/sql/Pg/011.schema.authority.sql
index 0d0e308..6d4fb50 100644
--- a/Open-ILS/src/sql/Pg/011.schema.authority.sql
+++ b/Open-ILS/src/sql/Pg/011.schema.authority.sql
@@ -36,7 +36,8 @@ CREATE TABLE authority.control_set_authority_field (
     nfi         CHAR(1),          -- non-filing indicator
     sf_list     TEXT    NOT NULL,
     name        TEXT    NOT NULL, -- i18n
-    description TEXT              -- i18n
+    description TEXT,             -- i18n
+    linking_subfield CHAR(1)
 );
 
 CREATE TABLE authority.control_set_bib_field (
@@ -86,6 +87,13 @@ CREATE TRIGGER a_marcxml_is_well_formed BEFORE INSERT OR UPDATE ON authority.rec
 CREATE TRIGGER b_maintain_901 BEFORE INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE evergreen.maintain_901();
 CREATE TRIGGER c_maintain_control_numbers BEFORE INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE maintain_control_numbers();
 
+CREATE TABLE authority.authority_linking (
+    id      BIGSERIAL PRIMARY KEY,
+    source  BIGINT REFERENCES authority.record_entry (id) NOT NULL,
+    target  BIGINT REFERENCES authority.record_entry (id) NOT NULL,
+    field   INT REFERENCES authority.control_set_authority_field (id) NOT NULL
+);
+
 CREATE TABLE authority.bib_linking (
     id          BIGSERIAL   PRIMARY KEY,
     bib         BIGINT      NOT NULL REFERENCES biblio.record_entry (id),
@@ -270,6 +278,11 @@ BEGIN
 
     res.record := auth_id;
 
+    -- XXX this SELECT control_set... business below should actually only
+    -- be a fallback.  We should (SELECT control_set FROM authority.record_entry
+    -- WHERE id = auth_id) when we have an auth_id, and use that if we can get
+    -- it.
+
     SELECT  control_set INTO cset
       FROM  authority.control_set_authority_field
       WHERE tag IN ( SELECT UNNEST(XPATH('//*[starts-with(@tag,"1")]/@tag',marcxml::XML)::TEXT[]) )
diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
index 2ec5f9b..1aa746c 100644
--- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql
+++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
@@ -10392,6 +10392,10 @@ INSERT INTO authority.control_set_authority_field (id, control_set, main_entry,
     (71, 1, 11, '485', 'ivwxyz4', oils_i18n_gettext('71','See From Tracing -- Form Subdivision','acsaf','name')),
     (72, 1, 12, '448', 'aivwxyz4', oils_i18n_gettext('72','See From Tracing -- Chronological Term','acsaf','name'));
 
+UPDATE authority.control_set_authority_field
+    SET linking_subfield = '0' WHERE main_entry IS NOT NULL;
+
+
 INSERT INTO authority.browse_axis (code,name,description,sorter) VALUES
     ('title','Title','Title axis','titlesort'),
     ('author','Author','Author axis','titlesort'),
diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql
index c3f1533..404480f 100644
--- a/Open-ILS/src/sql/Pg/999.functions.global.sql
+++ b/Open-ILS/src/sql/Pg/999.functions.global.sql
@@ -1520,6 +1520,61 @@ BEGIN
 END;
 $func$ LANGUAGE PLPGSQL;
 
+-- Given an authority record's ID, control set ID (if known), and marc::XML,
+-- return all links to other authority records in the form of rows that
+-- can be inserted into authority.authority_linking.
+CREATE OR REPLACE FUNCTION authority.calculate_authority_linking(
+    rec_id BIGINT, rec_control_set INT, rec_marc_xml XML
+) RETURNS SETOF authority.authority_linking AS $func$
+DECLARE
+    acsaf       authority.control_set_authority_field%ROWTYPE;
+    link        TEXT;
+    aal         authority.authority_linking%ROWTYPE;
+BEGIN
+    IF rec_control_set IS NULL THEN
+        -- No control_set on record?  Guess at one
+        SELECT control_set INTO rec_control_set
+            FROM authority.control_set_authority_field
+            WHERE tag IN (
+                SELECT UNNEST(
+                    XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc::XML)::TEXT[]
+                )
+            ) LIMIT 1;
+
+        IF NOT FOUND THEN
+            RAISE WARNING 'Could not even guess at control set for authority record %', rec_id;
+            RETURN;
+        END IF;
+    END IF;
+
+    aal.source := rec_id;
+
+    FOR acsaf IN
+        SELECT * FROM authority.control_set_authority_field
+        WHERE control_set = rec_control_set
+            AND linking_subfield IS NOT NULL
+            AND main_entry IS NOT NULL
+    LOOP
+        link := SUBSTRING(
+            (XPATH('//*[@tag="' || acsaf.tag || '"]/*[@code="' ||
+                acsaf.linking_subfield || '"]/text()', rec_marc_xml))[1]::TEXT,
+            '\d+$'
+        );
+
+        -- Ignore links that are null, malformed, circular, or point to
+        -- non-existent authority records.
+        IF link IS NOT NULL AND link::BIGINT <> rec_id THEN
+            PERFORM * FROM authority.record_entry WHERE id = link::BIGINT;
+            IF FOUND THEN
+                aal.target := link::BIGINT;
+                aal.field := acsaf.id;
+                RETURN NEXT aal;
+            END IF;
+        END IF;
+    END LOOP;
+END;
+$func$ LANGUAGE PLPGSQL;
+
 -- AFTER UPDATE OR INSERT trigger for authority.record_entry
 CREATE OR REPLACE FUNCTION authority.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$
 BEGIN
@@ -1529,6 +1584,12 @@ BEGIN
         DELETE FROM authority.full_rec WHERE record = NEW.id; -- Avoid validating fields against deleted authority records
         DELETE FROM authority.simple_heading WHERE record = NEW.id;
           -- Should remove matching $0 from controlled fields at the same time?
+
+        -- XXX What do we about the actual linking subfields present in
+        -- authority records that target this one when this happens?
+        DELETE FROM authority.authority_linking
+            WHERE source = NEW.id OR target = NEW.id;
+
         RETURN NEW; -- and we're done
     END IF;
 
@@ -1543,8 +1604,14 @@ BEGIN
         PERFORM authority.propagate_changes(NEW.id) FROM authority.record_entry WHERE id = NEW.id;
 
         DELETE FROM authority.simple_heading WHERE record = NEW.id;
+        DELETE FROM authority.authority_linking WHERE source = NEW.id;
     END IF;
 
+    INSERT INTO authority.authority_linking (source, target, field)
+        SELECT source, target, field FROM authority.calculate_authority_linking(
+            NEW.id, NEW.control_set, NEW.marc::XML
+        );
+
     INSERT INTO authority.simple_heading (record,atag,value,sort_value)
         SELECT record, atag, value, sort_value FROM authority.simple_heading_set(NEW.marc);
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql
new file mode 100644
index 0000000..0424a77
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql
@@ -0,0 +1,129 @@
+BEGIN;
+
+-- check whether patch can be applied
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+ALTER TABLE authority.control_set_authority_field
+    ADD COLUMN linking_subfield CHAR(1);
+
+UPDATE authority.control_set_authority_field
+    SET linking_subfield = '0' WHERE main_entry IS NOT NULL;
+
+CREATE TABLE authority.authority_linking (
+    id      BIGSERIAL PRIMARY KEY,
+    source  BIGINT REFERENCES authority.record_entry (id) NOT NULL,
+    target  BIGINT REFERENCES authority.record_entry (id) NOT NULL,
+    field   INT REFERENCES authority.control_set_authority_field (id) NOT NULL
+);
+
+-- Given an authority record's ID, control set ID (if known), and marc::XML,
+-- return all links to other authority records in the form of rows that
+-- can be inserted into authority.authority_linking.
+CREATE OR REPLACE FUNCTION authority.calculate_authority_linking(
+    rec_id BIGINT, rec_control_set INT, rec_marc_xml XML
+) RETURNS SETOF authority.authority_linking AS $func$
+DECLARE
+    acsaf       authority.control_set_authority_field%ROWTYPE;
+    link        TEXT;
+    aal         authority.authority_linking%ROWTYPE;
+BEGIN
+    IF rec_control_set IS NULL THEN
+        -- No control_set on record?  Guess at one
+        SELECT control_set INTO rec_control_set
+            FROM authority.control_set_authority_field
+            WHERE tag IN (
+                SELECT UNNEST(
+                    XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc::XML)::TEXT[]
+                )
+            ) LIMIT 1;
+
+        IF NOT FOUND THEN
+            RAISE WARNING 'Could not even guess at control set for authority record %', rec_id;
+            RETURN;
+        END IF;
+    END IF;
+
+    aal.source := rec_id;
+
+    FOR acsaf IN
+        SELECT * FROM authority.control_set_authority_field
+        WHERE control_set = rec_control_set
+            AND linking_subfield IS NOT NULL
+            AND main_entry IS NOT NULL
+    LOOP
+        link := SUBSTRING(
+            (XPATH('//*[@tag="' || acsaf.tag || '"]/*[@code="' ||
+                acsaf.linking_subfield || '"]/text()', rec_marc_xml))[1]::TEXT,
+            '\d+$'
+        );
+
+        -- Ignore links that are null, malformed, circular, or point to
+        -- non-existent authority records.
+        IF link IS NOT NULL AND link::BIGINT <> rec_id THEN
+            PERFORM * FROM authority.record_entry WHERE id = link::BIGINT;
+            IF FOUND THEN
+                aal.target := link::BIGINT;
+                aal.field := acsaf.id;
+                RETURN NEXT aal;
+            END IF;
+        END IF;
+    END LOOP;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+
+-- AFTER UPDATE OR INSERT trigger for authority.record_entry
+CREATE OR REPLACE FUNCTION authority.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$
+BEGIN
+
+    IF NEW.deleted IS TRUE THEN -- If this authority is deleted
+        DELETE FROM authority.bib_linking WHERE authority = NEW.id; -- Avoid updating fields in bibs that are no longer visible
+        DELETE FROM authority.full_rec WHERE record = NEW.id; -- Avoid validating fields against deleted authority records
+        DELETE FROM authority.simple_heading WHERE record = NEW.id;
+          -- Should remove matching $0 from controlled fields at the same time?
+
+        -- XXX What do we about the actual linking subfields present in
+        -- authority records that target this one when this happens?
+        DELETE FROM authority.authority_linking
+            WHERE source = NEW.id OR target = NEW.id;
+
+        RETURN NEW; -- and we're done
+    END IF;
+
+    IF TG_OP = 'UPDATE' THEN -- re-ingest?
+        PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled;
+
+        IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change
+            RETURN NEW;
+        END IF;
+
+        -- Propagate these updates to any linked bib records
+        PERFORM authority.propagate_changes(NEW.id) FROM authority.record_entry WHERE id = NEW.id;
+
+        DELETE FROM authority.simple_heading WHERE record = NEW.id;
+        DELETE FROM authority.authority_linking WHERE source = NEW.id;
+    END IF;
+
+    INSERT INTO authority.authority_linking (source, target, field)
+        SELECT source, target, field FROM authority.calculate_authority_linking(
+            NEW.id, NEW.control_set, NEW.marc::XML
+        );
+
+    INSERT INTO authority.simple_heading (record,atag,value,sort_value)
+        SELECT record, atag, value, sort_value FROM authority.simple_heading_set(NEW.marc);
+
+    -- Flatten and insert the afr data
+    PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_full_rec' AND enabled;
+    IF NOT FOUND THEN
+        PERFORM authority.reingest_authority_full_rec(NEW.id);
+        PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_rec_descriptor' AND enabled;
+        IF NOT FOUND THEN
+            PERFORM authority.reingest_authority_rec_descriptor(NEW.id);
+        END IF;
+    END IF;
+
+    RETURN NEW;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+COMMIT;

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/examples/fm_IDL.xml                       |   15 +
 .../perlmods/lib/OpenILS/Application/AppUtils.pm   |   17 +
 .../Application/Storage/Driver/Pg/QueryParser.pm   |    8 +
 .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm    |    2 +
 .../perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm |  383 +
 .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm   |   18 +-
 Open-ILS/src/sql/Pg/002.schema.config.sql          |    2 +
 Open-ILS/src/sql/Pg/011.schema.authority.sql       |   16 +-
 Open-ILS/src/sql/Pg/030.schema.metabib.sql         |  384 +-
 Open-ILS/src/sql/Pg/950.data.seed-values.sql       |  218 +-
 Open-ILS/src/sql/Pg/953.data.MODS32-xsl.sql        |  303 +-
 Open-ILS/src/sql/Pg/954.data.MODS33-xsl.sql        |   32 +-
 Open-ILS/src/sql/Pg/999.functions.global.sql       |   67 +
 .../0815.schema.config-metabib-interauthority.sql  |  129 +
 .../sql/Pg/upgrade/0816.schema.bib-auth-browse.sql | 7507 ++++++++++++++++++++
 Open-ILS/src/templates/opac/advanced.tt2           |    8 +-
 Open-ILS/src/templates/opac/browse.tt2             |  169 +
 Open-ILS/src/templates/opac/cnbrowse.tt2           |    4 +-
 Open-ILS/src/templates/opac/css/style.css.tt2      |   47 +-
 Open-ILS/src/templates/opac/home.tt2               |    4 +-
 Open-ILS/src/templates/opac/login.tt2              |    4 +-
 Open-ILS/src/templates/opac/mylist.tt2             |    4 +-
 Open-ILS/src/templates/opac/parts/config.tt2       |    1 +
 Open-ILS/src/templates/opac/parts/myopac/base.tt2  |    4 +-
 .../src/templates/opac/parts/qtype_selector.tt2    |   19 +-
 Open-ILS/src/templates/opac/parts/searchbar.tt2    |    8 +-
 Open-ILS/src/templates/opac/password_reset.tt2     |    4 +-
 Open-ILS/src/templates/opac/place_hold.tt2         |    4 +-
 Open-ILS/src/templates/opac/record.tt2             |    4 +-
 Open-ILS/src/templates/opac/record/email.tt2       |    4 +-
 Open-ILS/src/templates/opac/results.tt2            |    4 +-
 Open-ILS/src/templates/opac/sms_cn.tt2             |    4 +-
 Open-ILS/src/templates/opac/temp_warn.tt2          |    4 +-
 Open-ILS/web/css/skin/default/opac/semiauto.css    |    1 -
 docs/RELEASE_NOTES_NEXT/OPAC/BibAuthBrowse.txt     |   56 +
 35 files changed, 9234 insertions(+), 224 deletions(-)
 create mode 100644 Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/0815.schema.config-metabib-interauthority.sql
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/0816.schema.bib-auth-browse.sql
 create mode 100644 Open-ILS/src/templates/opac/browse.tt2
 create mode 100644 docs/RELEASE_NOTES_NEXT/OPAC/BibAuthBrowse.txt


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list