 
  <div role="main">
    {$singleMode:=contains($url, '/Record/'),
     if ($singleMode) then (
       singleModeRecordId:=substring-after($url, "/Record/"), 
       $new-books := ()
     ) else (),
     $ubLeipzig := contains($url, 'ub.uni-leipzig.de'),
     if ($ubLeipzig) then $search-result-count := extract(join(//script/node()[contains(., "piwik")]), "trackSiteSearch.*?, *([0-9]+)", 1, "s") else ()
    }
    <t:if test="not($singleMode) and not($ubLeipzig)">
      <t:switch prioritized="true">
        <div id="search-counter"><strong>{$search-result-count}</strong></div>
        <span class="numResult">{$search-result-count}</span>
        <t:element t:condition="(self::div or self::span) and exists(text()[matches(., 'Treffer|Showing')])">
        {$search-result-count := extract(.,"[0-9.,]+",0,"*")[position() le 3]}
        </t:element>
        <h2>Keine Ergebnisse<t:s>$search-result-count:=0</t:s></h2>
        <h2>No results<t:s>$search-result-count:=0</t:s></h2>
        <span class="sr-only">vl:raise(.)</span>
      </t:switch>
    </t:if>
    
    <t:if test="not($singleMode)">
    
    {$search-result-count := max( $search-result-count ! translate(.,".,","")[.] ! xs:integer(.) ),
     
     $new-books := (.//div|.//li)[starts-with(@id, 'result')]/(
       let $linkurls := .//a/@href
       let $records := $linkurls[matches(., "/Record/[^/]+$")]/parent::a[normalize-space()[.]]
       let $title := normalize-space($records[1])
       let $author := join($linkurls[matches(., "/Author/.*author=([^&]+)|Results[?].*lookfor=([^&]+).*type=Author")]/parent::a)
       let $year := (.//span[@property="publicationDate"], .//text()/extract(., "(,|published|Veröffentlicht|^)\s*\[?((ca\.\s*)?[1-3][0-9]{3})",2)[.])[1]
       let $internalIds := distinct-values($records/@href)
       let $splitBook := count($internalIds) > 1
       let $cover := resolve-html((.//img[contains(@src, "cover")])[1])
       for $internalId in $internalIds 
       return {"_recordId": substring-after($internalId, "/Record/"),
               "title": if ($splitBook) then x"{$title} ({$records[@href eq $internalId][last()]})" else $title, 
               "author": $author,
               "year": $year,
               "image-url": $cover}
     )}
     
     <ul class="pagination" t:test="not($search-result-count = 0)">{
     let $next-page := "page=" || (get("page", 1) + 1)
     return (
       search-next-page := (.//a/@href[contains(., "/Search/Results") and contains(., $next-page)])[1],
       search-next-page-available := exists($search-next-page)
     )
     }</ul>
     </t:if>
  </div>