-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.xslt
109 lines (103 loc) · 5.08 KB
/
common.xslt
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
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<!--
<xsl:template name="capitalizeFirst">
<xsl:param name="value"/>
<xsl:value-of select="translate(substring($value,1,1),$alpha,$ALPHA)"/>
<xsl:value-of select="substring($value,2)"/>
</xsl:template>
-->
<xsl:template match="*">
<xsl:message terminate="yes">
Node not handled: <xsl:for-each select="ancestor-or-self::*">/<xsl:value-of select="name()"/></xsl:for-each>
<xsl:for-each select="*">
; <xsl:value-of select="concat(name(),'=',.)"/>
</xsl:for-each>
</xsl:message>
</xsl:template>
<xsl:param name="fixCase"/>
<xsl:variable name="optionFixCase" select="$fixCase='true'"/>
<xsl:template name="escapeKeyword">
<xsl:param name="value"/>
<xsl:value-of select="$value"/>
</xsl:template>
<xsl:template name="toCamelCase">
<xsl:param name="value"/>
<xsl:param name="delimiter" select="'_'"/>
<xsl:param name="keepDelimiter" select="false()"/>
<xsl:variable name="segment" select="substring-before($value, $delimiter)"/>
<xsl:choose>
<xsl:when test="$segment != ''">
<xsl:value-of select="$segment"/><xsl:if test="$keepDelimiter"><xsl:value-of select="$delimiter"/></xsl:if>
<xsl:call-template name="toPascalCase">
<xsl:with-param name="value" select="substring-after($value, $delimiter)"/>
<xsl:with-param name="delimiter" select="$delimiter"/>
<xsl:with-param name="keepDelimiter" select="$keepDelimiter"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:variable name="alpha" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="ALPHA" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:template name="toPascalCase">
<xsl:param name="value"/>
<xsl:param name="delimiter" select="'_'"/>
<xsl:param name="keepDelimiter" select="false()"/>
<xsl:if test="$value != ''">
<xsl:variable name="segment" select="substring-before($value, $delimiter)"/>
<xsl:choose>
<xsl:when test="$segment != ''">
<xsl:value-of select="translate(substring($segment,1,1),$alpha,$ALPHA)"/><xsl:value-of select="substring($segment,2)"/><xsl:if test="$keepDelimiter"><xsl:value-of select="$delimiter"/></xsl:if>
<xsl:call-template name="toPascalCase">
<xsl:with-param name="value" select="substring-after($value, $delimiter)"/>
<xsl:with-param name="delimiter" select="$delimiter"/>
<xsl:with-param name="keepDelimiter" select="$keepDelimiter"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(substring($value,1,1),$alpha,$ALPHA)"/><xsl:value-of select="substring($value,2)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template name="pascal">
<xsl:param name="value" select="name"/>
<xsl:param name="delimiter" select="'_'"/>
<xsl:call-template name="escapeKeyword">
<xsl:with-param name="value"><xsl:choose>
<xsl:when test="$optionFixCase"><xsl:variable name="dotted"><xsl:call-template name="toPascalCase">
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="delimiter" select="'.'"/>
<xsl:with-param name="keepDelimiter" select="true()"/>
</xsl:call-template></xsl:variable><xsl:call-template name="toPascalCase">
<xsl:with-param name="value" select="$dotted"/>
<xsl:with-param name="delimiter" select="$delimiter"/>
</xsl:call-template></xsl:when>
<xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise>
</xsl:choose></xsl:with-param></xsl:call-template>
</xsl:template>
<xsl:template name="PickNamespace"><xsl:param name="defaultNamespace"/><xsl:choose>
<xsl:when test="package"><xsl:call-template name="pascal">
<xsl:with-param name="value" select="package"/>
</xsl:call-template></xsl:when>
<xsl:when test="$defaultNamespace"><xsl:value-of select="$defaultNamespace"/></xsl:when>
<xsl:otherwise><xsl:variable name="trimmedName"><xsl:choose>
<xsl:when test="substring(name,string-length(name)-5,6)='.proto'"><xsl:value-of select="substring(name,1,string-length(name)-6)"/></xsl:when>
<xsl:otherwise><xsl:value-of select="name"/></xsl:otherwise>
</xsl:choose></xsl:variable><xsl:call-template name="pascal">
<xsl:with-param name="value" select="$trimmedName"/>
</xsl:call-template></xsl:otherwise>
</xsl:choose></xsl:template>
<xsl:template match="FieldDescriptorProto/options"/>
<xsl:template match="FileDescriptorProto/options"/>
<xsl:template match="DescriptorProto/options"/>
<xsl:template match="EnumValueDescriptorProto/options"/>
<xsl:template match="EnumDescriptorProto/options"/>
<xsl:template match="ServiceDescriptorProto/options"/>
<xsl:template match="MethodDescriptorProto/options"/>
</xsl:stylesheet>