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-2007 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 as published by the Free Software Foundation,
|
---|
15 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
16 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
17 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * If you received this file as part of a commercial VirtualBox
|
---|
20 | * distribution, then only the terms of your commercial VirtualBox
|
---|
21 | * license agreement apply instead of the previous paragraph.
|
---|
22 | -->
|
---|
23 |
|
---|
24 | <xsl:stylesheet version="1.0"
|
---|
25 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
---|
26 | xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
---|
27 | xmlns:vb="http://www.innotek.de/VirtualBox-settings"
|
---|
28 | xmlns="http://www.innotek.de/VirtualBox-settings"
|
---|
29 | exclude-result-prefixes="#default vb xsl xsd"
|
---|
30 | >
|
---|
31 |
|
---|
32 | <xsl:output method = "xml" indent = "yes"/>
|
---|
33 |
|
---|
34 | <xsl:variable name="recentVer" select="1.2"/>
|
---|
35 |
|
---|
36 | <xsl:variable name="curVer" select="substring-before(/VirtualBox/@version, '-')"/>
|
---|
37 | <xsl:variable name="curVerPlat" select="substring-after(/VirtualBox/@version, '-')"/>
|
---|
38 | <xsl:variable name="curVerFull" select="/VirtualBox/@version"/>
|
---|
39 |
|
---|
40 | <xsl:template match="/">
|
---|
41 | <xsl:text>
</xsl:text>
|
---|
42 | <xsl:comment> Automatically converted from version <xsl:value-of select="$curVerFull"/> to version <xsl:value-of select="$recentVer"/> </xsl:comment>
|
---|
43 | <xsl:text>
</xsl:text>
|
---|
44 | <xsl:copy>
|
---|
45 | <xsl:apply-templates select="@*|node()"/>
|
---|
46 | </xsl:copy>
|
---|
47 | </xsl:template>
|
---|
48 |
|
---|
49 | <!--
|
---|
50 | * comments outside the root node are gathered to a single line, fix this
|
---|
51 | -->
|
---|
52 | <xsl:template match="/comment()">
|
---|
53 | <xsl:copy-of select="."/>
|
---|
54 | <xsl:text>
</xsl:text>
|
---|
55 | </xsl:template>
|
---|
56 |
|
---|
57 | <!--
|
---|
58 | * Forbid non-VirtualBox root nodes
|
---|
59 | -->
|
---|
60 |
|
---|
61 | <xsl:template match="/*">
|
---|
62 | <xsl:message terminate="yes">
|
---|
63 | Cannot convert an unknown XML file with the root node '<xsl:value-of select="name()"/>'!
|
---|
64 | </xsl:message>
|
---|
65 | </xsl:template>
|
---|
66 |
|
---|
67 | <!--
|
---|
68 | * Forbid unsupported VirtualBox settings versions
|
---|
69 | -->
|
---|
70 |
|
---|
71 | <xsl:template match="/VirtualBox">
|
---|
72 | <xsl:if test="@version=concat($recentVer,'-',$curVerPlat)">
|
---|
73 | <xsl:message terminate="yes">
|
---|
74 | Cannot convert from version <xsl:value-of select="@version"/> to version <xsl:value-of select="$recentVer"/>!
|
---|
75 | The source is already at the most recent version.
|
---|
76 | </xsl:message>
|
---|
77 | </xsl:if>
|
---|
78 | <xsl:message terminate="yes">
|
---|
79 | Cannot convert from version <xsl:value-of select="@version"/> to version <xsl:value-of select="$recentVer"/>!
|
---|
80 | The source version is not supported.
|
---|
81 | </xsl:message>
|
---|
82 | </xsl:template>
|
---|
83 |
|
---|
84 | <!--
|
---|
85 | * Accept supported settings versions
|
---|
86 | -->
|
---|
87 | <xsl:template match="/VirtualBox[@version='1.1-windows' or
|
---|
88 | @version='1.1-linux']">
|
---|
89 | <xsl:copy>
|
---|
90 | <xsl:attribute name="version"><xsl:value-of select="concat($recentVer,'-',$curVerPlat)"/></xsl:attribute>
|
---|
91 | <xsl:apply-templates select="node()"/>
|
---|
92 | </xsl:copy>
|
---|
93 | </xsl:template>
|
---|
94 |
|
---|
95 | <!--
|
---|
96 | * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
---|
97 | * Individual convertions
|
---|
98 | * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
---|
99 | -->
|
---|
100 |
|
---|
101 | <!--
|
---|
102 | * all non-root elements that are not explicitly matched are copied as is
|
---|
103 | -->
|
---|
104 | <xsl:template match="@*|node()[../..]">
|
---|
105 | <xsl:copy>
|
---|
106 | <xsl:apply-templates select="@*|node()[../..]"/>
|
---|
107 | </xsl:copy>
|
---|
108 | </xsl:template>
|
---|
109 |
|
---|
110 | <!--
|
---|
111 | * Global settings
|
---|
112 | -->
|
---|
113 |
|
---|
114 | <xsl:template match="VirtualBox[substring-before(@version,'-')='1.1']/
|
---|
115 | Global/DiskImageRegistry/HardDiskImages//
|
---|
116 | Image">
|
---|
117 | <DiffHardDisk>
|
---|
118 | <xsl:attribute name="uuid"><xsl:value-of select="@uuid"/></xsl:attribute>
|
---|
119 | <VirtualDiskImage>
|
---|
120 | <xsl:attribute name="filePath"><xsl:value-of select="@src"/></xsl:attribute>
|
---|
121 | </VirtualDiskImage>
|
---|
122 | <xsl:apply-templates select="Image"/>
|
---|
123 | </DiffHardDisk>
|
---|
124 | </xsl:template>
|
---|
125 |
|
---|
126 | <xsl:template match="VirtualBox[substring-before(@version,'-')='1.1']/
|
---|
127 | Global/DiskImageRegistry">
|
---|
128 | <DiskRegistry>
|
---|
129 | <HardDisks>
|
---|
130 | <xsl:for-each select="HardDiskImages/Image">
|
---|
131 | <HardDisk>
|
---|
132 | <xsl:attribute name="uuid"><xsl:value-of select="@uuid"/></xsl:attribute>
|
---|
133 | <xsl:attribute name="type">
|
---|
134 | <xsl:choose>
|
---|
135 | <xsl:when test="@independent='immutable'">immutable</xsl:when>
|
---|
136 | <xsl:when test="@independent='mutable'">immutable</xsl:when>
|
---|
137 | <xsl:otherwise>normal</xsl:otherwise>
|
---|
138 | </xsl:choose>
|
---|
139 | </xsl:attribute>
|
---|
140 | <VirtualDiskImage>
|
---|
141 | <xsl:attribute name="filePath"><xsl:value-of select="@src"/></xsl:attribute>
|
---|
142 | </VirtualDiskImage>
|
---|
143 | <xsl:apply-templates select="Image"/>
|
---|
144 | </HardDisk>
|
---|
145 | </xsl:for-each>
|
---|
146 | </HardDisks>
|
---|
147 | <xsl:copy-of select="DVDImages"/>
|
---|
148 | <xsl:copy-of select="FloppyImages"/>
|
---|
149 | </DiskRegistry>
|
---|
150 | </xsl:template>
|
---|
151 |
|
---|
152 | <!--
|
---|
153 | * Machine settings
|
---|
154 | -->
|
---|
155 |
|
---|
156 | <xsl:template match="VirtualBox[substring-before(@version,'-')='1.1']/
|
---|
157 | Machine//HardDisks">
|
---|
158 | <HardDiskAttachments>
|
---|
159 | <xsl:for-each select="HardDisk">
|
---|
160 | <HardDiskAttachment>
|
---|
161 | <xsl:attribute name="hardDisk"><xsl:value-of select="Image/@uuid"/></xsl:attribute>
|
---|
162 | <xsl:apply-templates select="@*"/>
|
---|
163 | </HardDiskAttachment>
|
---|
164 | </xsl:for-each>
|
---|
165 | </HardDiskAttachments>
|
---|
166 | </xsl:template>
|
---|
167 |
|
---|
168 | </xsl:stylesheet>
|
---|