From f4011f07dcf7c1696892efd862ec25dd064c63ac Mon Sep 17 00:00:00 2001
From: David Maus <maus@hab.de>
Date: Wed, 11 Oct 2017 14:31:21 +0200
Subject: [PATCH] Download der Edition

---
 config/routes.php                   |  3 +++
 resources/mets.xml                  | 18 ++++++--------
 resources/xslt/edition/download.xsl | 37 +++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 11 deletions(-)
 create mode 100644 resources/xslt/edition/download.xsl

diff --git a/config/routes.php b/config/routes.php
index 9977c70b..855b6af2 100644
--- a/config/routes.php
+++ b/config/routes.php
@@ -15,6 +15,9 @@ $app->get('/edition/richtlinien',  'controller.staticpage:handle')
 $app->get('/edition/diarium/register.xml', 'controller.staticpage:handle')
     ->bind('edition.diarium.register');
 
+$app->get('/edition/diarium/download', 'controller.staticpage:handle')
+    ->bind('edition.diarium.download');
+
 $app->get('/edition/diarium/{metsId}', 'controller.dynamicpage:handle')
     ->bind('edition.diarium.jahr')
     ->convert('metsId', function ($metsId) { return "edition.diarium.{$metsId}"; });
diff --git a/resources/mets.xml b/resources/mets.xml
index 421c97e1..5ce25938 100644
--- a/resources/mets.xml
+++ b/resources/mets.xml
@@ -205,6 +205,9 @@
         <div ID="edition.richtlinien" LABEL="Richtlinien">
           <fptr FILEID="edition.richtlinien.xml"/>
         </div>
+        <div ID="edition.diarium.download">
+          <fptr FILEID="edition.diarium.xml"/>
+        </div>
         <div ID="edition.diarium" LABEL="Diarium August II.">
           <fptr FILEID="edition.diarium.xml"/>
           <div ID="edition.diarium.front">
@@ -387,6 +390,10 @@
       <interfaceDef LOCTYPE="URL" xlink:href="http://www.w3.org/TR/xslt"/>
       <mechanism LOCTYPE="URL" xlink:href="xslt/default.xsl"/>
     </behavior>
+    <behavior STRUCTID="edition.diarium.download">
+      <interfaceDef LOCTYPE="URL" xlink:href="http://www.w3.org/TR/xslt"/>
+      <mechanism LOCTYPE="URL" xlink:href="xslt/edition/download.xsl"/>
+    </behavior>
     <behavior STRUCTID="edition.diarium">
       <interfaceDef LOCTYPE="URL" xlink:href="http://www.w3.org/TR/xslt"/>
       <mechanism LOCTYPE="URL" xlink:href="xslt/edition/diarium.xsl"/>
@@ -451,15 +458,4 @@
     </behavior>
   </behaviorSec>
 
-  <behaviorSec ID="tei">
-    <behavior STRUCTID="repertorium.eintrag">
-      <interfaceDef LOCTYPE="URL" xlink:href="http://www.w3.org/TR/xslt"/>
-      <mechanism LOCTYPE="URL" xlink:href="xslt/identity.xsl"/>
-    </behavior>
-    <behavior STRUCTID="edition.diarium">
-      <interfaceDef LOCTYPE="URL" xlink:href="http://www.w3.org/TR/xslt"/>
-      <mechanism LOCTYPE="URL" xlink:href="xslt/identity.xsl"/>
-    </behavior>
-  </behaviorSec>
-
 </mets>
diff --git a/resources/xslt/edition/download.xsl b/resources/xslt/edition/download.xsl
new file mode 100644
index 00000000..08f30dc8
--- /dev/null
+++ b/resources/xslt/edition/download.xsl
@@ -0,0 +1,37 @@
+<xsl:transform version="1.0"
+               xmlns:tei="http://www.tei-c.org/ns/1.0"
+               xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+  <xsl:output method="xml" encoding="utf-8" media-type="application/xml"/>
+
+  <xsl:template match="node() | @*">
+    <xsl:copy>
+      <xsl:apply-templates select="node() | @*"/>
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match="@xml:base"/>
+
+  <xsl:template match="@ref[starts-with(., 'register.xml')]">
+    <xsl:choose>
+      <xsl:when test="document(.)/tei:idno[@type = 'URI']">
+        <xsl:attribute name="ref">
+          <xsl:value-of select="document(.)/tei:idno[@type = 'URI']"/>
+        </xsl:attribute>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:attribute name="ref">
+          <xsl:value-of select="concat('tag:selbstzeugnisse.hab.de,2017:edition/diarium/register#', substring-after(., '#'))"/>
+        </xsl:attribute>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template match="@facs[starts-with(., 'http://selbstzeugnisse.hab.de/edition/images/')]">
+    <xsl:attribute name="facs">
+      <xsl:variable name="imageNr" select="substring-before(substring-after(., 'http://selbstzeugnisse.hab.de/edition/images/'), '.jpg')"/>
+      <xsl:value-of select="concat('http://diglib.hab.de/mss/42-19-aug-2f/start.htm?image=', $imageNr)"/>
+    </xsl:attribute>
+  </xsl:template>
+
+</xsl:transform>
-- 
GitLab