1 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
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
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
12 <!-- disable default templates -->
13 <xsl:template match="text()"/>
14 <xsl:template match="node()"/>
16 <!-- identity stylesheet templates -->
17 <!-- these parse pqf-xml input recursively and make identity operations -->
18 <xsl:template match="/query">
20 <xsl:apply-templates/>
24 <xsl:template match="rpn">
26 <xsl:attribute name="set">
27 <xsl:value-of select="@set"/>
29 <xsl:apply-templates/>
33 <xsl:template match="operator">
35 <xsl:attribute name="type">
36 <xsl:value-of select="@type"/>
38 <xsl:apply-templates/>
42 <xsl:template match="apt">
44 <!-- no re-ordering @attr's if you use the following -->
46 <xsl:apply-templates select="attr"/>
48 <xsl:apply-templates select="attr[@type=1]"/>
49 <xsl:apply-templates select="attr[@type=2]"/>
50 <xsl:apply-templates select="attr[@type=4]"/>
51 <xsl:apply-templates select="attr[@type=5]"/>
52 <xsl:apply-templates select="attr[@type=6]"/>
53 <xsl:apply-templates select="attr[@type=7]"/>
54 <xsl:apply-templates select="attr[@type=8]"/>
55 <xsl:apply-templates select="attr[@type=9]"/>
56 <xsl:apply-templates select="term"/>
60 <xsl:template match="attr">
61 <xsl:copy-of select="."/>
64 <xsl:template match="term">
65 <xsl:copy-of select="."/>
69 <!-- special rewrite templates
70 these are kicking in when special conditions apply -->
73 <!-- attribute rewrites -->
75 <!-- remove all @attr 6=3 with bracket syntax -->
77 <xsl:template match="attr[@type=6][@value=3]">
81 <!-- remove all @attr 6=4 with and syntax -->
83 <xsl:template match="attr[@type=6 and @value=4]">
87 <!-- rewrite all @attr 4=2 to @attr 4=1 -->
89 <xsl:template match="attr[@type=4][@value=2]">
90 <attr type="4" value="1"/>
94 <!-- rewrite all @attr 1=1016 to @attr 1=1016 @attr 6=2 -->
95 <!-- this will leave double @attr 6=? nodes, unless you remove all
96 @attr 6=? nodes in some other template -->
98 <xsl:template match="attr[@type=1 and @value=1016]">
99 <attr type="1" value="1016"/>
100 <attr type="6" value="2"/>
105 <!-- rules depending on multiple attribute combinations -->
107 <!-- whenever there is a <apt> containing an @attr 7 and an @attr 8,
108 rewrite these and drop all @attr 3 .
109 Notice that the selection rules can equally either be written
110 'attr/@type=7' or 'attr[@type=8]' with no difference -->
112 <xsl:template match="apt[attr/@type=7 and attr[@type=8]]">
114 <xsl:apply-templates select="attr[@type=1]"/>
115 <xsl:apply-templates select="attr[@type=2]"/>
116 <xsl:apply-templates select="attr[@type=4]"/>
117 <xsl:apply-templates select="attr[@type=5]"/>
118 <xsl:apply-templates select="attr[@type=6]"/>
119 <attr type="7" value="2"/>
120 <attr type="8" value="5"/>
121 <xsl:apply-templates select="attr[@type=9]"/>
122 <xsl:apply-templates select="term"/>
127 <!-- whenever there is an apt containing an @attr 7=1, an @attr 8=4, and
128 an @attr 1=? (of any value), let @attr 1=? pass unaltered, drop
129 @attr 3=? totally, and rewrite @attr 7=1 and @attr 8=4 .
130 Notice that this rule can equally be written either with 'and'
131 connecting the attribute type and value, or with a double '[]'.-->
133 <xsl:template match="apt[attr[@type=7 and @value=1]
134 and attr[@type=8][@value=4]
135 and attr[@type=1]] ">
137 <xsl:apply-templates select="attr[@type=1]"/>
138 <xsl:apply-templates select="attr[@type=2]"/>
139 <xsl:apply-templates select="attr[@type=4]"/>
140 <xsl:apply-templates select="attr[@type=5]"/>
141 <xsl:apply-templates select="attr[@type=6]"/>
142 <attr type="7" value="2"/>
143 <attr type="8" value="5"/>
144 <xsl:apply-templates select="attr[@type=9]"/>
145 <xsl:apply-templates select="term"/>
151 <!-- term rewrites -->
153 <!-- rewrite general term fish to squid -->
155 <xsl:template match="term[@type='general'][text()='fish']">
156 <term type="general">squid</term>
160 <!-- operator rewrites -->
162 <!-- remove 'not' operator, use first <apt> only -->
164 <xsl:template match="operator[@type='not']">
165 <xsl:apply-templates select="apt[1]"/>
169 <!-- nasty rewrite 'not' operator to 'and' operator -->
171 <xsl:template match="operator[@type='not']">
173 <xsl:attribute name="type">
174 <xsl:value-of select="'and'"/>
176 <xsl:apply-templates/>