Ignore records-2008-09-16
[irspy-moved-to-github.git] / xsl / irspy2zeerex.xsl
index 8a64677..0076589 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <!--
-    $Id: irspy2zeerex.xsl,v 1.13 2006-12-11 11:01:14 sondberg Exp $
+    $Id: irspy2zeerex.xsl,v 1.21 2007-06-28 14:01:56 sondberg Exp $
 
     This stylesheet is used by IRSpy to map the internal mixed Zeerex/IRSpy
     record format into the Zeerex record which we store.
@@ -23,6 +23,7 @@
 
   <xsl:variable name="old_indexes" select="/*/explain:indexInfo/explain:index"/>
   <xsl:variable name="use_attr_names" select="document('use-attr-names.xml')"/>
+  <xsl:variable name="ping_date" select="/*/irspy:status/irspy:probe[last()]"/>
 
 
   <xsl:template match="/*">
@@ -40,8 +41,7 @@
     <xsl:copy-of select="explain:serverInfo"/>
     <xsl:copy-of select="explain:databaseInfo"/>
     <metaInfo>
-      <dateModified><xsl:value-of
-                    select="/*/irspy:status/*[last()]"/></dateModified>
+      <dateModified><xsl:value-of select="$ping_date"/></dateModified>
     </metaInfo>
   </xsl:template>
 
@@ -73,7 +73,8 @@
 
         <!-- If not, insert what we already had... -->
         <xsl:otherwise>
-          <xsl:copy-of select="explain:indexInfo/*"/>
+          <xsl:copy-of
+                select="explain:indexInfo/explain:index[@search='true']"/>
         </xsl:otherwise>
       </xsl:choose>
     </indexInfo>
@@ -85,7 +86,7 @@
       <xsl:choose>
 
         <!-- Did we actually probe record syntaxes? -->
-        <xsl:when test="/*/irspy:status/irspy:record">
+        <xsl:when test="/*/irspy:status/irspy:record_fetch">
           <xsl:for-each select="/*/irspy:status/irspy:record_fetch[@ok = 1]">
             <recordSyntax name="{@syntax}">
               <elementSet name="F"/> <!-- FIXME: This should be probed too -->
   <!-- 
        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>
+      <xsl:copy-of select="*/irspy:libraryType"/>
+      <xsl:copy-of select="*/irspy:country"/>
+      <xsl:copy-of select="*/irspy:probe"/>
+
+      <xsl:call-template name="insert-latest-nodes">
+        <xsl:with-param name="nodes" select="*/irspy:boolean"/>
+        <xsl:with-param name="what" select="'boolean'"/>
+      </xsl:call-template>
+      
+      <xsl:call-template name="insert-latest-nodes">
+        <xsl:with-param name="nodes" select="*/irspy:named_resultset"/>
+        <xsl:with-param name="what" select="'named_resultset'"/>
+      </xsl:call-template>
+      
+      <xsl:call-template name="insert-latest-nodes">
+        <xsl:with-param name="nodes" select="*/irspy:explain"/>
+        <xsl:with-param name="what" select="'explain'"/>
+      </xsl:call-template>
+
+      <xsl:call-template name="insert-latest-nodes">
+        <xsl:with-param name="nodes" select="*/irspy:serverImplementationId"/>
+        <xsl:with-param name="what" select="'serverImplementationId'"/>
+      </xsl:call-template>
+
+      <xsl:call-template name="insert-latest-nodes">
+        <xsl:with-param name="nodes" select="*/irspy:serverImplementationName"/>
+        <xsl:with-param name="what" select="'serverImplementationName'"/>
+      </xsl:call-template>
+
+      <xsl:call-template name="insert-latest-nodes">
+        <xsl:with-param name="nodes"
+                    select="*/irspy:serverImplementationVersion"/>
+        <xsl:with-param name="what" select="'serverImplementationVersion'"/>
+      </xsl:call-template>
     </irspy:status>
   </xsl:template>
 
+
+  <!-- 
+       NB: This template assumes that the irspy:probe nodes come in ascending
+       order. If this is not the case, this template has to do some kind of
+       sorting which makes the whole thing more complicated.
+
+       Dec 12, 2006: Anders
+  -->
+  <xsl:template name="insert-latest-nodes">
+    <xsl:param name="nodes"/>
+    <xsl:param name="what" select="'unspecified'"/>
+    <xsl:param name="i" select="count(*/irspy:probe[@ok='1'])"/>
+    <xsl:variable name="date"
+        select="*/irspy:probe[@ok='1'][$i]"/>
+    <xsl:variable name="latest"
+        select="$nodes[irspy:strcmp(text(), $date) >= 0]"/>
+
+    <xsl:choose>
+      <xsl:when test="$latest">
+        <xsl:copy-of select="$latest"/>
+      </xsl:when>
+      <xsl:when test="$i > 0">
+        <xsl:call-template name="insert-latest-nodes">
+          <xsl:with-param name="what" select="$what"/>
+          <xsl:with-param name="nodes" select="$nodes"/>
+          <xsl:with-param name="i" select="$i - 1"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <irspy:missing what="{$what}" when="{$ping_date}"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
   
   <xsl:template match="node() | @*">
     <xsl:copy>
       </xsl:call-template>
     </xsl:param>
 
-    <index>
-      <xsl:attribute name="search">
-        <xsl:choose>
-          <xsl:when test="$update/@ok = 1">true</xsl:when>
-          <xsl:otherwise>false</xsl:otherwise>
-        </xsl:choose>
-      </xsl:attribute>
-      <title primary="true" lang="en">
-        <xsl:value-of select="$title"/>
-      </title>
-      <map primary="true">
-        <attr type="1" set="{$update/@set}">
-          <xsl:value-of select="$update/@ap"/>
-        </attr>
-      </map>
-    </index>
+    <xsl:if test="$update/@ok = 1">
+      <index search="true">
+        <title primary="true" lang="en"><xsl:value-of select="$title"/></title>
+        <map primary="true">
+          <attr type="1" set="{$update/@set}">
+            <xsl:value-of select="$update/@ap"/>
+          </attr>
+        </map>
+      </index>
+    </xsl:if>
   </xsl:template>