VirtualBox

source: vbox/trunk/src/VBox/Main/xml/SettingsConverter.xsl@ 7466

Last change on this file since 7466 was 7466, checked in by vboxsync, 17 years ago

Main/Settings: Applied all current XML settings format todos and increased version from 1.3.pre to 1.3.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.8 KB
Line 
1<?xml version="1.0"?>
2
3<!--
4 * :tabSize=2:indentSize=2:noTabs=true:
5 * :folding=explicit:collapseFolds=1:
6 *
7 * Template to convert old VirtualBox settings files to the most recent format.
8
9 Copyright (C) 2006-2008 innotek GmbH
10
11 This file is part of VirtualBox Open Source Edition (OSE), as
12 available from http://www.virtualbox.org. This file is free software;
13 you can redistribute it and/or modify it under the terms of the GNU
14 General Public License (GPL) as published by the Free Software
15 Foundation, in version 2 as it comes in the "COPYING" file of the
16 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18-->
19
20<xsl:stylesheet version="1.0"
21 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
23 xmlns:vb="http://www.innotek.de/VirtualBox-settings"
24 xmlns="http://www.innotek.de/VirtualBox-settings"
25 exclude-result-prefixes="#default vb xsl xsd"
26>
27
28<xsl:output method = "xml" indent = "yes"/>
29
30<xsl:variable name="curVer" select="substring-before(/vb:VirtualBox/@version, '-')"/>
31<xsl:variable name="curVerPlat" select="substring-after(/vb:VirtualBox/@version, '-')"/>
32<xsl:variable name="curVerFull" select="/vb:VirtualBox/@version"/>
33
34<xsl:template match="/">
35 <xsl:comment> Automatically converted from version '<xsl:value-of select="$curVerFull"/>' </xsl:comment>
36 <xsl:copy>
37 <xsl:apply-templates select="@*|node()"/>
38 </xsl:copy>
39</xsl:template>
40
41<!--
42 * comments outside the root node are gathered to a single line, fix this
43-->
44<xsl:template match="/comment()">
45 <xsl:copy-of select="."/>
46</xsl:template>
47
48<!--
49 * Forbid non-VirtualBox root nodes
50-->
51<xsl:template match="/*">
52 <xsl:message terminate="yes">
53Cannot convert an unknown XML file with the root node '<xsl:value-of select="name()"/>'!
54 </xsl:message>
55</xsl:template>
56
57<!--
58 * Forbid all unsupported VirtualBox settings versions
59-->
60<xsl:template match="/vb:VirtualBox">
61 <xsl:message terminate="yes">
62Cannot convert settings from version '<xsl:value-of select="@version"/>'.
63The source version is not supported.
64 </xsl:message>
65</xsl:template>
66
67<!--
68 * Accept supported settings versions (source setting files we can convert)
69 *
70 * Note that in order to simplify conversion from versions prior to the previous
71 * one, we support multi-step conversion like this: step 1: 1.0 => 1.1,
72 * step 2: 1.1 => 1.2, where 1.2 is the most recent version. If you want to use
73 * such multi-step mode, you need to ensure that only 1.0 => 1.1 is possible, by
74 * using the 'mode=1.1' attribute on both 'apply-templates' within the starting
75 * '/vb:VirtualBox[1.0]' template and within all templates that this
76 * 'apply-templates' should apply.
77 *
78 * If no 'mode' attribute is used as described above, then a direct conversion
79 * (1.0 => 1.2 in the above example) will happen when version 1.0 of the settings
80 * files is detected. Note that the direct conversion from pre-previous versions
81 * will require to patch their conversion templates so that they include all
82 * modifications from all newer versions, which is error-prone. It's better to
83 * use the milt-step mode.
84-->
85
86<!-- 1.1 => 1.2 -->
87<xsl:template match="/vb:VirtualBox[substring-before(@version,'-')='1.1']">
88 <xsl:copy>
89 <xsl:attribute name="version"><xsl:value-of select="concat('1.2','-',$curVerPlat)"/></xsl:attribute>
90 <xsl:apply-templates select="node()" mode="v1.2"/>
91 </xsl:copy>
92</xsl:template>
93
94<!-- 1.2 => 1.3.pre -->
95<xsl:template match="/vb:VirtualBox[substring-before(@version,'-')='1.2']">
96 <xsl:copy>
97 <xsl:attribute name="version"><xsl:value-of select="concat('1.3.pre','-',$curVerPlat)"/></xsl:attribute>
98 <xsl:apply-templates select="node()" mode="v1.3.pre"/>
99 </xsl:copy>
100</xsl:template>
101
102<!-- 1.3.pre => 1.3 -->
103<xsl:template match="/vb:VirtualBox[substring-before(@version,'-')='1.3.pre']">
104 <xsl:copy>
105 <xsl:attribute name="version"><xsl:value-of select="concat('1.3','-',$curVerPlat)"/></xsl:attribute>
106 <xsl:apply-templates select="node()" mode="v1.3"/>
107 </xsl:copy>
108</xsl:template>
109
110<!--
111 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
112 * 1.1 => 1.2
113 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114-->
115
116<!--
117 * all non-root elements that are not explicitly matched are copied as is
118-->
119<xsl:template match="@*|node()[../..]" mode="v1.2">
120 <xsl:copy>
121 <xsl:apply-templates select="@*|node()[../..]" mode="v1.2"/>
122 </xsl:copy>
123</xsl:template>
124
125<!--
126 * Global settings
127-->
128
129<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.1']/
130 vb:Global/vb:DiskImageRegistry/vb:HardDiskImages//
131 vb:Image"
132 mode="v1.2">
133 <DiffHardDisk>
134 <xsl:attribute name="uuid"><xsl:value-of select="@uuid"/></xsl:attribute>
135 <VirtualDiskImage>
136 <xsl:attribute name="filePath"><xsl:value-of select="@src"/></xsl:attribute>
137 </VirtualDiskImage>
138 <xsl:apply-templates select="vb:Image"/>
139 </DiffHardDisk>
140</xsl:template>
141
142<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.1']/
143 vb:Global/vb:DiskImageRegistry"
144 mode="v1.2">
145<DiskRegistry>
146 <HardDisks>
147 <xsl:for-each select="vb:HardDiskImages/vb:Image">
148 <HardDisk>
149 <xsl:attribute name="uuid"><xsl:value-of select="@uuid"/></xsl:attribute>
150 <xsl:attribute name="type">
151 <xsl:choose>
152 <xsl:when test="@independent='immutable'">immutable</xsl:when>
153 <xsl:when test="@independent='mutable'">immutable</xsl:when>
154 <xsl:otherwise>normal</xsl:otherwise>
155 </xsl:choose>
156 </xsl:attribute>
157 <VirtualDiskImage>
158 <xsl:attribute name="filePath"><xsl:value-of select="@src"/></xsl:attribute>
159 </VirtualDiskImage>
160 <xsl:apply-templates select="vb:Image"/>
161 </HardDisk>
162 </xsl:for-each>
163 </HardDisks>
164 <xsl:copy-of select="vb:DVDImages"/>
165 <xsl:copy-of select="vb:FloppyImages"/>
166</DiskRegistry>
167</xsl:template>
168
169<!--
170 * Machine settings
171-->
172
173<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.1']/
174 vb:Machine//vb:HardDisks"
175 mode="v1.2">
176 <HardDiskAttachments>
177 <xsl:for-each select="vb:HardDisk">
178 <HardDiskAttachment>
179 <xsl:attribute name="hardDisk"><xsl:value-of select="vb:Image/@uuid"/></xsl:attribute>
180 <xsl:apply-templates select="@*"/>
181 </HardDiskAttachment>
182 </xsl:for-each>
183 </HardDiskAttachments>
184</xsl:template>
185
186<!--
187 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
188 * 1.2 => 1.3.pre
189 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
190-->
191
192<!--
193 * all non-root elements that are not explicitly matched are copied as is
194-->
195<xsl:template match="@*|node()[../..]" mode="v1.3.pre">
196 <xsl:copy>
197 <xsl:apply-templates select="@*|node()[../..]" mode="v1.3.pre"/>
198 </xsl:copy>
199</xsl:template>
200
201<!--
202 * Global settings
203-->
204
205<!--
206 * Machine settings
207-->
208
209<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.2']/
210 vb:Machine//vb:USBController"
211 mode="v1.3.pre">
212 <xsl:copy>
213 <xsl:apply-templates select="@*|node()" mode="v1.3.pre"/>
214 </xsl:copy>
215 <SATAController enabled="false"/>
216</xsl:template>
217
218<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.2']/
219 vb:Machine//vb:HardDiskAttachments/vb:HardDiskAttachment"
220 mode="v1.3.pre">
221 <HardDiskAttachment>
222 <xsl:attribute name="hardDisk"><xsl:value-of select="@hardDisk"/></xsl:attribute>
223 <xsl:attribute name="bus">
224 <xsl:choose>
225 <xsl:when test="@bus='ide0'">
226 <xsl:text>IDE</xsl:text>
227 </xsl:when>
228 <xsl:when test="@bus='ide1'">
229 <xsl:text>IDE</xsl:text>
230 </xsl:when>
231 <xsl:otherwise>
232 <xsl:message terminate="yes">
233Value '<xsl:value-of select="@bus"/>' of 'HardDiskAttachment::bus' attribute is invalid.
234 </xsl:message>
235 </xsl:otherwise>
236 </xsl:choose>
237 </xsl:attribute>
238 <xsl:attribute name="channel">0</xsl:attribute>
239 <xsl:attribute name="device">
240 <xsl:choose>
241 <xsl:when test="@device='master'">
242 <xsl:text>0</xsl:text>
243 </xsl:when>
244 <xsl:when test="@device='slave'">
245 <xsl:text>1</xsl:text>
246 </xsl:when>
247 <xsl:otherwise>
248 <xsl:message terminate="yes">
249Value '<xsl:value-of select="@device"/>' of 'HardDiskAttachment::device' attribute is invalid.
250 </xsl:message>
251 </xsl:otherwise>
252 </xsl:choose>
253 </xsl:attribute>
254 </HardDiskAttachment>
255</xsl:template>
256
257<!--
258 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
259 * 1.3.pre => 1.3
260 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
261-->
262
263<!--
264 * all non-root elements that are not explicitly matched are copied as is
265-->
266<xsl:template match="@*|node()[../..]" mode="v1.3">
267 <xsl:copy>
268 <xsl:apply-templates select="@*|node()[../..]" mode="v1.3"/>
269 </xsl:copy>
270</xsl:template>
271
272<!--
273 * Global settings
274-->
275
276<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.3.pre']/
277 vb:Global//vb:SystemProperties"
278 mode="v1.3">
279 <xsl:copy>
280 <xsl:apply-templates select="@*[not(name()='defaultSavedStateFolder')]|node()" mode="v1.3"/>
281 </xsl:copy>
282</xsl:template>
283
284<!--
285 * Machine settings
286-->
287
288<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.3.pre']/
289 vb:Machine//vb:AudioAdapter"
290 mode="v1.3">
291 <xsl:copy>
292 <xsl:apply-templates select="@*[not(name()='driver')]|node()" mode="v1.3"/>
293 <xsl:attribute name="driver">
294 <xsl:choose>
295 <xsl:when test="@driver='null'">Null</xsl:when>
296 <xsl:when test="@driver='oss'">OSS</xsl:when>
297 <xsl:when test="@driver='alsa'">ALSA</xsl:when>
298 <xsl:when test="@driver='pulse'">Pulse</xsl:when>
299 <xsl:when test="@driver='codeaudio'">CoreAudio</xsl:when>
300 <xsl:when test="@driver='winmm'">WinMM</xsl:when>
301 <xsl:when test="@driver='dsound'">DirectSound</xsl:when>
302 <xsl:when test="@driver='esd'">ESD</xsl:when>
303 <xsl:when test="@driver='mmpm'">MMPM</xsl:when>
304 <xsl:otherwise>
305 <xsl:message terminate="yes">
306Value '<xsl:value-of select="@driver"/>' of 'AudioAdapter::driver' attribute is invalid.
307 </xsl:message>
308 </xsl:otherwise>
309 </xsl:choose>
310 </xsl:attribute>
311 </xsl:copy>
312 <xsl:if test="not(../vb:SharedFolders)">
313 <SharedFolders/>
314 </xsl:if>
315 <xsl:if test="not(../vb:Clipboard)">
316 <Clipboard mode="Disabled"/>
317 </xsl:if>
318 <xsl:if test="not(../vb:Guest)">
319 <Guest/>
320 </xsl:if>
321</xsl:template>
322
323<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.3.pre']/
324 vb:Machine//vb:RemoteDisplay"
325 mode="v1.3">
326 <xsl:copy>
327 <xsl:apply-templates select="@*[not(name()='authType')]|node()" mode="v1.3"/>
328 <xsl:attribute name="authType">
329 <xsl:choose>
330 <xsl:when test="@authType='null'">Null</xsl:when>
331 <xsl:when test="@authType='guest'">Guest</xsl:when>
332 <xsl:when test="@authType='external'">External</xsl:when>
333 <xsl:otherwise>
334 <xsl:message terminate="yes">
335Value '<xsl:value-of select="@authType"/>' of 'RemoteDisplay::authType' attribute is invalid.
336 </xsl:message>
337 </xsl:otherwise>
338 </xsl:choose>
339 </xsl:attribute>
340 </xsl:copy>
341</xsl:template>
342
343<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.3.pre']/
344 vb:Machine//vb:BIOS/vb:BootMenu"
345 mode="v1.3">
346 <xsl:copy>
347 <xsl:apply-templates select="@*[not(name()='mode')]|node()" mode="v1.3"/>
348 <xsl:attribute name="mode">
349 <xsl:choose>
350 <xsl:when test="@mode='disabled'">Disabled</xsl:when>
351 <xsl:when test="@mode='menuonly'">MenuOnly</xsl:when>
352 <xsl:when test="@mode='messageandmenu'">MessageAndMenu</xsl:when>
353 <xsl:otherwise>
354 <xsl:message terminate="yes">
355Value '<xsl:value-of select="@mode"/>' of 'BootMenu::mode' attribute is invalid.
356 </xsl:message>
357 </xsl:otherwise>
358 </xsl:choose>
359 </xsl:attribute>
360 </xsl:copy>
361</xsl:template>
362
363<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.3.pre']/
364 vb:Machine//vb:USBController/vb:DeviceFilter |
365 vb:VirtualBox[substring-before(@version,'-')='1.3.pre']/
366 vb:Global/vb:USBDeviceFilters/vb:DeviceFilter"
367 mode="v1.3">
368 <xsl:copy>
369 <xsl:apply-templates select="node()" mode="v1.3"/>
370 <xsl:for-each select="@*">
371 <xsl:choose>
372 <xsl:when test="name()='vendorid'">
373 <xsl:attribute name="vendorId"><xsl:value-of select="."/></xsl:attribute>
374 </xsl:when>
375 <xsl:when test="name()='productid'">
376 <xsl:attribute name="productId"><xsl:value-of select="."/></xsl:attribute>
377 </xsl:when>
378 <xsl:when test="name()='serialnumber'">
379 <xsl:attribute name="serialNumber"><xsl:value-of select="."/></xsl:attribute>
380 </xsl:when>
381 <xsl:otherwise>
382 <xsl:apply-templates select="." mode="v1.3"/>
383 </xsl:otherwise>
384 </xsl:choose>
385 </xsl:for-each>
386 </xsl:copy>
387</xsl:template>
388
389<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.3.pre']/
390 vb:Machine//vb:Guest"
391 mode="v1.3">
392 <xsl:copy>
393 <xsl:apply-templates select="node()" mode="v1.3"/>
394 <xsl:for-each select="@*">
395 <xsl:choose>
396 <xsl:when test="name()='MemoryBalloonSize'">
397 <xsl:attribute name="memoryBalloonSize"><xsl:value-of select="."/></xsl:attribute>
398 </xsl:when>
399 <xsl:when test="name()='StatisticsUpdateInterval'">
400 <xsl:attribute name="statisticsUpdateInterval"><xsl:value-of select="."/></xsl:attribute>
401 </xsl:when>
402 <xsl:otherwise>
403 <xsl:apply-templates select="node()" mode="v1.3"/>
404 </xsl:otherwise>
405 </xsl:choose>
406 </xsl:for-each>
407 </xsl:copy>
408</xsl:template>
409
410<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.3.pre']/
411 vb:Machine//vb:Uart"
412 mode="v1.3">
413 <UART>
414 <xsl:apply-templates select="@*|node()" mode="v1.3"/>
415 </UART>
416</xsl:template>
417
418<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.3.pre']/
419 vb:Machine//vb:Lpt"
420 mode="v1.3">
421 <LPT>
422 <xsl:apply-templates select="@*|node()" mode="v1.3"/>
423 </LPT>
424</xsl:template>
425
426<xsl:template match="vb:VirtualBox[substring-before(@version,'-')='1.3.pre']/
427 vb:Machine"
428 mode="v1.3">
429 <xsl:copy>
430 <xsl:apply-templates select="@*|node()" mode="v1.3"/>
431 <xsl:if test="not(@lastStateChange)">
432 <xsl:attribute name="lastStateChange"></xsl:attribute>
433 </xsl:if>
434 </xsl:copy>
435</xsl:template>
436
437</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette