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

</xsl:text>
<!-- generate indent for opening tag -->
<xsl:for-each select="ancestor::*">
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:if>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>