source: MDService2/trunk/MDService2/src/xsl/XCQL2Xpath.xsl @ 1029

Last change on this file since 1029 was 1029, checked in by vronk, 13 years ago

changes to columns, terms (unfinished) ; .ui-context-dialog

File size: 6.2 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<xsl:stylesheet
3  version="2.0"
4  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:my="myFunctions">
5
6<!--
7<purpose>transform XCQL to xpath
8! WARNING: not pure Xpath! actually it adapts the query on the query-interface of MD-Repository
9in particular there is special handling for index "collection"
10</purpose>
11<history>
12        <change on="2010-01-28" type="created" by="vr"></change>                       
13        <change on="2010-07-01" type="changed" by="vr">handling of collection-filter</change>
14</history>
15<sample>
16<triple>
17  <boolean>
18    <value>and</value>
19  </boolean>
20  <leftOperand>
21    <searchClause>
22      <index>bath.author</index>
23      <relation>
24        <value>any</value>
25      </relation>
26      <term>fish</term>
27    </searchClause>
28  </leftOperand>
29  <rightOperand>
30    <searchClause>
31      <index>dc.title</index>
32      <relation>
33        <value>all</value>
34      </relation>
35      <term>cat dog</term>
36    </searchClause>
37  </rightOperand>
38</triple>
39</sample>
40      -->
41     
42
43<xsl:include href="cmd_functions.xsl"/>
44<!--<xsl:include href="params.xsl"/>
45<xsl:variable name="terms_setup" select="document($terms_setup_uri)" />
46<xsl:variable name="terms_flat" select="document($terms_flat_uri)" />
47-->
48<xsl:output method="text" />
49
50       
51<xsl:template match="triple">
52
53        <xsl:choose>
54        <!--  this is rather hacky yet
55aim is: special handling of collection-index (as separate parameter)
56precondition: collection-index just as rightOperand on top-nesting-level and boolean='and'
57 -->
58                <xsl:when test="rightOperand/searchClause/index='collection'" >
59                        <xsl:apply-templates select="leftOperand/*" />
60                        <xsl:apply-templates select="rightOperand/*" mode="collection"/>                       
61                </xsl:when>
62                <xsl:otherwise>
63                        <xsl:if test="not(ancestor::triple)" >//CMD/*[</xsl:if>                 
64                                <xsl:call-template name="boolean" >
65                                        <xsl:with-param name="op" select="boolean/value" />
66                                        <xsl:with-param name="left" >
67                                                <xsl:apply-templates select="leftOperand/*" />
68                                        </xsl:with-param>
69                                        <xsl:with-param name="right" >
70                                                <xsl:apply-templates select="rightOperand/*" />
71                                        </xsl:with-param>
72                                </xsl:call-template>
73                        <xsl:if test="not(ancestor::triple)" >]</xsl:if>                               
74                </xsl:otherwise>
75        </xsl:choose>
76       
77</xsl:template>
78
79<xsl:template name="boolean">
80        <xsl:param name="op" />
81        <xsl:param name="left" />
82        <xsl:param name="right" />
83        <xsl:message>XCQL2XPath.template-boolean.$op:<xsl:value-of select="$op" /></xsl:message>
84       
85
86        <xsl:choose>
87                <xsl:when test="$op='and'">
88                        <xsl:text></xsl:text>
89                        <xsl:value-of select="$left" />
90                        <xsl:text>][</xsl:text><xsl:value-of select="$right" /><xsl:text></xsl:text>
91                </xsl:when>
92                <xsl:when test="$op='or'">
93                        <xsl:value-of select="$left" />
94                        <xsl:text>%20or%20</xsl:text><xsl:value-of select="$right" />
95                </xsl:when>             
96        </xsl:choose>
97       
98       
99</xsl:template>
100
101<xsl:template match="searchClause">
102        <xsl:apply-templates select="index" />
103        <xsl:apply-templates select="relation">
104                <xsl:with-param name="term" select="term" />
105        </xsl:apply-templates> 
106</xsl:template>
107
108
109<!--   aim is: special handling of collection-filter (as separate parameter) -->
110<xsl:template match="searchClause" mode="collection">
111                <xsl:text>&amp;collection=</xsl:text><xsl:value-of select="term"></xsl:value-of>               
112</xsl:template>
113
114<xsl:template match="index">
115
116        <!-- reverting the "escaping" of whitespaces in indices with datcat-name -->
117        <xsl:variable name="ix_string" select="replace(text(),'_',' ')" />
118       
119        <xsl:variable name="ix_resolved" >     
120                <xsl:choose>
121                        <xsl:when test="contains(.,':')">
122                                <xsl:variable name="prefix" select="substring-before(.,':')" />                         
123                                <xsl:variable name="termset" select="$terms_setup/Termsets/Termset[@id=$prefix]" />                             
124                               
125                                <xsl:message>XCQL2XPath.index:<xsl:copy-of select="$termset"/>
126                                                                ix_string:<xsl:value-of select="$ix_string"/>
127                                </xsl:message>
128                                <xsl:choose>
129                                <!-- magic happening here  -->
130                                        <xsl:when test="$termset[@type='dcr' or @type='rr']">
131                                                <xsl:variable name="expanded_context" select="$terms_flat//context[@path=$ix_string]"></xsl:variable>
132                                                        <xsl:variable name="expanded_query" >
133                                                                <xsl:text>(</xsl:text>
134                                                                <xsl:for-each select="distinct-values($expanded_context//context[@elem]/@path)">
135                                                                        <xsl:variable name="prefix" select="substring-before(.,':')" />
136                                                                        <xsl:variable name="termset" select="$terms_setup/Termsets/Termset[@id=$prefix]" />                                                                     
137                                                                        <xsl:value-of select="concat($termset/@name,'//',substring-after(.,':'))" />
138                                                                        <xsl:if test="position()!=last()"><xsl:text>|</xsl:text></xsl:if>
139                                                                </xsl:for-each>
140                                                                <xsl:text>)</xsl:text>
141                                                        </xsl:variable>
142                                                        <xsl:message>expanded-context:<xsl:value-of select="$expanded_query" /></xsl:message>
143                                                <xsl:value-of select="$expanded_query" />
144                                        </xsl:when>
145                                        <xsl:otherwise>
146                                                <xsl:value-of select="concat($termset/@name,'//',substring-after(.,':'))" />   
147                                        </xsl:otherwise>
148                                </xsl:choose>
149                                 
150                        </xsl:when>
151                        <xsl:otherwise><xsl:value-of select="." />
152                        </xsl:otherwise>
153                </xsl:choose>           
154               
155        </xsl:variable>
156        <!-- <xsl:variable name="ix_xpathed" select="translate($ix_resolved, '.', '/')" ></xsl:variable> -->
157        <xsl:variable name="ix_xpathed" select="my:index2xpath(.)" ></xsl:variable> 
158        <xsl:choose>
159                <xsl:when test=".='cql.serverChoice' or .='*'" >//Components</xsl:when>                         
160                <xsl:when test="ancestor::triple" >
161                        <xsl:value-of select="concat('.//',$ix_xpathed)" />
162                </xsl:when>
163                <xsl:otherwise>         
164                        <xsl:value-of select="concat('//',$ix_xpathed)" />     
165                </xsl:otherwise>
166        </xsl:choose>
167</xsl:template>
168
169<xsl:template match="relation">
170        <xsl:param name="term" />
171       
172        <xsl:text>[</xsl:text>
173                <xsl:choose>                   
174                        <xsl:when test="value='contains' or preceding-sibling::index='cql.serverChoice'" >
175                                <xsl:text>contains(.,'</xsl:text><xsl:value-of select="$term"/><xsl:text>')</xsl:text>                         
176                        </xsl:when>
177                        <xsl:when test="value='any'" >
178                        <!--  use full-text querying: [ft:query(., "language")] -->
179                                <xsl:text>ft:query(.,'</xsl:text><xsl:value-of select="$term"/><xsl:text>')</xsl:text>
180                                                                       
181                        </xsl:when>
182                        <xsl:otherwise>         
183                                <xsl:text>.</xsl:text> <xsl:value-of select="value" />
184                                <xsl:text>'</xsl:text><xsl:value-of select="$term"/><xsl:text>'</xsl:text>     
185                        </xsl:otherwise>
186                </xsl:choose>   
187        <xsl:text>]</xsl:text>
188       
189</xsl:template>
190
191
192</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.