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 && xsltproc identity.xsl 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 && xsltproc identity.xsl 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 <xsl:template match="/query">
19 <xsl:apply-templates/>
23 <xsl:template match="rpn">
25 <xsl:attribute name="set">
26 <xsl:value-of select="@set"/>
28 <xsl:apply-templates/>
33 <xsl:template match="apt">
35 <xsl:apply-templates select="attr"/>
36 <xsl:apply-templates select="term"/>
37 <!-- re-ordering @attr's if you use the following -->
39 <xsl:apply-templates select="attr[@type=1]"/>
40 <xsl:apply-templates select="attr[@type=2]"/>
41 <xsl:apply-templates select="attr[@type=4]"/>
42 <xsl:apply-templates select="attr[@type=5]"/>
43 <xsl:apply-templates select="attr[@type=6]"/>
44 <xsl:apply-templates select="attr[@type=7]"/>
45 <xsl:apply-templates select="attr[@type=8]"/>
46 <xsl:apply-templates select="attr[@type=9]"/>
47 <xsl:apply-templates select="term"/>
52 <xsl:template match="operator">
54 <xsl:attribute name="type">
55 <xsl:value-of select="@type"/>
57 <xsl:apply-templates/>
61 <xsl:template match="attr">
62 <xsl:copy-of select="."/>
65 <xsl:template match="term">
66 <xsl:copy-of select="."/>
70 <!-- special rewrite templates -->
72 <!-- attribute rewrites -->
74 <!-- remove all @attr 6=3 with bracket syntax -->
75 <xsl:template match="attr[@type=6][@value=3]">
78 <!-- remove all @attr 6=4 with and syntax -->
79 <xsl:template match="attr[@type=6 and @value=4]">
82 <!-- rewrite all @attr 4=2 to @attr 4=1 -->
83 <xsl:template match="attr[@type=4][@value=2]">
84 <attr type="4" value="1"/>
87 <!-- rewrite all @attr 1=1016 to @attr 1=1016 @attr 6=2 -->
88 <xsl:template match="attr[@type=1 and @value=1016]">
89 <attr type="1" value="1016"/>
90 <attr type="6" value="2"/>
95 <!-- term rewrites -->
97 <!-- rewrite general term fish to squid -->
98 <xsl:template match="term[@type='general'][text()='fish']">
99 <term type="general">squid</term>
103 <!-- operator rewrites -->
104 <!-- nasty rewrite 'not' operator to 'and' operator -->
106 <xsl:template match="operator[@type='not']">
108 <xsl:attribute name="type">
109 <xsl:value-of select="'and'"/>
111 <xsl:apply-templates/>
116 <!-- remove 'not' operator, use first <apt> only -->
117 <xsl:template match="operator[@type='not']">
118 <xsl:apply-templates select="apt[1]"/>
123 <!-- more nasty things for special occasions
124 depending on multiple attribute combinations -->
126 <!-- whenever there is a <apt> containing a @attr 7 and a @attr 8,
127 rewrite these and drop all @attr 3,
128 finally sort all other @attrs according to type
129 and call all terms, still rewriting 'fish' to 'squid' -->
131 <xsl:template match="apt[attr/@type=7 and attr/@type=8]">
133 <xsl:apply-templates select="attr[@type=1]"/>
134 <xsl:apply-templates select="attr[@type=2]"/>
135 <xsl:apply-templates select="attr[@type=4]"/>
136 <xsl:apply-templates select="attr[@type=5]"/>
137 <xsl:apply-templates select="attr[@type=6]"/>
138 <attr type="7" value="2"/>
139 <attr type="8" value="5"/>
140 <xsl:apply-templates select="attr[@type=9]"/>
141 <xsl:apply-templates select="term"/>