/[cvs]/nfo/perl/libs/XML/XUpdate/xupdate2xsl.xml
ViewVC logotype

Contents of /nfo/perl/libs/XML/XUpdate/xupdate2xsl.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations)
Wed May 7 13:01:33 2003 UTC (21 years ago) by joko
Branch: MAIN
Changes since 1.5: +45 -7 lines
File MIME type: text/xml
+ enhanced: [2.9 Variables and Values of Variables] - now has two modes - one like the spec and one additional
+ added comments regarding section numbers at http://www.xmldb.org/xupdate/xupdate-wd.html to identify what has been already implemented

1 <?xml version="1.0" encoding="ISO-8859-1"?>
2
3 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4
5 <!--
6
7 xupdate2xsl: Translate XML document from namespace 'xupdate' to 'xsl'.
8
9 Purpose of this XML Stylesheet is to implement a set of templates
10 to translate XUpdate lingo into an intermediate xslt stylesheet
11 which actually performs the update to the original xml document
12 in a second step.
13
14 The required glue code - written in Perl - is available in module
15 XML::XUpdate::XSLT. Please have a look at this in order to write
16 code to use this stylesheet from other language bindings.
17
18 Please have a look at the XUpdate specs and associated resources:
19 Requirements: http://www.xmldb.org/xupdate/xupdate-req.html
20 Working Draft: http://www.xmldb.org/xupdate/xupdate-wd.html
21
22 ChangeLog:
23 2003-04-30: first alpha
24 2003-05-01: works: xupdate:insert-after (elements/attributes)
25 2003-05-06: works: xupdate:insert-before (elements/attributes)
26
27 -->
28
29 <xsl:output method="xml" />
30
31 <!-- 1. This is the passthru logic (copy all untouched nodes). -->
32 <xsl:template name="passthru"><xsl:copy><xsl:apply-templates /></xsl:copy></xsl:template>
33 <!-- activate this -->
34 <xsl:template match="*"><xsl:call-template name="passthru" /></xsl:template>
35 <!-- override some builtin rules: see http://www.w3.org/TR/xslt#built-in-rule -->
36 <xsl:template match="comment()"><xsl:call-template name="passthru" /></xsl:template>
37
38
39 <!-- 2. This is the translation part: XUpdate becomes XSLT -->
40
41 <!-- lib -->
42 <!-- This node "encapsulates" common core infrastructure. -->
43 <xsl:template match="xupdate:modifications">
44
45 <!-- <xsl:template name="identity_template_rule"> -->
46 <xsl:element name="xsl:template">
47 <xsl:attribute name="name">identity_template_rule</xsl:attribute>
48
49 <!-- An "identity template rule" - original version by Mike Kay, Software AG -->
50 <!-- Please visit [http://p2p.wrox.com/archive/xslt/2001-06/98.asp] -->
51 <!-- Translated to "self hosting xsl": Andreas Motl, andreas.motl@ilo.de -->
52 <!-- FIXME: Could this be used to replace passthru-logic at 1. ? -->
53 <xsl:element name="xsl:copy">
54 <xsl:element name="xsl:copy-of">
55 <xsl:attribute name="select">@*</xsl:attribute>
56 </xsl:element>
57 <xsl:element name="xsl:apply-templates" />
58 </xsl:element>
59
60 </xsl:element>
61 <!-- </xsl:template> -->
62
63 <!--
64 1. Note: Former custom passthru logic (copy all untouched nodes)
65 now completely replaced by Mike Kay's "identity template rule".
66 What is left here is just the required overriding of some builtin rules
67 to (e.g.) not to loose comments.
68 -->
69 <xsl:comment> 1. override built-in rules </xsl:comment>
70 <!-- override some builtin rules: see http://www.w3.org/TR/xslt#built-in-rule -->
71 <xsl:element name="xsl:template"><xsl:attribute name="match">comment()</xsl:attribute>
72 <xsl:element name="xsl:call-template">
73 <xsl:attribute name="name">identity_template_rule</xsl:attribute>
74 </xsl:element>
75 </xsl:element>
76
77 <!-- continue with all inline nodes -->
78 <xsl:apply-templates />
79
80 </xsl:template>
81
82
83
84
85
86 <!-- code -->
87 <!-- This node "encapsulates" infrastructure for handling the directives. -->
88
89 <!-- Dispatch all "XUpdate Services" here. -->
90 <!-- FIXME: Actually implement action = "CREATE|RETRIEVE|UPDATE|DELETE"!!! -->
91
92 <!--
93 xsl for XUpdate Services [2 XUpdate Syntax] [2.3 Modifications]
94 -->
95
96 <!-- xsl for [2.4 Inserts] -->
97 <xsl:template match="xupdate:insert-after">
98 <!-- <xsl:variable name="select" select="@select">Hello World!</xsl:variable> -->
99 <xsl:call-template name="findcontext">
100 <xsl:with-param name="service">Insert</xsl:with-param>
101 <xsl:with-param name="position">after</xsl:with-param>
102 </xsl:call-template>
103 </xsl:template>
104
105 <!-- xsl for [2.4 Inserts] -->
106 <xsl:template match="xupdate:insert-before">
107 <xsl:call-template name="findcontext">
108 <xsl:with-param name="service">Insert</xsl:with-param>
109 <xsl:with-param name="position">before</xsl:with-param>
110 </xsl:call-template>
111 </xsl:template>
112
113 <!-- xsl for [2.5 Append] -->
114 <xsl:template match="xupdate:append">
115 <xsl:call-template name="findcontext">
116 <xsl:with-param name="service">Append</xsl:with-param>
117 <!-- <xsl:with-param name="position">inline</xsl:with-param> -->
118 <xsl:with-param name="test">.</xsl:with-param>
119 </xsl:call-template>
120 </xsl:template>
121
122 <!-- xsl for [2.6 Update] -->
123 <xsl:template match="xupdate:update">
124 <xsl:call-template name="findcontext">
125 <xsl:with-param name="service">Update</xsl:with-param>
126 <!-- <xsl:with-param name="position">after</xsl:with-param> -->
127 <xsl:with-param name="test">.</xsl:with-param>
128 </xsl:call-template>
129 </xsl:template>
130
131 <!-- xsl for [2.7 Remove] -->
132 <xsl:template match="xupdate:remove">
133 <xsl:call-template name="findcontext">
134 <xsl:with-param name="service">Remove</xsl:with-param>
135 <!-- <xsl:with-param name="position">after</xsl:with-param> -->
136 <xsl:with-param name="test">.</xsl:with-param>
137 </xsl:call-template>
138 </xsl:template>
139
140 <!-- xsl for [2.8 Rename] -->
141 <xsl:template match="xupdate:rename">
142 <xsl:call-template name="findcontext">
143 <xsl:with-param name="service">Rename</xsl:with-param>
144 <!-- <xsl:with-param name="position">after</xsl:with-param> -->
145 <xsl:with-param name="test">.</xsl:with-param>
146 </xsl:call-template>
147 </xsl:template>
148
149
150
151 <xsl:template name="findcontext">
152
153 <xsl:comment> 2. context finder </xsl:comment>
154
155 <!-- new of 2003-05-06: introducing parameters here to handle all cases -->
156 <xsl:param name="service" />
157 <xsl:param name="position" />
158 <!-- new of 2003-05-07: replacement for test if undef -->
159 <xsl:param name="test" />
160
161 <!--
162 <xsl:comment>
163 service: <xsl:value-of select="$service" />
164 position: <xsl:value-of select="$position" />
165 test: <xsl:value-of select="$test" />
166 </xsl:comment>
167 -->
168
169 <!-- this resembles some parts of the CRUD API - retranslated to self-hosting xsl -->
170
171 <!-- V1 -->
172 <!-- <xsl:element name="xsl:template"> -->
173 <!-- <xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute> -->
174
175 <!-- fallback -->
176 <xsl:element name="xsl:template">
177 <xsl:attribute name="match">*</xsl:attribute>
178 <xsl:element name="xsl:call-template">
179 <xsl:attribute name="name">identity_template_rule</xsl:attribute>
180 <!-- <xsl:attribute name="name">passthru</xsl:attribute> -->
181 </xsl:element>
182 </xsl:element>
183
184 <!-- V2 -->
185 <xsl:element name="xsl:template">
186 <!-- <xsl:attribute name="match">/addresses/address</xsl:attribute> -->
187 <!-- <xsl:attribute name="match">*</xsl:attribute> -->
188 <xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute>
189
190 <xsl:element name="xsl:choose">
191 <!-- <xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute> -->
192 <xsl:element name="xsl:when">
193 <!-- <xsl:attribute name="test"><xsl:value-of select="@select" /></xsl:attribute> -->
194 <xsl:attribute name="test"><xsl:value-of select="@test" /><xsl:value-of select="$test" /></xsl:attribute>
195
196 <xsl:choose>
197 <xsl:when test="{$service}=Insert">
198
199 <xsl:comment> 2.a. Insert </xsl:comment>
200
201 <!-- Implementation of "xupdate:insert-before" -->
202 <xsl:choose>
203 <xsl:when test="{$position}=before">
204 <xsl:apply-templates />
205 </xsl:when>
206 </xsl:choose>
207
208 <!-- call the "identity template rule" to passthru all childnodes -->
209 <xsl:element name="xsl:call-template">
210 <xsl:attribute name="name">identity_template_rule</xsl:attribute>
211 <!-- <xsl:attribute name="name">passthru</xsl:attribute> -->
212 </xsl:element>
213
214 <!-- Implementation of "xupdate:insert-after" -->
215 <xsl:choose>
216 <xsl:when test="{$position}=after">
217 <xsl:apply-templates />
218 </xsl:when>
219 </xsl:choose>
220
221 </xsl:when>
222
223 <!-- Implementation of "xupdate:append" -->
224 <xsl:when test="{$service}=Append">
225 <xsl:comment> 2.b. Append </xsl:comment>
226 <!-- V1 -->
227 <!-- <xsl:apply-templates /> -->
228 <!-- V2 -->
229 <xsl:element name="xsl:copy">
230 <!--
231 <xsl:element name="xsl:copy-of">
232 <xsl:attribute name="select">@*</xsl:attribute>
233 </xsl:element>
234 -->
235 <!-- Keep content ... -->
236 <xsl:element name="xsl:apply-templates" />
237 <!-- Append this: -->
238 <xsl:apply-templates />
239 </xsl:element>
240 </xsl:when>
241
242 <!-- Implementation of "xupdate:update" -->
243 <xsl:when test="{$service}=Update">
244 <xsl:comment> 2.c. Update </xsl:comment>
245 <!-- V1 -->
246 <!-- <xsl:apply-templates /> -->
247 <!-- V2 -->
248 <xsl:element name="xsl:copy">
249 <!--
250 <xsl:element name="xsl:copy-of">
251 <xsl:attribute name="select">@*</xsl:attribute>
252 </xsl:element>
253 -->
254 <!-- Keep content ... -->
255 <!-- <xsl:element name="xsl:apply-templates" /> -->
256 <!-- Add (replace through) this: -->
257 <xsl:apply-templates />
258 </xsl:element>
259 </xsl:when>
260
261 <!-- Implementation of "xupdate:remove" -->
262 <xsl:when test="{$service}=Remove">
263 <xsl:comment> 2.d. Remove </xsl:comment>
264 </xsl:when>
265
266 <!-- Implementation of "xupdate:rename" -->
267 <xsl:when test="{$service}=Rename">
268 <xsl:comment> 2.e. Rename (Remove context and Append modified identity template) </xsl:comment>
269
270 <xsl:comment> [5.a.] modify node name </xsl:comment>
271 <xsl:element name="xsl:element">
272 <!-- this renames the node (change the "name"-attribute) -->
273 <xsl:attribute name="name">
274 <xsl:apply-templates />
275 </xsl:attribute>
276 <!-- this propagates the original content -->
277 <xsl:element name="xsl:apply-templates" />
278 </xsl:element>
279
280 </xsl:when>
281
282 </xsl:choose>
283
284 </xsl:element>
285 <xsl:element name="xsl:otherwise">
286
287 <!-- call the "identity template rule" to passthru all childnodes -->
288 <xsl:element name="xsl:call-template">
289 <xsl:attribute name="name">identity_template_rule</xsl:attribute>
290 <!-- <xsl:attribute name="name">passthru</xsl:attribute> -->
291 </xsl:element>
292
293 <!-- <xsl:apply-templates /> -->
294 </xsl:element>
295
296 </xsl:element>
297 </xsl:element>
298
299 <!-- <xsl:apply-templates /> -->
300
301 </xsl:template>
302
303
304 <!--
305 Rewrite XUpdate elements to XSLT elements.
306 These templates pass through all attributes
307 and childnodes rewriting the tagname only.
308 FIXME: The redundant encoding for each XUpdate
309 element type seems dummy. Could this be stripped
310 shorter somehow sometimes?
311 -->
312
313 <!--
314 xsl for [2.4 Inserts]
315 -->
316
317 <!-- xsl for [2.4.1 Creating Elements] -->
318 <xsl:template match="xupdate:element">
319 <xsl:comment> 3.a. vivify generic node </xsl:comment>
320 <xsl:element name="xsl:element">
321 <xsl:copy-of select="@*"/>
322 <xsl:apply-templates />
323 </xsl:element>
324 </xsl:template>
325
326 <!-- xsl for [2.4.2 Creating Attributes] -->
327 <xsl:template match="xupdate:attribute">
328 <xsl:comment> 3.b. vivify node attributes </xsl:comment>
329 <xsl:element name="xsl:attribute">
330 <xsl:copy-of select="@*"/>
331 <xsl:apply-templates />
332 </xsl:element>
333 </xsl:template>
334
335 <!-- xsl for [2.4.3 Creating Text] -->
336 <xsl:template match="xupdate:text">
337 <xsl:comment> 4.a. vivify text node </xsl:comment>
338 <xsl:element name="xsl:text">
339 <xsl:copy-of select="@*"/>
340 <xsl:apply-templates />
341 </xsl:element>
342 </xsl:template>
343
344 <!-- xsl for [2.4.4 Creating Processing Instructions] -->
345 <xsl:template match="xupdate:processing-instruction">
346 <xsl:comment> 4.b. vivify PI node </xsl:comment>
347 <xsl:element name="xsl:processing-instruction">
348 <xsl:copy-of select="@*"/>
349 <xsl:apply-templates />
350 </xsl:element>
351 </xsl:template>
352
353 <!-- xsl for [2.4.5 Creating Comments] -->
354 <xsl:template match="xupdate:comment">
355 <xsl:comment> 4.c. vivify comment node </xsl:comment>
356 <xsl:element name="xsl:comment">
357 <xsl:copy-of select="@*"/>
358 <xsl:apply-templates />
359 </xsl:element>
360 </xsl:template>
361
362
363 <!--
364 xsl for [2.9 Variables and Values of Variables]
365 Encapsulates block payload into a named template.
366 -->
367 <xsl:template match="xupdate:variable">
368 <xsl:comment> 5.a. vivify xsl-element "variable" </xsl:comment>
369
370 <xsl:element name="xsl:template">
371 <xsl:attribute name="name">Variables</xsl:attribute>
372
373 <!--
374 <xsl:element name="xsl:variable">
375 <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
376 -->
377
378 <xsl:choose>
379
380 <!-- Mode 1 [spec]: just evaluate as (sub-)selection if "select"-attribute is not empty -->
381 <xsl:when test="@select!=">
382 <xsl:element name="xsl:apply-templates">
383 <xsl:attribute name="select"><xsl:value-of select="@select" /></xsl:attribute>
384 </xsl:element>
385 </xsl:when>
386
387 <!-- Mode 2 [feature]: in other cases: pass thru the current node w/o any operation(s) on it -->
388 <xsl:otherwise>
389 <xsl:value-of select="." />
390 </xsl:otherwise>
391
392 </xsl:choose>
393
394 <!--
395 </xsl:element>
396 -->
397
398 </xsl:element>
399
400 </xsl:template>
401
402 <!--
403 xsl for [2.9 Variables and Values of Variables]
404 Calls encapsulated named template "Variables"
405 for each occourance of an "xupdate:value-of" element.
406 -->
407 <xsl:template match="xupdate:value-of">
408 <xsl:comment> 5.b. vivify xsl-element "value-of" </xsl:comment>
409 <xsl:element name="xsl:call-template">
410 <xsl:attribute name="name">Variables</xsl:attribute>
411 </xsl:element>
412
413 <!-- is this required any more??? -->
414 <xsl:element name="xsl:value-of">
415 <xsl:copy-of select="@*"/>
416 <!-- <xsl:apply-templates /> -->
417 <!-- this propagates the original content -->
418 <!-- <xsl:element name="xsl:apply-templates"> -->
419 <!-- <xsl:attribute name="" > -->
420 <!-- </xsl:element> -->
421 </xsl:element>
422 </xsl:template>
423
424
425 </xsl:stylesheet>
426

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed