Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / lib / topicmerge.xsl
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/lib/topicmerge.xsl b/JMCR-Stable/real-world application/derby-10.3.2.1/lib/topicmerge.xsl
new file mode 100644 (file)
index 0000000..05cad88
--- /dev/null
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="UTF-8" ?>\r
+<!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->\r
+\r
+<!-- book.xsl \r
+ | Merge DITA topics with "validation" of topic property\r
+ *-->\r
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\r
+  \r
+<!-- Include error message template -->\r
+<xsl:include href="common/output-message.xsl"/>\r
+\r
+<xsl:param name="root-path"></xsl:param>\r
+\r
+<!-- Set the prefix for error message numbers -->\r
+<xsl:variable name="msgprefix">IDXS</xsl:variable>\r
+\r
+<xsl:variable name="xml-path"></xsl:variable>\r
+\r
+<xsl:output method="xml"\r
+            encoding="utf-8"\r
+/>\r
+\r
+<xsl:template match="/*">\r
+   <xsl:element name="{name()}">\r
+     <xsl:apply-templates select="@*" mode="copy-element"/>\r
+     <xsl:apply-templates select="*"/>\r
+   </xsl:element>\r
+</xsl:template>\r
+\r
+<xsl:template match="/*/*[contains(@class,' map/topicmeta ')]" priority="1">\r
+  <xsl:apply-templates select="." mode="copy-element"/>\r
+</xsl:template>\r
+<xsl:template match="*[contains(@class,' map/topicmeta ')]"/>\r
+<xsl:template match="*[contains(@class,' map/navref ')]"/>\r
+<xsl:template match="*[contains(@class,' map/reltable ')]"/>\r
+<xsl:template match="*[contains(@class,' map/anchor ')]"/>\r
+\r
+<xsl:template match="*[contains(@class,' map/topicref ')][@href][not(@href='')][not(@print='no')]">\r
+  <xsl:variable name="topicrefClass"><xsl:value-of select="@class"/></xsl:variable>\r
+  <xsl:comment>Start of imbed for <xsl:value-of select="@href"/></xsl:comment>\r
+  <xsl:choose>\r
+    <xsl:when test="@format and not(@format='dita')">\r
+       <!-- Topicref to non-dita files will be ingored in PDF transformation -->\r
+      <xsl:call-template name="output-message">\r
+        <xsl:with-param name="msg">Topicref to non-dita files will be ignored in PDF transformation</xsl:with-param>\r
+        <xsl:with-param name="msgnum">039</xsl:with-param>\r
+        <xsl:with-param name="msgsev">I</xsl:with-param>\r
+      </xsl:call-template>\r
+    </xsl:when>\r
+    <xsl:when test="contains(@href,'#')">\r
+      <xsl:variable name="sourcefile"><xsl:value-of select="substring-before(@href,'#')"/></xsl:variable>\r
+      <xsl:variable name="sourcetopic"><xsl:value-of select="substring-after(@href,'#')"/></xsl:variable>\r
+      <xsl:variable name="targetName"><xsl:value-of select="name(document($sourcefile,/)//*[@id=$sourcetopic][contains(@class,' topic/topic ')][1])"/></xsl:variable>\r
+      <xsl:element name="{$targetName}">\r
+        <xsl:apply-templates select="document($sourcefile,/)//*[@id=$sourcetopic][contains(@class,' topic/topic ')][1]/@*" mode="copy-element"/>\r
+        <xsl:attribute name="refclass"><xsl:value-of select="$topicrefClass"/></xsl:attribute>\r
+        <xsl:apply-templates select="document($sourcefile,/)//*[@id=$sourcetopic][contains(@class,' topic/topic ')][1]/*" mode="copy-element">\r
+          <xsl:with-param name="src-file"><xsl:value-of select="$sourcefile"/></xsl:with-param>\r
+        </xsl:apply-templates>\r
+        <xsl:apply-templates/>\r
+      </xsl:element>\r
+    </xsl:when>\r
+    <!-- If the target is a topic, as opposed to a ditabase mixed file -->\r
+    <xsl:when test="document(@href,/)/*[contains(@class,' topic/topic ')]">\r
+      <xsl:variable name="targetName"><xsl:value-of select="name(document(@href,/)/*)"/></xsl:variable>\r
+      <xsl:element name="{$targetName}">\r
+        <xsl:apply-templates select="document(@href,/)/*/@*" mode="copy-element"/>\r
+        <xsl:attribute name="refclass"><xsl:value-of select="$topicrefClass"/></xsl:attribute>\r
+        <!-- If the root element of the topic does not contain an id attribute, then generate one.\r
+             Later, we will use these id attributes as anchors for PDF bookmarks. -->\r
+        <xsl:if test="not(document(@href,/)/*/@id)">\r
+          <xsl:attribute name="id"><xsl:value-of select="generate-id()"/></xsl:attribute>\r
+        </xsl:if>\r
+        <xsl:apply-templates select="document(@href,/)/*/*" mode="copy-element">\r
+          <xsl:with-param name="src-file"><xsl:value-of select="@href"/></xsl:with-param>\r
+        </xsl:apply-templates>\r
+        <xsl:apply-templates/>\r
+      </xsl:element>\r
+    </xsl:when>\r
+    <!-- Otherwise: pointing to ditabase container; output each topic in the ditabase file.\r
+         The refclass value is copied to each of the main topics.\r
+         If this topicref has children, they will be treated as children of the <dita> wrapper.\r
+         This is the same as saving them as peers of the topics in the ditabase file. -->\r
+    <xsl:otherwise>\r
+      <xsl:for-each select="document(@href,/)/*/*">\r
+        <xsl:element name="{name()}">\r
+          <xsl:apply-templates select="@*" mode="copy-element"/>\r
+          <xsl:attribute name="refclass"><xsl:value-of select="$topicrefClass"/></xsl:attribute>\r
+          <xsl:apply-templates select="*" mode="copy-element"/>\r
+        </xsl:element>\r
+      </xsl:for-each>\r
+      <xsl:apply-templates/>\r
+    </xsl:otherwise>\r
+  </xsl:choose>\r
+</xsl:template>\r
+\r
+<xsl:template match="*[contains(@class,' map/topicref ')][not(@href)]">\r
+  <xsl:element name="{name()}">\r
+    <xsl:apply-templates select="@*" mode="copy-element"/>\r
+    <xsl:apply-templates/>\r
+  </xsl:element>\r
+</xsl:template>\r
+\r
+<xsl:template match="*|@*|comment()|processing-instruction()|text()" mode="copy-element">\r
+<xsl:param name="src-file"></xsl:param>\r
+  <xsl:copy>\r
+    <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="copy-element">\r
+      <xsl:with-param name="src-file"><xsl:value-of select="$src-file"/></xsl:with-param>\r
+    </xsl:apply-templates>\r
+  </xsl:copy>\r
+</xsl:template>\r
+\r
+<xsl:template match="@href" mode="copy-element" priority="1">\r
+  <xsl:param name="src-file"></xsl:param>\r
+\r
+  <xsl:variable name="file-path">  \r
+    <xsl:call-template name="get-file-path">\r
+      <xsl:with-param name="src-file">\r
+        <xsl:value-of select="$src-file"/>\r
+      </xsl:with-param>\r
+    </xsl:call-template>\r
+    <xsl:value-of select="."/>\r
+  </xsl:variable>\r
+\r
+  <xsl:variable name="file-path-new">\r
+    <xsl:call-template name="normalize-path">\r
+      <xsl:with-param name="file-path">\r
+        <xsl:value-of select="$file-path"/>\r
+      </xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:variable>  \r
+\r
+  <xsl:choose>\r
+    <xsl:when test="contains(.,'://') or starts-with(.,'#')">\r
+      <xsl:copy/>\r
+    </xsl:when>\r
+    <xsl:otherwise>\r
+      <xsl:attribute name="href">\r
+        <xsl:value-of select="$file-path-new"/>\r
+      </xsl:attribute>\r
+    </xsl:otherwise>\r
+  </xsl:choose>  \r
+</xsl:template>\r
+\r
+<xsl:template name="get-file-path">\r
+  <xsl:param name="src-file"/>  \r
+  <xsl:if test="contains($src-file,'/')">\r
+    <xsl:value-of select="substring-before($src-file,'/')"/>\r
+    <xsl:text>/</xsl:text>\r
+    <xsl:call-template name="get-file-path">\r
+      <xsl:with-param name="src-file">\r
+        <xsl:value-of select="substring-after($src-file,'/')"/>\r
+      </xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:if>  \r
+</xsl:template>\r
+\r
+<xsl:template name="normalize-path">\r
+  <xsl:param name="file-path"></xsl:param>  \r
+\r
+  <xsl:choose>\r
+    <xsl:when test="contains($file-path, '/')">\r
+      <xsl:variable name="dirname" select="substring-before($file-path,'/')"/>\r
+      <xsl:variable name="file-path-new" select="substring-after($file-path,'/')"/>\r
+      <xsl:variable name="dirname2" select="substring-before($file-path-new,'/')"/>\r
+      <xsl:variable name="file-path-new2" select="substring-after($file-path-new,'/')"/>\r
+\r
+      <xsl:choose>\r
+        <xsl:when test="$dirname2='..'">          \r
+          <xsl:choose>\r
+            <xsl:when test="$dirname='..'">\r
+              <xsl:text>../../</xsl:text>\r
+              <xsl:call-template name="normalize-path">\r
+                <xsl:with-param name="file-path">\r
+                  <xsl:value-of select="$file-path-new2"/>\r
+                </xsl:with-param>\r
+              </xsl:call-template>\r
+            </xsl:when>\r
+            <xsl:otherwise>\r
+              <xsl:call-template name="normalize-path">\r
+                <xsl:with-param name="file-path">\r
+                  <xsl:value-of select="$file-path-new2"/>\r
+                </xsl:with-param>\r
+              </xsl:call-template>\r
+            </xsl:otherwise>\r
+          </xsl:choose>\r
+        </xsl:when>\r
+        <xsl:otherwise>\r
+          <xsl:value-of select="$dirname"/><xsl:text>/</xsl:text>\r
+          <xsl:call-template name="normalize-path">\r
+            <xsl:with-param name="file-path">\r
+              <xsl:value-of select="$file-path-new"/>\r
+            </xsl:with-param>\r
+          </xsl:call-template>\r
+        </xsl:otherwise>\r
+      </xsl:choose>\r
+    </xsl:when>\r
+    <xsl:when test="$file-path">\r
+      <xsl:value-of select="$file-path"/>\r
+    </xsl:when>\r
+    <xsl:otherwise></xsl:otherwise>\r
+  </xsl:choose>\r
+</xsl:template>\r
+\r
+</xsl:stylesheet>\r