4 |
|
|
5 |
<!-- |
<!-- |
6 |
|
|
7 |
xupdate2xsl: Translate XML document from namespace 'xupdate' to 'xsl'. |
xupdate2xsl: Translate XML document from namespace 'xupdate' to 'xsl'. |
8 |
|
|
9 |
Purpose of this XML Stylesheet is to implement a set of templates |
Purpose of this XML Stylesheet is to implement a set of templates |
10 |
to translate XUpdate lingo into an intermediate xslt stylesheet |
to translate XUpdate lingo into an intermediate xslt stylesheet |
11 |
which actually performs the update to the original xml document |
which actually performs the update to the original xml document |
12 |
in a second step. |
in a second step. |
13 |
|
|
14 |
The required glue code - written in Perl - is available in module |
The required glue code - written in Perl - is available in module |
15 |
XML::XUpdate::XSLT. Please have a look at this in order to use |
XML::XUpdate::XSLT. Please have a look at this in order to write |
16 |
this stylesheet from other bindings. |
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" /> |
<xsl:output method="xml" /> |
60 |
</xsl:element> |
</xsl:element> |
61 |
<!-- </xsl:template> --> |
<!-- </xsl:template> --> |
62 |
|
|
63 |
<!-- 1. This is the passthru logic (copy all untouched nodes). --> |
<!-- |
64 |
<!-- in fact this is the xsl from above translated to be able to be generated by xsl itself! --> |
1. Note: Former custom passthru logic (copy all untouched nodes) |
65 |
<xsl:comment> 1. passthru logic </xsl:comment> |
now completely replaced by Mike Kay's "identity template rule". |
66 |
<xsl:element name="xsl:template"> |
What is left here is just the required overriding of some builtin rules |
67 |
<xsl:attribute name="name">passthru</xsl:attribute> |
to (e.g.) not to loose comments. |
68 |
<xsl:element name="xsl:copy"><xsl:element name="xsl:apply-templates" /></xsl:element> |
--> |
69 |
</xsl:element> |
<xsl:comment> 1. override built-in rules </xsl:comment> |
70 |
<xsl:element name="xsl:template"> |
<!-- override some builtin rules: see http://www.w3.org/TR/xslt#built-in-rule --> |
71 |
<!-- <xsl:attribute name="match">*</xsl:attribute> --> |
<xsl:element name="xsl:template"><xsl:attribute name="match">comment()</xsl:attribute> |
72 |
<xsl:attribute name="match">*ab</xsl:attribute> |
<xsl:element name="xsl:call-template"> |
73 |
<xsl:element name="xsl:call-template"><xsl:attribute name="name">passthru</xsl:attribute></xsl:element> |
<xsl:attribute name="name">identity_template_rule</xsl:attribute> |
74 |
</xsl:element> |
</xsl:element> |
|
<xsl:element name="xsl:template"> |
|
|
<xsl:attribute name="match">comment()</xsl:attribute> |
|
|
<xsl:element name="xsl:call-template"><xsl:attribute name="name">passthru</xsl:attribute></xsl:element> |
|
75 |
</xsl:element> |
</xsl:element> |
76 |
|
|
77 |
<!-- continue with all inline nodes --> |
<!-- continue with all inline nodes --> |
85 |
|
|
86 |
<!-- code --> |
<!-- code --> |
87 |
<!-- This node "encapsulates" infrastructure for handling the directives. --> |
<!-- This node "encapsulates" infrastructure for handling the directives. --> |
88 |
<!-- FIXME: handle the other ones: append, remove, etc. --> |
|
89 |
|
<!-- Dispatch all "XUpdate Services" here. --> |
90 |
|
<!-- FIXME: Actually implement action = "CREATE|RETRIEVE|UPDATE|DELETE"!!! --> |
91 |
<xsl:template match="xupdate:insert-after"> |
<xsl:template match="xupdate:insert-after"> |
|
<xsl:comment> 2. context finder </xsl:comment> |
|
92 |
<!-- <xsl:variable name="select" select="@select">Hello World!</xsl:variable> --> |
<!-- <xsl:variable name="select" select="@select">Hello World!</xsl:variable> --> |
93 |
|
<xsl:call-template name="findcontext"> |
94 |
|
<xsl:with-param name="service">Insert</xsl:with-param> |
95 |
|
<xsl:with-param name="position">after</xsl:with-param> |
96 |
|
</xsl:call-template> |
97 |
|
</xsl:template> |
98 |
|
|
99 |
|
<xsl:template match="xupdate:insert-before"> |
100 |
|
<xsl:call-template name="findcontext"> |
101 |
|
<xsl:with-param name="service">Insert</xsl:with-param> |
102 |
|
<xsl:with-param name="position">before</xsl:with-param> |
103 |
|
</xsl:call-template> |
104 |
|
</xsl:template> |
105 |
|
|
106 |
|
<xsl:template match="xupdate:append"> |
107 |
|
<xsl:call-template name="findcontext"> |
108 |
|
<xsl:with-param name="service">Append</xsl:with-param> |
109 |
|
<!-- <xsl:with-param name="position">inline</xsl:with-param> --> |
110 |
|
<xsl:with-param name="test">.</xsl:with-param> |
111 |
|
</xsl:call-template> |
112 |
|
</xsl:template> |
113 |
|
|
114 |
|
<xsl:template match="xupdate:update"> |
115 |
|
<xsl:call-template name="findcontext"> |
116 |
|
<xsl:with-param name="service">Update</xsl:with-param> |
117 |
|
<!-- <xsl:with-param name="position">after</xsl:with-param> --> |
118 |
|
<xsl:with-param name="test">.</xsl:with-param> |
119 |
|
</xsl:call-template> |
120 |
|
</xsl:template> |
121 |
|
|
122 |
|
<xsl:template match="xupdate:remove"> |
123 |
|
<xsl:call-template name="findcontext"> |
124 |
|
<xsl:with-param name="service">Remove</xsl:with-param> |
125 |
|
<!-- <xsl:with-param name="position">after</xsl:with-param> --> |
126 |
|
<xsl:with-param name="test">.</xsl:with-param> |
127 |
|
</xsl:call-template> |
128 |
|
</xsl:template> |
129 |
|
|
130 |
|
<xsl:template match="xupdate:rename"> |
131 |
|
<xsl:call-template name="findcontext"> |
132 |
|
<xsl:with-param name="service">Rename</xsl:with-param> |
133 |
|
<!-- <xsl:with-param name="position">after</xsl:with-param> --> |
134 |
|
<xsl:with-param name="test">.</xsl:with-param> |
135 |
|
</xsl:call-template> |
136 |
|
</xsl:template> |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
<xsl:template name="findcontext"> |
141 |
|
|
142 |
|
<xsl:comment> 2. context finder </xsl:comment> |
143 |
|
|
144 |
|
<!-- new of 2003-05-06: introducing parameters here to handle all cases --> |
145 |
|
<xsl:param name="service" /> |
146 |
|
<xsl:param name="position" /> |
147 |
|
<!-- new of 2003-05-07: replacement for test if undef --> |
148 |
|
<xsl:param name="test" /> |
149 |
|
<xsl:param name="town" /> |
150 |
|
|
151 |
|
<xsl:variable name="town" select="huhu">haha</xsl:variable> |
152 |
|
|
153 |
|
<!-- |
154 |
|
<xsl:comment> |
155 |
|
service: <xsl:value-of select="$service" /> |
156 |
|
position: <xsl:value-of select="$position" /> |
157 |
|
test: <xsl:value-of select="$test" /> |
158 |
|
</xsl:comment> |
159 |
|
--> |
160 |
|
|
161 |
<!-- this resembles some parts of the CRUD API - retranslated to self-hosting xsl --> |
<!-- this resembles some parts of the CRUD API - retranslated to self-hosting xsl --> |
162 |
|
|
163 |
<!-- V1 --> |
<!-- V1 --> |
164 |
<!-- <xsl:element name="xsl:template"> --> |
<!-- <xsl:element name="xsl:template"> --> |
165 |
<!-- <xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute> --> |
<!-- <xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute> --> |
166 |
|
|
167 |
|
<!-- fallback --> |
168 |
|
<xsl:element name="xsl:template"> |
169 |
|
<xsl:attribute name="match">*</xsl:attribute> |
170 |
|
<xsl:element name="xsl:call-template"> |
171 |
|
<xsl:attribute name="name">identity_template_rule</xsl:attribute> |
172 |
|
<!-- <xsl:attribute name="name">passthru</xsl:attribute> --> |
173 |
|
</xsl:element> |
174 |
|
</xsl:element> |
175 |
|
|
176 |
<!-- V2 --> |
<!-- V2 --> |
177 |
<xsl:element name="xsl:template"> |
<xsl:element name="xsl:template"> |
|
<xsl:attribute name="match">*</xsl:attribute> |
|
178 |
<!-- <xsl:attribute name="match">/addresses/address</xsl:attribute> --> |
<!-- <xsl:attribute name="match">/addresses/address</xsl:attribute> --> |
179 |
<!-- <xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute> --> |
<!-- <xsl:attribute name="match">*</xsl:attribute> --> |
180 |
|
<xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute> |
181 |
|
|
182 |
<xsl:element name="xsl:choose"> |
<xsl:element name="xsl:choose"> |
183 |
<!-- <xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute> --> |
<!-- <xsl:attribute name="match"><xsl:value-of select="@select" /></xsl:attribute> --> |
184 |
<xsl:element name="xsl:when"> |
<xsl:element name="xsl:when"> |
185 |
<!-- <xsl:attribute name="test"><xsl:value-of select="@test" /></xsl:attribute> --> |
<!-- <xsl:attribute name="test"><xsl:value-of select="@select" /></xsl:attribute> --> |
186 |
<xsl:attribute name="test"><xsl:value-of select="@select" /></xsl:attribute> |
<xsl:attribute name="test"><xsl:value-of select="@test" /><xsl:value-of select="$test" /></xsl:attribute> |
187 |
|
|
188 |
<!-- FIXME: case "insert-before"!!! --> |
<xsl:choose> |
189 |
<!-- <xsl:apply-templates /> --> |
<xsl:when test="{$service}=Insert"> |
190 |
|
|
191 |
<!-- call the "identity template rule" to passthru all childnodes --> |
<xsl:comment> 2.a. Insert </xsl:comment> |
|
<xsl:element name="xsl:call-template"> |
|
|
<xsl:attribute name="name">identity_template_rule</xsl:attribute> |
|
|
<!-- <xsl:attribute name="name">passthru</xsl:attribute> --> |
|
|
</xsl:element> |
|
192 |
|
|
193 |
<!-- FIXME: case "insert-after"!!! --> |
<!-- Implementation of "xupdate:insert-before" --> |
194 |
<xsl:apply-templates /> |
<xsl:choose> |
195 |
|
<xsl:when test="{$position}=before"> |
196 |
|
<xsl:apply-templates /> |
197 |
|
</xsl:when> |
198 |
|
</xsl:choose> |
199 |
|
|
200 |
|
<!-- call the "identity template rule" to passthru all childnodes --> |
201 |
|
<xsl:element name="xsl:call-template"> |
202 |
|
<xsl:attribute name="name">identity_template_rule</xsl:attribute> |
203 |
|
<!-- <xsl:attribute name="name">passthru</xsl:attribute> --> |
204 |
|
</xsl:element> |
205 |
|
|
206 |
|
<!-- Implementation of "xupdate:insert-after" --> |
207 |
|
<xsl:choose> |
208 |
|
<xsl:when test="{$position}=after"> |
209 |
|
<xsl:apply-templates /> |
210 |
|
</xsl:when> |
211 |
|
</xsl:choose> |
212 |
|
|
213 |
|
</xsl:when> |
214 |
|
|
215 |
|
<!-- Implementation of "xupdate:append" --> |
216 |
|
<xsl:when test="{$service}=Append"> |
217 |
|
<xsl:comment> 2.b. Append </xsl:comment> |
218 |
|
<!-- V1 --> |
219 |
|
<!-- <xsl:apply-templates /> --> |
220 |
|
<!-- V2 --> |
221 |
|
<xsl:element name="xsl:copy"> |
222 |
|
<!-- |
223 |
|
<xsl:element name="xsl:copy-of"> |
224 |
|
<xsl:attribute name="select">@*</xsl:attribute> |
225 |
|
</xsl:element> |
226 |
|
--> |
227 |
|
<!-- Keep content ... --> |
228 |
|
<xsl:element name="xsl:apply-templates" /> |
229 |
|
<!-- Append this: --> |
230 |
|
<xsl:apply-templates /> |
231 |
|
</xsl:element> |
232 |
|
</xsl:when> |
233 |
|
|
234 |
|
<!-- Implementation of "xupdate:update" --> |
235 |
|
<xsl:when test="{$service}=Update"> |
236 |
|
<xsl:comment> 2.c. Update </xsl:comment> |
237 |
|
<!-- V1 --> |
238 |
|
<!-- <xsl:apply-templates /> --> |
239 |
|
<!-- V2 --> |
240 |
|
<xsl:element name="xsl:copy"> |
241 |
|
<!-- |
242 |
|
<xsl:element name="xsl:copy-of"> |
243 |
|
<xsl:attribute name="select">@*</xsl:attribute> |
244 |
|
</xsl:element> |
245 |
|
--> |
246 |
|
<!-- Keep content ... --> |
247 |
|
<!-- <xsl:element name="xsl:apply-templates" /> --> |
248 |
|
<!-- Add (replace through) this: --> |
249 |
|
<xsl:apply-templates /> |
250 |
|
</xsl:element> |
251 |
|
</xsl:when> |
252 |
|
|
253 |
|
<!-- Implementation of "xupdate:remove" --> |
254 |
|
<xsl:when test="{$service}=Remove"> |
255 |
|
<xsl:comment> 2.d. Remove </xsl:comment> |
256 |
|
</xsl:when> |
257 |
|
|
258 |
|
<!-- Implementation of "xupdate:rename" --> |
259 |
|
<xsl:when test="{$service}=Rename"> |
260 |
|
<xsl:comment> 2.e. Rename (Remove context and Append modified identity template) </xsl:comment> |
261 |
|
|
262 |
|
<xsl:comment> [5.a.] modify node name </xsl:comment> |
263 |
|
<xsl:element name="xsl:element"> |
264 |
|
<!-- this renames the node (change the "name"-attribute) --> |
265 |
|
<xsl:attribute name="name"> |
266 |
|
<xsl:apply-templates /> |
267 |
|
</xsl:attribute> |
268 |
|
<!-- this propagates the original content --> |
269 |
|
<xsl:element name="xsl:apply-templates" /> |
270 |
|
</xsl:element> |
271 |
|
|
272 |
|
</xsl:when> |
273 |
|
|
274 |
|
</xsl:choose> |
275 |
|
|
276 |
</xsl:element> |
</xsl:element> |
277 |
<xsl:element name="xsl:otherwise"> |
<xsl:element name="xsl:otherwise"> |
283 |
</xsl:element> |
</xsl:element> |
284 |
|
|
285 |
<!-- <xsl:apply-templates /> --> |
<!-- <xsl:apply-templates /> --> |
|
|
|
286 |
</xsl:element> |
</xsl:element> |
287 |
|
|
288 |
</xsl:element> |
</xsl:element> |
289 |
</xsl:element> |
</xsl:element> |
290 |
|
|
291 |
<!-- <xsl:apply-templates /> --> |
<!-- <xsl:apply-templates /> --> |
292 |
|
|
293 |
</xsl:template> |
</xsl:template> |
294 |
|
|
295 |
<!-- This node passes through all attributes and childnodes rewriting the tagname only. --> |
|
296 |
|
<!-- |
297 |
|
Rewrite XUpdate elements to XSLT elements. |
298 |
|
These templates pass through all attributes |
299 |
|
and childnodes rewriting the tagname only. |
300 |
|
FIXME: The redundant encoding for each XUpdate |
301 |
|
element type seems dummy. Could this be stripped |
302 |
|
shorter somehow sometimes? |
303 |
|
--> |
304 |
|
|
305 |
<xsl:template match="xupdate:element"> |
<xsl:template match="xupdate:element"> |
306 |
<xsl:comment> 3.a. vivify elements </xsl:comment> |
<xsl:comment> 3.a. vivify generic node </xsl:comment> |
307 |
<xsl:element name="xsl:element"> |
<xsl:element name="xsl:element"> |
308 |
<xsl:copy-of select="@*"/> |
<xsl:copy-of select="@*"/> |
309 |
<xsl:apply-templates /> |
<xsl:apply-templates /> |
310 |
</xsl:element> |
</xsl:element> |
311 |
</xsl:template> |
</xsl:template> |
312 |
|
|
|
<!-- This node passes through all attributes and childnodes rewriting the tagname only. --> |
|
313 |
<xsl:template match="xupdate:attribute"> |
<xsl:template match="xupdate:attribute"> |
314 |
<xsl:comment> 3.b. vivify attributes </xsl:comment> |
<xsl:comment> 3.b. vivify node attributes </xsl:comment> |
315 |
<xsl:element name="xsl:attribute"> |
<xsl:element name="xsl:attribute"> |
316 |
<xsl:copy-of select="@*"/> |
<xsl:copy-of select="@*"/> |
317 |
<xsl:apply-templates /> |
<xsl:apply-templates /> |
318 |
</xsl:element> |
</xsl:element> |
319 |
</xsl:template> |
</xsl:template> |
320 |
|
|
321 |
</xsl:stylesheet> |
<xsl:template match="xupdate:text"> |
322 |
|
<xsl:comment> 4.a. vivify text node </xsl:comment> |
323 |
|
<xsl:element name="xsl:text"> |
324 |
|
<xsl:copy-of select="@*"/> |
325 |
|
<xsl:apply-templates /> |
326 |
|
</xsl:element> |
327 |
|
</xsl:template> |
328 |
|
|
329 |
|
<xsl:template match="xupdate:processing-instruction"> |
330 |
|
<xsl:comment> 4.b. vivify PI node </xsl:comment> |
331 |
|
<xsl:element name="xsl:processing-instruction"> |
332 |
|
<xsl:copy-of select="@*"/> |
333 |
|
<xsl:apply-templates /> |
334 |
|
</xsl:element> |
335 |
|
</xsl:template> |
336 |
|
|
337 |
|
<xsl:template match="xupdate:comment"> |
338 |
|
<xsl:comment> 4.c. vivify comment node </xsl:comment> |
339 |
|
<xsl:element name="xsl:comment"> |
340 |
|
<xsl:copy-of select="@*"/> |
341 |
|
<xsl:apply-templates /> |
342 |
|
</xsl:element> |
343 |
|
</xsl:template> |
344 |
|
|
345 |
|
<!-- xsl for [2.9 Variables and Values of Variables] --> |
346 |
|
<xsl:template match="xupdate:variable"> |
347 |
|
<xsl:comment> 5.a. vivify xsl-element "variable" </xsl:comment> |
348 |
|
<xsl:element name="xsl:variable"> |
349 |
|
<xsl:copy-of select="@*"/> |
350 |
|
<!-- |
351 |
|
<xsl:apply-templates /> |
352 |
|
--> |
353 |
|
<!-- <xsl:element name="xsl:apply-templates" > --> |
354 |
|
<xsl:attribute name="select"> |
355 |
|
<!-- <xsl:apply-templates /> --> |
356 |
|
/addresses[2]/address[4]/town |
357 |
|
</xsl:attribute> |
358 |
|
<!-- </xsl:element> --> |
359 |
|
hui |
360 |
|
</xsl:element> |
361 |
|
|
362 |
|
</xsl:template> |
363 |
|
|
364 |
|
<xsl:template match="xupdate:value-of"> |
365 |
|
<xsl:comment> 5.b. vivify xsl-element "value-of" </xsl:comment> |
366 |
|
<xsl:element name="xsl:value-of"> |
367 |
|
<xsl:copy-of select="@*"/> |
368 |
|
<xsl:apply-templates /> |
369 |
|
</xsl:element> |
370 |
|
<xsl:text>abs</xsl:text> |
371 |
|
</xsl:template> |
372 |
|
|
373 |
|
|
374 |
|
</xsl:stylesheet> |
375 |
|
|