<t:switch prioritized="true">
  <html>
  {declare function local:parse-column($element){ 
     $element/normalize-space(string-join(node() except span[contains(@class, "oclc-module-label")])) 
   };
  culture := (//input[contains(@name, "Culture")]/@value, "de-DE")[1], 
  userRndId := //input[ends-with(@name, "PatronRndId")]/@value otherwise $username,
  vl:delete-current-books() 
  }
  <link t:condition="contains(@href, 'PatronAccountModule')">{extendableCheck := extract(resolve-uri(@href), "^.*PatronAccountModule[/\\]") || "PatronAccountService.asmx/IsCatalogueCopyExtendable"}</link>
  
  <form>
    { $user-form := form(., {"": {"kind": "submit"}}),
      $renew-button := (//input[ends-with(@name, "BtnExtendMediums")])[1]/{"__EVENTTARGET":  @name},
      $cancel-ordered-button := (//input[ends-with(@name, "BtnCancelReservations")])[1]/{"__EVENTTARGET":  @name},
      $cancel-provided-button := (//input[ends-with(@name, "BtnCancelReadyForPickup")])[1]/{"__EVENTTARGET":  @name},
      let $split := extract($raw, 'LoadExtensionsAsync *\( *["'']([^"'']*?/IsCatalogueCopyExtendable)["''] *, *["'']([^"'']*?)["''] *, *["'']([^"'']*?)["''] *(\)|, *["'']([^"'']*?)["''])', (1,2,3,5))
      return (
        $extendableCheck := $split[1][.] 
                            otherwise (//link[contains(@href, 'PatronAccountModule')])[1]/(extract(resolve-uri(@href), "^.*PatronAccountModule[/\\]") || "PatronAccountService.asmx/IsCatalogueCopyExtendable"),
        $portalId := $split[2][.] 
                     otherwise extract($raw, 'eonportalid *= *[''"]([0-9]+)[''"]', 1)[.] 
                     otherwise "0",
        $localResourceFile := $split[4][contains(., "DesktopModules")]
                              otherwise $split[3][.]
                              otherwise "/DesktopModules/OCLC.OPEN.PL.DNN.PatronAccountModule/App_LocalResources/NormalView"
      )
    }
    
    <span t:condition="ends-with(@id, 'MembershipValidUntilData')">{$account-expiration}</span>?
    
    <TABLE t:condition="contains(@id, 'grdViewLoans')">
      <t:switch prioritized="true">
        <tr>
          <t:siblings-header>
          <th t:condition='@abbr="Cover" or contains(., "Cover")'/>
          <th t:condition='@abbr="Titel" or matches(., "Titel|Title")'/>
          <th t:condition='@abbr="Verfasser" or contains(a/@href, "Sort$Author")'/>
          <th t:condition='@abbr="Mediengruppe" or contains(a/@href, "Sort$MediaGroup")'/>?
          <th t:condition='@abbr="Zweigstelle" or contains(a/@href, "Sort$Branch")'/>?
          <th t:condition='@abbr="Frist" or contains(a/@href, "Sort$DueDate")'/>
          <t:element t:condition="self::td or self::th"/>*
                              
          </t:siblings-header>
          <!--<th abbr="Verlängerbar">Verlängerbar</th>-->          
        </tr>
        <tr class="GridViewInnerBorderNoData"/>
        <tr class="oclc-module-table-nodata"/>
      </t:switch>
      <t:loop>
        <TR>{book:={}}
          <t:siblings>
          <TD>{$book.image-url := .//(img,input[type="image"])
                 !(@src,@sources,@data-sources)
                 !tokenize(., "[|]")[contains(.,"://")],
               $book.image-url!extract(., "(amazon.*/(ASIN|P)/|isbn=|cover/)([-0-9X]{8,})([./&amp;]|[.]jpg)", 3)[.][1]!($book.ISBN := .)
           }</TD>
          <TD>{book.title := local:parse-column(.)}</TD>
          <TD>{book.author := local:parse-column(.)}</TD>
          <TD>{book.category := local:parse-column(.)}</TD>
          <TD>{book.libraryBranch := local:parse-column(.)}</TD>
          <TD>{book.duedate := parse-date(extract(., "[0-9./-]{6,}")[.] otherwise .)}</TD>
          <td>{
          .//input!(
            if (@type = "checkbox") then $book._renewid := string(@name)
            else if (contains(@name, 'CopyId')) then 
              $all-copyIds[] := $book._copyId := $book.id := string(@value)
            else ()
          )
          }
          </td>
          </t:siblings>          
        </TR>
      </t:loop>
    </TABLE>             
  
  
    <table t:condition="contains(@id, 'grdViewReservations')">
      <t:switch prioritized="true">
        <tr><th/></tr>
        <tr class="GridViewInnerBorderNoData"/>
        <tr class="oclc-module-table-nodata"/>
      </t:switch>
      <tr><td><input>{book := {"_cancelid": @name, "statusId": "ordered", "cancelable": true()}}</input></td>
          <TD/><!--<input type="image" src=".."/>-->
          <TD>{book.title := local:parse-column(.)}</TD>
          <TD>{book.author := local:parse-column(.)}</TD>
      </tr>*
    </table>
           
    
  	<table t:condition="contains(@id, 'grdViewReadyForPickups')">
      <t:switch prioritized="true">
        <tr><th/></tr>
        <tr class="GridViewInnerBorderNoData"/>
        <tr class="oclc-module-table-nodata"/>
      </t:switch>
      <tr><td><input>{book := {"_cancelid": @name, "statusId": "provided", "cancelable": true()}}</input></td>
          <TD/><!--<input type="image" src=".."/>-->
          <TD>{book.title := local:parse-column(.)}</TD>
          <TD>{book.author := local:parse-column(.)}</TD>
      </tr>* <!-- todo: correct columns???-->
  	</table>
    
  </form>
  </html>
  
  <form t:test="exists(get('pendingLoginError', ()))">
    <input t:condition="ends-with(@name, 'txtUsername')"/>
    {vl:raise-login(get('pendingLoginError', ()))}
  </form>
  
  <div t:condition="contains(@id, 'dnnSkinMessage')" class="dnnFormMessage dnnFormWarning">
    <span id="contains(@id, 'lblMessage')">
    {vl:raise(.)}
    </span>
  </div>
</t:switch>
