<html>
<template:meta default-text-matching="regex"/>
{if (get("singleBookResult", "") != "") then book := {"_detail-url": $url} else ()}

<div class="box">
  <td>
    <strong>Signatur|Regalstandort</strong>{$book.id := text()}
  </td>?
  <img alt="Buchcover">{book.image-url := resolve-uri(@src)}</img>?
</div>?

<div t:condition="(@id,@class)=('tab-content', 'detailsTabs-titleinfo', 'box-container')">
  <template:switch prioritized="true">
    <table t:condition="@class=('fulltitle','titleinfo', 'data2')">
      {for $row in .//tr 
       let $key := $row/(let $th := th[1] return if ($th) then $th else
                         let $td := td return if (count($td) le 2) then $td else $td[not(@class = "fieldnumber")])[1]
       let $value := $key/following-sibling::td
       let $key := normalize-space(translate($key, ":", ""))
       let $key := switch($key)
                   case "Titel" case "Title" return "title"
                   case "Autor" case "Verfasser" return "author"
                   case "Ort"    return "location"
                   case "Verlag" return "publisher"
                   case "Jahr"   return "year"
                   case "ISBN"   return "isbn"
                   default return $key || "!"
        where string-length($key) gt 2
        return $book($key) := $value/inner-text()
      }
    </table>
    
    <t:element t:condition="(self::table and contains(@class, 'data') ) or (self::div and contains(@class, 'container-fluid'))">
    <template:loop><template:switch>
      <strong>^Titelzusatz<t:s>$book.title:= concat($book.title, " ", (./following-sibling::*[1] | ./following-sibling::text())[normalize-space(.)][1])</t:s></strong>
      <strong>^(Titel|Title)<t:s>$book.title:=       (./following-sibling::*[1] | ./following-sibling::text())[normalize-space(.)][1]</t:s></strong>
      <strong>^Autor|^Verfasser|Person<t:s>$book.author:=      (./following-sibling::*[1] | ./following-sibling::text())[normalize-space(.)][1]</t:s></strong>
      <strong>^Ort<t:s>$book.location:=      (./following-sibling::*[1] | ./following-sibling::text())[normalize-space(.)][1]</t:s></strong>
      <strong>^Verlag<t:s>$book.publisher:=  (./following-sibling::*[1] | ./following-sibling::text())[normalize-space(.)][1]</t:s></strong>
      <strong>^Jahr<t:s>$book.year:=         (./following-sibling::*[1] | ./following-sibling::text())[normalize-space(.)][1]</t:s></strong>
      <strong>ISBN<t:s>$book.isbn:=         (./following-sibling::*[1] | ./following-sibling::text())[normalize-space(.)][1]</t:s></strong>
      <h1>{$book.title}</h1>
      <strong>{$book(. || "!") := (./following-sibling::*[1] | ./following-sibling::text())[normalize-space(.)][1]/(if (exists(@href) and contains(@href, '://')) then x'{.} ( {@href} )' else .)}</strong>
    </template:switch></template:loop>
    </t:element>
  </template:switch>
</div>
</html>