Updating the recordSyntax elements too.
[irspy-moved-to-github.git] / xsl / irspy2zeerex.xsl
1 <?xml version="1.0"?>
2 <!--
3     $Id: irspy2zeerex.xsl,v 1.4 2006-10-27 12:27:38 sondberg 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:preserve-space elements="*"/>
23
24   <xsl:variable name="old_indexes" select="/*/explain:indexInfo/explain:index"/>
25   <xsl:variable name="old_syntaxes" select="/*/explain:recordInfo"/>
26
27
28   <xsl:template match="node() | @*">
29     <xsl:copy>
30       <xsl:apply-templates select="@* | node()"/>
31     </xsl:copy>
32   </xsl:template>
33
34
35   <xsl:template match="explain:indexInfo">
36     <indexInfo>
37       <xsl:for-each select="/*/irspy:status/irspy:search">
38         <xsl:variable name="set" select="@set"/>
39         <xsl:variable name="ap" select="@ap"/>
40         <xsl:variable name="old"
41             select="$old_indexes[explain:map/explain:attr/@set = $set and
42                                  explain:map/explain:attr/text() = $ap]"/>
43         <xsl:choose>
44           <xsl:when test="$old">
45             <xsl:call-template name="insert-index-section">
46               <xsl:with-param name="title" select="$old/explain:title"/>
47             </xsl:call-template>
48           </xsl:when>
49           <xsl:otherwise>
50             <xsl:call-template name="insert-index-section"/>
51           </xsl:otherwise>
52         </xsl:choose>
53       </xsl:for-each>
54     </indexInfo>
55   </xsl:template>
56
57
58   <xsl:template match="explain:recordInfo">
59     <recordInfo>
60       <xsl:for-each select="/*/irspy:status/irspy:record_fetch[@ok = 1]">
61         <recordSyntax name="{@syntax}">
62           <elementSet name="F"/> <!-- FIXME: This should be probed too -->
63         </recordSyntax>
64       </xsl:for-each>
65     </recordInfo>
66   </xsl:template>
67
68
69   <xsl:template name="insert-index-section">
70     <xsl:param name="update" select="."/>
71     <xsl:param name="title">
72       <xsl:call-template name="insert-index-title">
73         <xsl:with-param name="update" select="$update"/>
74       </xsl:call-template>
75     </xsl:param>
76
77     <index>
78       <xsl:attribute name="search">
79         <xsl:choose>
80           <xsl:when test="$update/@ok = 1">true</xsl:when>
81           <xsl:otherwise>false</xsl:otherwise>
82         </xsl:choose>
83       </xsl:attribute>
84       <title primary="true" lang="en">
85         <xsl:value-of select="$title"/>
86       </title>
87       <map primary="true">
88         <attr type="1" set="{$update/@set}">
89           <xsl:value-of select="$update/@ap"/>
90         </attr>
91       </map>
92     </index>
93   </xsl:template>
94
95
96   <xsl:template name="insert-index-title">
97     <xsl:param name="update"/>
98     <xsl:value-of select="$update/@ap"/>
99   </xsl:template>
100
101
102   <xsl:template match="explain:dateModified">
103     <dateModified><xsl:value-of
104                     select="/*/irspy:status/*[last()]"/></dateModified>
105   </xsl:template>
106
107
108 </xsl:stylesheet>