vFLOWER lagt til
[virt-orchestrator.git] / vFLOWER / format.xsl
1 <xsl:stylesheet
2         version="1.0"
3         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4         xmlns:vco="http://vmware.com/vco/workflow"
5         xmlns:trax="http://xml.apache.org/xslt"
6 >
7
8         <xsl:output method="xml" version="1.0" indent="yes" trax:indent-amount="4"/>
9         <xsl:strip-space elements="*"/>
10
11         <xsl:template name="ltrim">
12                 <xsl:param name="text"/>
13                 <xsl:value-of select="substring($text, string-length(substring-before($text, substring(normalize-space($text), 1, 1))) + 1)"/>
14         </xsl:template>
15
16         <xsl:template name="getNumOfTrailingSpaces">
17                 <xsl:param name="text"/>
18                 <xsl:variable name="normalizedText">
19                         <xsl:value-of select="normalize-space($text)"/>
20                 </xsl:variable>
21                 <xsl:choose>
22                         <xsl:when test="string-length($normalizedText) > 0">
23                                 <xsl:call-template name="getNumOfTrailingSpaces">
24                                         <xsl:with-param name="text" select="substring-after(substring($text, string-length($normalizedText)), substring($normalizedText, string-length($normalizedText)))"/>
25                                 </xsl:call-template>
26                         </xsl:when>
27                         <xsl:otherwise>
28                                 <xsl:value-of select="string-length($text)"/>
29                         </xsl:otherwise>
30                 </xsl:choose>
31         </xsl:template>
32
33         <xsl:template name="rtrim">
34                 <xsl:param name="text"/>
35                 <xsl:variable name="numOfTrailingSpaces">
36                         <xsl:call-template name="getNumOfTrailingSpaces">
37                                 <xsl:with-param name="text">
38                                         <xsl:call-template name="ltrim">
39                                                 <xsl:with-param name="text" select="$text"/>
40                                         </xsl:call-template>
41                                 </xsl:with-param>
42                         </xsl:call-template>
43                 </xsl:variable>
44                 <xsl:value-of select="substring($text, 1, string-length($text) - $numOfTrailingSpaces)"/>
45         </xsl:template>
46
47         <xsl:template name="trim">
48                 <xsl:param name="text"/>
49                         <xsl:call-template name="rtrim">
50                                 <xsl:with-param name="text">
51                                         <xsl:call-template name="ltrim">
52                                                 <xsl:with-param name="text" select="$text"/>
53                                         </xsl:call-template>
54                                 </xsl:with-param>
55                         </xsl:call-template>
56         </xsl:template>
57
58         <xsl:template match="@*|node()">
59                 <xsl:copy>
60                         <xsl:apply-templates select="@*|node()"/>
61                 </xsl:copy>
62         </xsl:template>
63
64         <xsl:template match="text()">
65                 <xsl:variable name="trimmed">
66                         <xsl:call-template name="trim">
67                                 <xsl:with-param name="text" select="."/>
68                         </xsl:call-template>
69                 </xsl:variable>
70                 <xsl:if test="parent::vco:script or parent::script or contains(., '&#xa;')">
71                         <xsl:text>&#xa;</xsl:text>
72                 </xsl:if>
73                 <xsl:value-of select="$trimmed"/>
74                 <xsl:if test="parent::vco:script or parent::script or contains(., '&#xa;')">
75                         <xsl:text>&#xa;</xsl:text>
76                         <!-- generate indent for closing tag -->
77                         <!-- get ancestor nodes except root element (which has no parent) -->
78                         <xsl:for-each select="ancestor::*[parent::*]">
79                                 <xsl:text>    </xsl:text>
80                         </xsl:for-each>
81                 </xsl:if>
82         </xsl:template>
83
84         <xsl:template match="vco:workflow | dunes-script-module | package | config-element">
85                 <xsl:text>&#xa;</xsl:text>
86                 <xsl:copy>
87                         <xsl:apply-templates select="@*|node()"/>
88                 </xsl:copy>
89         </xsl:template>
90
91         <xsl:template match="vco:workflow[not(allowed-operations)]/@api-version">
92                 <xsl:copy>
93                         <xsl:attribute name="allowed-operations">vfe</xsl:attribute>
94                 </xsl:copy>
95         </xsl:template>
96
97         <xsl:template match="dunes-script-module[not(allowed-operations)]/@version">
98                 <xsl:copy>
99                         <xsl:attribute name="allowed-operations">vfe</xsl:attribute>
100                 </xsl:copy>
101         </xsl:template>
102
103         <xsl:template match="vco:input | vco:output | vco:attrib[position() = 1] | vco:workflow-item
104                         | vco:position | vco:description[local-name(parent::*) != 'attrib'] | vco:in-binding
105                         | vco:out-binding | vco:script | vco:presentation
106                         | script | param">
107                 <xsl:if test="preceding-sibling::*">
108                         <xsl:text>&#xa;&#xa;</xsl:text>
109                         <!-- generate indent for opening tag -->
110                         <xsl:for-each select="ancestor::*">
111                                 <xsl:text>    </xsl:text>
112                         </xsl:for-each>
113                 </xsl:if>
114                 <xsl:copy>
115                         <xsl:apply-templates select="@*|node()"/>
116                 </xsl:copy>
117         </xsl:template>
118
119 </xsl:stylesheet>