4c630561a6a0389c706713c63973875ee9c0244b
[irspy-moved-to-github.git] / xsl / irspy2zeerex.xsl
1 <?xml version="1.0"?>
2 <!--
3     $Id: irspy2zeerex.xsl,v 1.12 2006-12-06 12:58:32 mike Exp $
4
5     This stylesheet is used by IRSpy to map the internal mixed Zeerex/IRSpy
6     record format into the Zeerex record which we store.
7
8 -->
9 <xsl:stylesheet
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"
15     version="1.0">
16
17   <xsl:output indent="yes"
18       method="xml"
19       version="1.0"
20       encoding="UTF-8"/>
21
22   <xsl:strip-space elements="*"/>
23
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
27
28   <xsl:template match="/*">
29     <explain>
30       <xsl:call-template name="insert-zeerexBase"/>
31       <xsl:call-template name="insert-indexInfo"/>
32       <xsl:call-template name="insert-recordInfo"/>
33       <xsl:call-template name="insert-configInfo"/>
34       <xsl:call-template name="insert-irspySection"/>
35     </explain>
36   </xsl:template>
37
38
39   <xsl:template name="insert-zeerexBase">
40     <xsl:copy-of select="explain:serverInfo"/>
41     <xsl:copy-of select="explain:databaseInfo"/>
42     <metaInfo>
43       <dateModified><xsl:value-of
44                     select="/*/irspy:status/*[last()]"/></dateModified>
45     </metaInfo>
46   </xsl:template>
47
48
49   <xsl:template name="insert-indexInfo">
50     <indexInfo>
51       <xsl:for-each select="/*/irspy:status/irspy:search">
52         <xsl:variable name="set" select="@set"/>
53         <xsl:variable name="ap" select="@ap"/>
54         <xsl:variable name="old"
55             select="$old_indexes[explain:map/explain:attr/@set = $set and
56                                  explain:map/explain:attr/text() = $ap]"/>
57         <xsl:choose>
58           <xsl:when test="$old">
59             <xsl:call-template name="insert-index-section">
60               <xsl:with-param name="title" select="$old/explain:title"/>
61             </xsl:call-template>
62           </xsl:when>
63           <xsl:otherwise>
64             <xsl:call-template name="insert-index-section"/>
65           </xsl:otherwise>
66         </xsl:choose>
67       </xsl:for-each>
68     </indexInfo>
69   </xsl:template>
70
71
72   <xsl:template name="insert-recordInfo">
73     <recordInfo>
74       <xsl:for-each select="/*/irspy:status/irspy:record_fetch[@ok = 1]">
75         <recordSyntax name="{@syntax}">
76           <elementSet name="F"/> <!-- FIXME: This should be probed too -->
77         </recordSyntax>
78       </xsl:for-each>
79     </recordInfo>
80   </xsl:template>
81
82
83   <xsl:template name="insert-configInfo">
84     <configInfo>
85       <xsl:for-each select="/*/irspy:status/irspy:init_opt">
86         <supports type="z3950_{@option}">1</supports>
87       </xsl:for-each>
88     </configInfo>
89   </xsl:template>
90
91
92   <!-- 
93        Here we list the bits and pieces of the irspy:status element which we
94        want to keep in the persistent version of the zeerex record.
95        Simply add "| irspy:xxx" to the select attribute.
96   -->
97   <xsl:template name="insert-irspySection">
98     <irspy:status>
99       <xsl:for-each select="*/irspy:probe   |
100                             */irspy:boolean |
101                             */irspy:named_resultset |
102                             */irspy:explain">
103         <xsl:copy-of select="."/>
104       </xsl:for-each>
105     </irspy:status>
106   </xsl:template>
107
108   
109   <xsl:template match="node() | @*">
110     <xsl:copy>
111       <xsl:apply-templates select="@* | node()"/>
112     </xsl:copy>
113   </xsl:template>
114
115
116   <xsl:template name="insert-index-section">
117     <xsl:param name="update" select="."/>
118     <xsl:param name="title">
119       <xsl:call-template name="insert-index-title">
120         <xsl:with-param name="update" select="$update"/>
121       </xsl:call-template>
122     </xsl:param>
123
124     <index>
125       <xsl:attribute name="search">
126         <xsl:choose>
127           <xsl:when test="$update/@ok = 1">true</xsl:when>
128           <xsl:otherwise>false</xsl:otherwise>
129         </xsl:choose>
130       </xsl:attribute>
131       <title primary="true" lang="en">
132         <xsl:value-of select="$title"/>
133       </title>
134       <map primary="true">
135         <attr type="1" set="{$update/@set}">
136           <xsl:value-of select="$update/@ap"/>
137         </attr>
138       </map>
139     </index>
140   </xsl:template>
141
142
143   <xsl:template name="insert-index-title">
144     <xsl:param name="update"/>
145     <xsl:variable name="name"
146                 select="$use_attr_names/*/map[@attr = $update/@ap and
147                                               @set = $update/@set]/@name"/>
148
149     <xsl:choose>
150       <xsl:when test="string-length($name) &gt; 0"><xsl:value-of
151                                             select="$name"/></xsl:when>
152       <xsl:otherwise><xsl:value-of select="$update/@ap"/></xsl:otherwise>
153     </xsl:choose>
154   </xsl:template>
155
156
157   <xsl:template match="*"/>
158
159 </xsl:stylesheet>