common.xslt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. <xsl:template name="escapeKeyword">
  23. <xsl:param name="value"/>
  24. <xsl:value-of select="$value"/>
  25. </xsl:template>
  26. <xsl:template name="toCamelCase">
  27. <xsl:param name="value"/>
  28. <xsl:param name="delimiter" select="'_'"/>
  29. <xsl:param name="keepDelimiter" select="false()"/>
  30. <xsl:variable name="segment" select="substring-before($value, $delimiter)"/>
  31. <xsl:choose>
  32. <xsl:when test="$segment != ''">
  33. <xsl:value-of select="$segment"/><xsl:if test="$keepDelimiter"><xsl:value-of select="$delimiter"/></xsl:if>
  34. <xsl:call-template name="toPascalCase">
  35. <xsl:with-param name="value" select="substring-after($value, $delimiter)"/>
  36. <xsl:with-param name="delimiter" select="$delimiter"/>
  37. <xsl:with-param name="keepDelimiter" select="$keepDelimiter"/>
  38. </xsl:call-template>
  39. </xsl:when>
  40. <xsl:otherwise>
  41. <xsl:value-of select="$value"/>
  42. </xsl:otherwise>
  43. </xsl:choose>
  44. </xsl:template>
  45. <xsl:variable name="alpha" select="'abcdefghijklmnopqrstuvwxyz'"/>
  46. <xsl:variable name="ALPHA" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
  47. <xsl:template name="toPascalCase">
  48. <xsl:param name="value"/>
  49. <xsl:param name="delimiter" select="'_'"/>
  50. <xsl:param name="keepDelimiter" select="false()"/>
  51. <xsl:if test="$value != ''">
  52. <xsl:variable name="segment" select="substring-before($value, $delimiter)"/>
  53. <xsl:choose>
  54. <xsl:when test="$segment != ''">
  55. <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>
  56. <xsl:call-template name="toPascalCase">
  57. <xsl:with-param name="value" select="substring-after($value, $delimiter)"/>
  58. <xsl:with-param name="delimiter" select="$delimiter"/>
  59. <xsl:with-param name="keepDelimiter" select="$keepDelimiter"/>
  60. </xsl:call-template>
  61. </xsl:when>
  62. <xsl:otherwise>
  63. <xsl:value-of select="translate(substring($value,1,1),$alpha,$ALPHA)"/><xsl:value-of select="substring($value,2)"/>
  64. </xsl:otherwise>
  65. </xsl:choose>
  66. </xsl:if>
  67. </xsl:template>
  68. <xsl:template name="pascal">
  69. <xsl:param name="value" select="name"/>
  70. <xsl:param name="delimiter" select="'_'"/>
  71. <xsl:call-template name="escapeKeyword">
  72. <xsl:with-param name="value"><xsl:choose>
  73. <xsl:when test="$optionFixCase"><xsl:variable name="dotted"><xsl:call-template name="toPascalCase">
  74. <xsl:with-param name="value" select="$value"/>
  75. <xsl:with-param name="delimiter" select="'.'"/>
  76. <xsl:with-param name="keepDelimiter" select="true()"/>
  77. </xsl:call-template></xsl:variable><xsl:call-template name="toPascalCase">
  78. <xsl:with-param name="value" select="$dotted"/>
  79. <xsl:with-param name="delimiter" select="$delimiter"/>
  80. </xsl:call-template></xsl:when>
  81. <xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise>
  82. </xsl:choose></xsl:with-param></xsl:call-template>
  83. </xsl:template>
  84. <xsl:template name="PickNamespace"><xsl:param name="defaultNamespace"/><xsl:choose>
  85. <xsl:when test="package"><xsl:call-template name="pascal">
  86. <xsl:with-param name="value" select="package"/>
  87. </xsl:call-template></xsl:when>
  88. <xsl:when test="$defaultNamespace"><xsl:value-of select="$defaultNamespace"/></xsl:when>
  89. <xsl:otherwise><xsl:variable name="trimmedName"><xsl:choose>
  90. <xsl:when test="substring(name,string-length(name)-5,6)='.proto'"><xsl:value-of select="substring(name,1,string-length(name)-6)"/></xsl:when>
  91. <xsl:otherwise><xsl:value-of select="name"/></xsl:otherwise>
  92. </xsl:choose></xsl:variable><xsl:call-template name="pascal">
  93. <xsl:with-param name="value" select="$trimmedName"/>
  94. </xsl:call-template></xsl:otherwise>
  95. </xsl:choose></xsl:template>
  96. <xsl:template match="FieldDescriptorProto/options"/>
  97. <xsl:template match="FileDescriptorProto/options"/>
  98. <xsl:template match="DescriptorProto/options"/>
  99. <xsl:template match="EnumValueDescriptorProto/options"/>
  100. <xsl:template match="EnumDescriptorProto/options"/>
  101. <xsl:template match="ServiceDescriptorProto/options"/>
  102. <xsl:template match="MethodDescriptorProto/options"/>
  103. </xsl:stylesheet>