New
[irspy-moved-to-github.git] / xsl / irspy2zeerex.xsl
index ebe4772..4c63056 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <!--
-    $Id: irspy2zeerex.xsl,v 1.4 2006-10-27 12:27:38 sondberg Exp $
+    $Id: irspy2zeerex.xsl,v 1.12 2006-12-06 12:58:32 mike Exp $
 
     This stylesheet is used by IRSpy to map the internal mixed Zeerex/IRSpy
     record format into the Zeerex record which we store.
       version="1.0"
       encoding="UTF-8"/>
 
-  <xsl:preserve-space elements="*"/>
+  <xsl:strip-space elements="*"/>
 
   <xsl:variable name="old_indexes" select="/*/explain:indexInfo/explain:index"/>
-  <xsl:variable name="old_syntaxes" select="/*/explain:recordInfo"/>
+  <xsl:variable name="use_attr_names" select="document('use-attr-names.xml')"/>
 
 
-  <xsl:template match="node() | @*">
-    <xsl:copy>
-      <xsl:apply-templates select="@* | node()"/>
-    </xsl:copy>
+  <xsl:template match="/*">
+    <explain>
+      <xsl:call-template name="insert-zeerexBase"/>
+      <xsl:call-template name="insert-indexInfo"/>
+      <xsl:call-template name="insert-recordInfo"/>
+      <xsl:call-template name="insert-configInfo"/>
+      <xsl:call-template name="insert-irspySection"/>
+    </explain>
   </xsl:template>
 
 
-  <xsl:template match="explain:indexInfo">
+  <xsl:template name="insert-zeerexBase">
+    <xsl:copy-of select="explain:serverInfo"/>
+    <xsl:copy-of select="explain:databaseInfo"/>
+    <metaInfo>
+      <dateModified><xsl:value-of
+                    select="/*/irspy:status/*[last()]"/></dateModified>
+    </metaInfo>
+  </xsl:template>
+
+
+  <xsl:template name="insert-indexInfo">
     <indexInfo>
       <xsl:for-each select="/*/irspy:status/irspy:search">
         <xsl:variable name="set" select="@set"/>
@@ -55,7 +69,7 @@
   </xsl:template>
 
 
-  <xsl:template match="explain:recordInfo">
+  <xsl:template name="insert-recordInfo">
     <recordInfo>
       <xsl:for-each select="/*/irspy:status/irspy:record_fetch[@ok = 1]">
         <recordSyntax name="{@syntax}">
   </xsl:template>
 
 
+  <xsl:template name="insert-configInfo">
+    <configInfo>
+      <xsl:for-each select="/*/irspy:status/irspy:init_opt">
+        <supports type="z3950_{@option}">1</supports>
+      </xsl:for-each>
+    </configInfo>
+  </xsl:template>
+
+
+  <!-- 
+       Here we list the bits and pieces of the irspy:status element which we
+       want to keep in the persistent version of the zeerex record.
+       Simply add "| irspy:xxx" to the select attribute.
+  -->
+  <xsl:template name="insert-irspySection">
+    <irspy:status>
+      <xsl:for-each select="*/irspy:probe   |
+                            */irspy:boolean |
+                            */irspy:named_resultset |
+                            */irspy:explain">
+        <xsl:copy-of select="."/>
+      </xsl:for-each>
+    </irspy:status>
+  </xsl:template>
+
+  
+  <xsl:template match="node() | @*">
+    <xsl:copy>
+      <xsl:apply-templates select="@* | node()"/>
+    </xsl:copy>
+  </xsl:template>
+
+
   <xsl:template name="insert-index-section">
     <xsl:param name="update" select="."/>
     <xsl:param name="title">
 
   <xsl:template name="insert-index-title">
     <xsl:param name="update"/>
-    <xsl:value-of select="$update/@ap"/>
+    <xsl:variable name="name"
+                select="$use_attr_names/*/map[@attr = $update/@ap and
+                                              @set = $update/@set]/@name"/>
+
+    <xsl:choose>
+      <xsl:when test="string-length($name) &gt; 0"><xsl:value-of
+                                            select="$name"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="$update/@ap"/></xsl:otherwise>
+    </xsl:choose>
   </xsl:template>
 
 
-  <xsl:template match="explain:dateModified">
-    <dateModified><xsl:value-of
-                    select="/*/irspy:status/*[last()]"/></dateModified>
-  </xsl:template>
-
+  <xsl:template match="*"/>
 
 </xsl:stylesheet>