<DIV class="aDISMaske"><!-- this page shows the books, but not if they are renewable. need to click on a button for that -->
<template:meta default-text-matching="regex"/>  
 <t:switch prioritized="true">
  <FORM>
  {let $form := form(., {"": {"kind": "submit"}})
   let $inputs := .//input
   let $backButton := ($inputs[@title = "Zurück zur vorherigen Seite" or @value = "Zur Übersicht"])[1]
   let $backButton := if ($backButton) then $backButton else ($inputs[contains(@title, 'zur vorherigen Seite')])[1] (:is this line needed? düsseldorf has the wrong umlaut on search:)
   return (
     if ($mode = 'lend') then (
      $extendFormPost := request-combine($form, (($inputs[@type = "submit" and contains(@value, "arkierte") and contains(@value, "ngern")])[1])),
      $extendFormPost.post := replace($extendFormPost.post, "[a-zA-Z0-9]+=on&", "")
     ) else (
       $cancelFormPost := request-combine($form, ($inputs[@type = "submit" and contains(@value, "arkierte") and contains(@value, "schen")])[1]),
       $cancelFormPost.post := replace($cancelFormPost.post, "[a-zA-Z0-9]+=on&", "")
     ),
     if ($backButton/@name) then 
       $goBackPage := request-combine($form, $backButton)
     else let $href := (//a[matches(., "(^Benutzerkonto$)|(Konto$)|(^Anmeldung$)")])[1]/@href return
       if ($href) then 
         $goBackPage := ( if (starts-with($href, "javascript:")) then 
           let $code := extract($href, "javascript:top\.htmlOnLink\(['""](.*)['""]\)", 1) 
           return if ($code) then form($href/ancestor::form[1], "selected=ZTEXT       "||$code)
           else vl:raise-internal("Der Link zum Ausleihkonto konnte nicht geöffnet werden: """ || . || """: " || $href )
         else resolve-html($href) )
       else vl:raise-internal("Kein Link von der Ausleihentabelle zurück zur vorherigen Seite gefunden" )
   ),
   $default-book := map:merge(({"_mode": $mode},
     switch ($mode)
       case "lend" return {"_splitIndex": $splitIndex}
       case 'ordered' case 'orderedMagazine' return {"statusId": "ordered"}
       case "provided" return {"statusId": "provided"}
       default return ()
   ))
  }

 
    <DIV class="rTable_div">
    <TABLE class="rTable_table">
    
    <thead><tr>
      <t:siblings-header>
    <!--    <th>Fällig am</th>?
        <th>Bis</th>?-->
        <th>Bibliothek|Ausgabeort|Zweigstelle</th>?
        <th>Titel</th>
        <th>Hinweis|Bemerkung</th>?
        <th>vorgemerkt am</th>?
        <th/>*
      </t:siblings-header>
    </tr></thead>
  
    
    <t:loop>
    <TR>
    {book := $default-book}
    <t:siblings>
<!--    <TD>{
      if (contains(., "-")) then (book.issuedate := parse-date(substring-before(., "-"), "dd.mm.yyyy"), book.duedate := parse-date(substring-after(., "-"), "dd.mm.yyyy"))
      else book.duedate := parse-date(., "dd.mm.yyyy")
    }</TD>
    <TD>{
      if (contains(., ".")) then book.duedate := parse-date(., "dd.mm.yyyy") 
      else ()}
      <!- - vormerkungs verfall - -></TD>-->
    <TD>{book.libraryBranch := .}</TD>
    <TD>{let
            $lines := for tumbling window $w in .//node()[self::text() or self::br]
                      start when true() 
                      end $node when $node/self::br
                      return string-join($w),
            $lines := if ( count($lines) = 4 and matches($lines[1], "\[.*\]") ) then 
                        ($lines[1] || $lines[2], $lines[3], $lines[4])
                       else 
                        $lines,
            $text := $lines[1],
            $split := extract($text, "^\s*(\[([^\]]*)\])?\s*([^/]+)\s*(/\s*(.*))?", (2,3,5), "s")             
         return (
           book.category := $split[1],
           book.author := $split[3],
           book.title := $split[2],
           if (count($lines) > 1) then book.id := string-join(tail($lines), ":")
           else ()
         )
         }
    </TD>
    <TD>{book.status := inner-text(),
         book.renewCount := extract($book.status, "([0-9]+) *Verlängerung", 1)
        }
        <t:if test="matches(., x'((nicht +verl.*ngerbar|Keine Verl.*gerung +m.*glich|Vormerkungen|Verlängerung +(noch)? *nicht +möglich).*Stand +{string-join(reverse(tokenize(current-date(), '-')), '[.]')})|((Max. +)?Anzahl +der +Verl.*erreicht)','i')">
          {book.statusId := "critical"}
        </t:if>
    </TD>
    <td>
      {book.status := concat("vorgemerkt am ", inner-text()), book.statusId := "ordered"}
    </td>
    <TD>{
      if ($mode = "lend") then (.//input!(book.extendData := concat(encode-for-uri(@name), "=", encode-for-uri(@value otherwise "on")) ) )
      else if ($mode = ("ordered", "requested", "provided","orderedMagazine")) then .//input!(book.cancelData := concat(encode-for-uri(@name), "=", encode-for-uri(@value otherwise "on")) )
      else (),
      let $date := extract(., "(([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4}) *- *)?([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4})", (1,3))
      where $date[2] and not($book.duedate)
      return (
        $book.duedate := parse-date($date[2]),
        if ($date[1]) then $book.issuedate := parse-date($date[1]) else ()
      )
    }</TD>
    </t:siblings>   
    </TR>
    </t:loop>
    </TABLE>

  </DIV>
 


  </form>
  
  
   
  <FORM>
    {form := .}
    
    <!--Servicebereiche-->
    <a t:condition="contains(., 'zeigen oder verlängern in:')"/>
    {let $sublinks := //a[contains(., 'zeigen oder verlängern in:')]
     return (
       nextSplitTable := ($sublinks/@href)[$splitIndex], 
       splitCount := count($sublinks)
     )
    }
  </form>
  </t:switch>
</div>