3 $Id: irspy2zeerex.xsl,v 1.17 2006-12-19 12:54:38 sondberg Exp $
5 This stylesheet is used by IRSpy to map the internal mixed Zeerex/IRSpy
6 record format into the Zeerex record which we store.
10 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
11 xmlns:irspy="http://indexdata.com/irspy/1.0"
12 xmlns="http://explain.z3950.org/dtd/2.0/"
13 xmlns:explain="http://explain.z3950.org/dtd/2.0/"
14 exclude-result-prefixes="irspy explain"
17 <xsl:output indent="yes"
22 <xsl:strip-space elements="*"/>
24 <xsl:variable name="old_indexes" select="/*/explain:indexInfo/explain:index"/>
25 <xsl:variable name="use_attr_names" select="document('use-attr-names.xml')"/>
26 <xsl:variable name="ping_date" select="/*/irspy:status/irspy:probe[last()]"/>
29 <xsl:template match="/*">
31 <xsl:call-template name="insert-zeerexBase"/>
32 <xsl:call-template name="insert-indexInfo"/>
33 <xsl:call-template name="insert-recordInfo"/>
34 <xsl:call-template name="insert-configInfo"/>
35 <xsl:call-template name="insert-irspySection"/>
40 <xsl:template name="insert-zeerexBase">
41 <xsl:copy-of select="explain:serverInfo"/>
42 <xsl:copy-of select="explain:databaseInfo"/>
44 <dateModified><xsl:value-of select="$ping_date"/></dateModified>
49 <xsl:template name="insert-indexInfo">
53 <!-- Check that search was actually probed -->
54 <xsl:when test="/*/irspy:status/irspy:search">
55 <xsl:for-each select="/*/irspy:status/irspy:search">
56 <xsl:variable name="set" select="@set"/>
57 <xsl:variable name="ap" select="@ap"/>
58 <xsl:variable name="old"
59 select="$old_indexes[explain:map/explain:attr/@set = $set and
60 explain:map/explain:attr/text() = $ap]"/>
62 <xsl:when test="$old">
63 <xsl:call-template name="insert-index-section">
64 <xsl:with-param name="title" select="$old/explain:title"/>
68 <xsl:call-template name="insert-index-section"/>
74 <!-- If not, insert what we already had... -->
76 <xsl:copy-of select="explain:indexInfo/*"/>
83 <xsl:template name="insert-recordInfo">
87 <!-- Did we actually probe record syntaxes? -->
88 <xsl:when test="/*/irspy:status/irspy:record">
89 <xsl:for-each select="/*/irspy:status/irspy:record_fetch[@ok = 1]">
90 <recordSyntax name="{@syntax}">
91 <elementSet name="F"/> <!-- FIXME: This should be probed too -->
96 <!-- If not, use the existing test report... -->
98 <xsl:copy-of select="explain:recordInfo/*"/>
105 <xsl:template name="insert-configInfo">
108 <xsl:when test="/*/irspy:status/irspy:init_opt">
109 <xsl:for-each select="/*/irspy:status/irspy:init_opt">
110 <supports type="z3950_{@option}">1</supports>
114 <xsl:copy-of select="explain:configInfo/*"/>
122 Here we list the bits and pieces of the irspy:status element which we
123 want to keep in the persistent version of the zeerex record.
125 <xsl:template name="insert-irspySection">
127 <xsl:copy-of select="*/irspy:probe"/>
129 <xsl:call-template name="insert-latest-nodes">
130 <xsl:with-param name="nodes" select="*/irspy:boolean"/>
131 <xsl:with-param name="what" select="'boolean'"/>
134 <xsl:call-template name="insert-latest-nodes">
135 <xsl:with-param name="nodes" select="*/irspy:named_resultset"/>
136 <xsl:with-param name="what" select="'named_resultset'"/>
139 <xsl:call-template name="insert-latest-nodes">
140 <xsl:with-param name="nodes" select="*/irspy:explain"/>
141 <xsl:with-param name="what" select="'explain'"/>
144 <xsl:call-template name="insert-latest-nodes">
145 <xsl:with-param name="nodes" select="*/irspy:serverImplementationId"/>
146 <xsl:with-param name="what" select="'serverImplementationId'"/>
149 <xsl:call-template name="insert-latest-nodes">
150 <xsl:with-param name="nodes" select="*/irspy:serverImplementationName"/>
151 <xsl:with-param name="what" select="'serverImplementationName'"/>
154 <xsl:call-template name="insert-latest-nodes">
155 <xsl:with-param name="nodes"
156 select="*/irspy:serverImplementationVersion"/>
157 <xsl:with-param name="what" select="'serverImplementationVersion'"/>
164 NB: This template assumes that the irspy:probe nodes come in ascending
165 order. If this is not the case, this template has to do some kind of
166 sorting which makes the whole thing more complicated.
170 <xsl:template name="insert-latest-nodes">
171 <xsl:param name="nodes"/>
172 <xsl:param name="what" select="'unspecified'"/>
173 <xsl:param name="i" select="count(*/irspy:probe[@ok='1'])"/>
174 <xsl:variable name="date"
175 select="*/irspy:probe[@ok='1' and position() = $i]"/>
176 <xsl:variable name="latest"
177 select="$nodes[irspy:strcmp(text(), $date) > 0]"/>
180 <xsl:when test="$latest">
181 <xsl:copy-of select="$latest"/>
183 <xsl:when test="$i > 0">
184 <xsl:call-template name="insert-latest-nodes">
185 <xsl:with-param name="what" select="$what"/>
186 <xsl:with-param name="nodes" select="$nodes"/>
187 <xsl:with-param name="i" select="$i - 1"/>
191 <irspy:missing what="{$what}" when="{$ping_date}"/>
197 <xsl:template match="node() | @*">
199 <xsl:apply-templates select="@* | node()"/>
204 <xsl:template name="insert-index-section">
205 <xsl:param name="update" select="."/>
206 <xsl:param name="title">
207 <xsl:call-template name="insert-index-title">
208 <xsl:with-param name="update" select="$update"/>
213 <xsl:attribute name="search">
215 <xsl:when test="$update/@ok = 1">true</xsl:when>
216 <xsl:otherwise>false</xsl:otherwise>
219 <title primary="true" lang="en">
220 <xsl:value-of select="$title"/>
223 <attr type="1" set="{$update/@set}">
224 <xsl:value-of select="$update/@ap"/>
231 <xsl:template name="insert-index-title">
232 <xsl:param name="update"/>
233 <xsl:variable name="name"
234 select="$use_attr_names/*/map[@attr = $update/@ap and
235 @set = $update/@set]/@name"/>
238 <xsl:when test="string-length($name) > 0"><xsl:value-of
239 select="$name"/></xsl:when>
240 <xsl:otherwise><xsl:value-of select="$update/@ap"/></xsl:otherwise>
245 <xsl:template match="*"/>