diff software/mpdl-services-new/mpiwg-mpdl-cms/src/de/mpg/mpiwg/berlin/mpdl/cms/transform/replaceAnchor.xsl @ 25:e9fe3186670c default tip

letzter Stand eingecheckt
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 21 May 2013 10:19:32 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/software/mpdl-services-new/mpiwg-mpdl-cms/src/de/mpg/mpiwg/berlin/mpdl/cms/transform/replaceAnchor.xsl	Tue May 21 10:19:32 2013 +0200
@@ -0,0 +1,82 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet 
+  version="2.0" 
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xlink="http://www.w3.org/1999/xlink"
+  xmlns:xhtml="http://www.w3.org/1999/xhtml"
+  exclude-result-prefixes="xsl xlink xhtml"
+>
+
+<xsl:output method="xml" encoding="utf-8"/>
+
+<xsl:template match="@*|node()">
+  <xsl:copy>
+    <xsl:apply-templates select="@*|node()"/>
+  </xsl:copy>
+</xsl:template>
+
+<!-- insert figure number  -->
+<xsl:template match="*:figure">
+  <xsl:variable name="number" select="count(./preceding::*:figure) + 1"/>
+  <xsl:element name="{name()}" namespace="{namespace-uri()}"><!-- remove namespace in element and its subnodes  -->
+    <xsl:apply-templates select="@*"/>
+    <xsl:attribute name="number"><xsl:value-of select="$number"/></xsl:attribute>
+    <xsl:apply-templates/>
+  </xsl:element>
+</xsl:template>
+
+<!-- insert figure number  -->
+<xsl:template match="*:handwritten">
+  <xsl:variable name="number" select="count(./preceding::*:handwritten) + 1"/>
+  <xsl:element name="{name()}" namespace="{namespace-uri()}"><!-- remove namespace in element and its subnodes  -->
+    <xsl:apply-templates select="@*"/>
+    <xsl:attribute name="number"><xsl:value-of select="$number"/></xsl:attribute>
+    <xsl:apply-templates/>
+  </xsl:element>
+</xsl:template>
+
+<xsl:template match="*:anchor">
+  <xsl:variable name="type" select="@type"/>
+  <xsl:variable name="href" select="@xlink:href"/>
+  <xsl:choose>
+    <xsl:when test="$type = 'figure'">
+      <xsl:variable name="figure" select="//*:figure[@xlink:label = $href]"/>
+      <xsl:apply-templates select="$figure"/>
+    </xsl:when>
+    <xsl:when test="$type = 'handwritten'">
+      <xsl:variable name="handwritten" select="//*:handwritten[@xlink:label = $href]"/>
+      <xsl:apply-templates select="$handwritten"/>
+    </xsl:when>
+    <xsl:when test="$type = 'note'">
+      <xsl:variable name="note" select="//*:note[@xlink:label = $href]"/>
+      <xsl:sequence select="$note"/>
+    </xsl:when>
+    <xsl:when test="$type = 'table'">
+      <xsl:variable name="table" select="//xhtml:table[@xlink:label = $href]"/>
+      <xsl:sequence select="$table"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:copy>
+        <xsl:apply-templates select="@*|node()"/>
+      </xsl:copy>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<!-- remove the anchored divs: div which contain a labeled figure, note, handwritten or table -->
+<xsl:template match="*:div">
+  <xsl:variable name="containingElems" select="*:figure|*:note|*:handwritten|xhtml:table"/>
+  <xsl:variable name="hasLabel" select="not(empty($containingElems[1]/@xlink:label))"/>
+  <xsl:choose>
+    <xsl:when test="$hasLabel"></xsl:when>
+    <xsl:otherwise>
+      <xsl:copy>
+        <xsl:apply-templates select="@*|node()"/>
+      </xsl:copy>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+
+</xsl:stylesheet>