|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 3 | + xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" |
| 4 | +> |
| 5 | + <!-- |
| 6 | + <xsl:template name="capitalizeFirst"> |
| 7 | + <xsl:param name="value"/> |
| 8 | + <xsl:value-of select="translate(substring($value,1,1),$alpha,$ALPHA)"/> |
| 9 | + <xsl:value-of select="substring($value,2)"/> |
| 10 | + </xsl:template> |
| 11 | + --> |
| 12 | + <xsl:template match="*"> |
| 13 | + <xsl:message terminate="yes"> |
| 14 | + Node not handled: <xsl:for-each select="ancestor-or-self::*">/<xsl:value-of select="name()"/></xsl:for-each> |
| 15 | + <xsl:for-each select="*"> |
| 16 | + ; <xsl:value-of select="concat(name(),'=',.)"/> |
| 17 | + </xsl:for-each> |
| 18 | + </xsl:message> |
| 19 | + </xsl:template> |
| 20 | + <xsl:param name="fixCase"/> |
| 21 | + <xsl:variable name="optionFixCase" select="$fixCase='true'"/> |
| 22 | + |
| 23 | + <xsl:template name="escapeKeyword"> |
| 24 | + <xsl:param name="value"/> |
| 25 | + <xsl:value-of select="$value"/> |
| 26 | + </xsl:template> |
| 27 | + |
| 28 | + <xsl:template name="toCamelCase"> |
| 29 | + <xsl:param name="value"/> |
| 30 | + <xsl:param name="delimiter" select="'_'"/> |
| 31 | + <xsl:param name="keepDelimiter" select="false()"/> |
| 32 | + <xsl:variable name="segment" select="substring-before($value, $delimiter)"/> |
| 33 | + <xsl:choose> |
| 34 | + <xsl:when test="$segment != ''"> |
| 35 | + <xsl:value-of select="$segment"/><xsl:if test="$keepDelimiter"><xsl:value-of select="$delimiter"/></xsl:if> |
| 36 | + <xsl:call-template name="toPascalCase"> |
| 37 | + <xsl:with-param name="value" select="substring-after($value, $delimiter)"/> |
| 38 | + <xsl:with-param name="delimiter" select="$delimiter"/> |
| 39 | + <xsl:with-param name="keepDelimiter" select="$keepDelimiter"/> |
| 40 | + </xsl:call-template> |
| 41 | + </xsl:when> |
| 42 | + <xsl:otherwise> |
| 43 | + <xsl:value-of select="$value"/> |
| 44 | + </xsl:otherwise> |
| 45 | + </xsl:choose> |
| 46 | + </xsl:template> |
| 47 | + |
| 48 | + <xsl:variable name="alpha" select="'abcdefghijklmnopqrstuvwxyz'"/> |
| 49 | + <xsl:variable name="ALPHA" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/> |
| 50 | + |
| 51 | + <xsl:template name="toPascalCase"> |
| 52 | + <xsl:param name="value"/> |
| 53 | + <xsl:param name="delimiter" select="'_'"/> |
| 54 | + <xsl:param name="keepDelimiter" select="false()"/> |
| 55 | + <xsl:if test="$value != ''"> |
| 56 | + <xsl:variable name="segment" select="substring-before($value, $delimiter)"/> |
| 57 | + <xsl:choose> |
| 58 | + <xsl:when test="$segment != ''"> |
| 59 | + <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> |
| 60 | + <xsl:call-template name="toPascalCase"> |
| 61 | + <xsl:with-param name="value" select="substring-after($value, $delimiter)"/> |
| 62 | + <xsl:with-param name="delimiter" select="$delimiter"/> |
| 63 | + <xsl:with-param name="keepDelimiter" select="$keepDelimiter"/> |
| 64 | + </xsl:call-template> |
| 65 | + </xsl:when> |
| 66 | + <xsl:otherwise> |
| 67 | + <xsl:value-of select="translate(substring($value,1,1),$alpha,$ALPHA)"/><xsl:value-of select="substring($value,2)"/> |
| 68 | + </xsl:otherwise> |
| 69 | + </xsl:choose> |
| 70 | + </xsl:if> |
| 71 | + </xsl:template> |
| 72 | + <xsl:template name="pascal"> |
| 73 | + <xsl:param name="value" select="name"/> |
| 74 | + <xsl:param name="delimiter" select="'_'"/> |
| 75 | + <xsl:call-template name="escapeKeyword"> |
| 76 | + <xsl:with-param name="value"><xsl:choose> |
| 77 | + <xsl:when test="$optionFixCase"><xsl:variable name="dotted"><xsl:call-template name="toPascalCase"> |
| 78 | + <xsl:with-param name="value" select="$value"/> |
| 79 | + <xsl:with-param name="delimiter" select="'.'"/> |
| 80 | + <xsl:with-param name="keepDelimiter" select="true()"/> |
| 81 | + </xsl:call-template></xsl:variable><xsl:call-template name="toPascalCase"> |
| 82 | + <xsl:with-param name="value" select="$dotted"/> |
| 83 | + <xsl:with-param name="delimiter" select="$delimiter"/> |
| 84 | + </xsl:call-template></xsl:when> |
| 85 | + <xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise> |
| 86 | + </xsl:choose></xsl:with-param></xsl:call-template> |
| 87 | + </xsl:template> |
| 88 | + |
| 89 | + <xsl:template name="PickNamespace"><xsl:param name="defaultNamespace"/><xsl:choose> |
| 90 | + <xsl:when test="package"><xsl:call-template name="pascal"> |
| 91 | + <xsl:with-param name="value" select="package"/> |
| 92 | + </xsl:call-template></xsl:when> |
| 93 | + <xsl:when test="$defaultNamespace"><xsl:value-of select="$defaultNamespace"/></xsl:when> |
| 94 | + <xsl:otherwise><xsl:variable name="trimmedName"><xsl:choose> |
| 95 | + <xsl:when test="substring(name,string-length(name)-5,6)='.proto'"><xsl:value-of select="substring(name,1,string-length(name)-6)"/></xsl:when> |
| 96 | + <xsl:otherwise><xsl:value-of select="name"/></xsl:otherwise> |
| 97 | + </xsl:choose></xsl:variable><xsl:call-template name="pascal"> |
| 98 | + <xsl:with-param name="value" select="$trimmedName"/> |
| 99 | + </xsl:call-template></xsl:otherwise> |
| 100 | + </xsl:choose></xsl:template> |
| 101 | + |
| 102 | + <xsl:template match="FieldDescriptorProto/options"/> |
| 103 | + <xsl:template match="FileDescriptorProto/options"/> |
| 104 | + <xsl:template match="DescriptorProto/options"/> |
| 105 | + <xsl:template match="EnumValueDescriptorProto/options"/> |
| 106 | + <xsl:template match="EnumDescriptorProto/options"/> |
| 107 | + <xsl:template match="ServiceDescriptorProto/options"/> |
| 108 | + <xsl:template match="MethodDescriptorProto/options"/> |
| 109 | +</xsl:stylesheet> |
0 commit comments