Windows: use Boost 1.59, msvc 14.0
[metaproxy-moved-to-github.git] / etc / pqf2pqf-loc.xsl
1 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2   version="1.0">
3
4   <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
5
6   <!--
7 ./yaz-xmlquery -p '@and @attr 1=1016 @attr 4=2 @attr 6=3 the @attr 1=4 fish' > test.xml && xmllint -format test.xml && ./yaz-xmlquery -x test1.xml && xsltproc pqf2pqf.xsl test.xml |tee test2.xml && ./yaz-xmlquery -x test2.xml 
8
9 ./yaz-xmlquery -p '@not @attr 1=1016 @attr 4=2 @attr 6=3 @attr 7=1 @attr 8=4 fish @attr 1=4 fish' > test.xml && xmllint -format test.xml && ./yaz-xmlquery -x test.xml && xsltproc pqf2pqf.xsl test.xml |tee test2.xml && ./yaz-xmlquery -x test2.xml 
10   -->
11
12   <!-- disable default templates -->
13   <xsl:template match="text()"/>
14   <xsl:template match="node()"/>
15
16   <!-- identity stylesheet templates -->
17   <!-- these parse pqf-xml input recursively and make identity operations -->
18   <xsl:template match="/query">
19     <query>
20       <xsl:apply-templates/>
21     </query>
22   </xsl:template>
23
24   <xsl:template match="rpn">
25     <rpn>
26       <xsl:attribute name="set">
27         <xsl:value-of  select="@set"/>
28       </xsl:attribute>
29       <xsl:apply-templates/>
30     </rpn>
31   </xsl:template>
32
33   <xsl:template match="operator">
34     <operator>
35       <xsl:attribute name="type">
36         <xsl:value-of  select="@type"/>
37       </xsl:attribute>
38       <xsl:apply-templates/>
39     </operator>
40   </xsl:template>
41
42   <xsl:template match="apt">
43     <apt>
44       <xsl:apply-templates select="attr"/>
45       <xsl:apply-templates select="term"/>
46     </apt>
47   </xsl:template>
48
49   <xsl:template match="attr">
50     <xsl:copy-of select="."/>
51   </xsl:template>
52
53   <xsl:template match="term">
54     <xsl:copy-of select="."/>
55   </xsl:template>
56
57   <!-- validate use attributes -->
58   <xsl:template match="attr[@type=1]">
59     <xsl:choose>
60        <xsl:when test="@value &gt;= 1 and @value &lt;= 11">
61          <xsl:copy-of select="."/>
62        </xsl:when>
63        <xsl:when test="@value &gt;= 13 and @value &lt;= 1010">
64          <xsl:copy-of select="."/>
65        </xsl:when>
66        <xsl:when test="@value &gt;= 1013 and @value &lt;= 1023">
67          <xsl:copy-of select="."/>
68        </xsl:when>
69        <xsl:when test="@value &gt;= 1025 and @value &lt;= 1030">
70          <xsl:copy-of select="."/>
71        </xsl:when>
72        <xsl:otherwise>
73          <diagnostic code="114" addinfo="{@value}"/>
74        </xsl:otherwise>
75     </xsl:choose>
76   </xsl:template>
77
78   <!-- validate relation attributes -->
79   <xsl:template match="attr[@type=2]">
80     <xsl:choose>
81        <xsl:when test="@value &gt;= 1 and @value &lt;= 6">
82          <xsl:copy-of select="."/>
83        </xsl:when>
84        <xsl:otherwise>
85          <diagnostic code="117" addinfo="{@value}"/>
86        </xsl:otherwise>
87     </xsl:choose>
88   </xsl:template>
89
90   <!-- validate position attributes -->
91   <xsl:template match="attr[@type=3]">
92     <xsl:choose>
93        <xsl:when test="@value &gt;= 1 and @value &lt;= 3">
94          <xsl:copy-of select="."/>
95        </xsl:when>
96        <xsl:otherwise>
97          <diagnostic code="119" addinfo="{@value}"/>
98        </xsl:otherwise>
99     </xsl:choose>
100   </xsl:template>
101
102   <!-- validate structure attributes -->
103   <xsl:template match="attr[@type=4]">
104     <xsl:choose>
105        <xsl:when test="@value &gt;= 1 and @value &lt;= 6">
106          <xsl:copy-of select="."/>
107        </xsl:when>
108        <xsl:otherwise>
109          <diagnostic code="118" addinfo="{@value}"/>
110        </xsl:otherwise>
111     </xsl:choose>
112   </xsl:template>
113
114   <!-- validate truncation attributes -->
115   <xsl:template match="attr[@type=5]">
116     <xsl:choose>
117        <xsl:when test="@value = 1 or @value = 100">
118          <xsl:copy-of select="."/>
119        </xsl:when>
120        <xsl:otherwise>
121          <diagnostic code="120" addinfo="{@value}"/>
122        </xsl:otherwise>
123     </xsl:choose>
124   </xsl:template>
125
126   <!-- validate completeness attributes -->
127   <xsl:template match="attr[@type=6]">
128     <xsl:choose>
129        <xsl:when test="@value &gt;= 1 and @value &lt;= 3">
130          <xsl:copy-of select="."/>
131        </xsl:when>
132        <xsl:otherwise>
133          <diagnostic code="122" addinfo="{@value}"/>
134        </xsl:otherwise>
135     </xsl:choose>
136   </xsl:template>
137
138   <!-- throw error for other types -->
139   <xsl:template match="attr[@type &gt;= 7]">
140      <diagnostic code="113" addinfo="{@type}"/>
141   </xsl:template>
142
143 </xsl:stylesheet>
144
145