properties-file.xsl 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4. xmlns:fn="http://example.com/namespace"
  5. exclude-result-prefixes="xs fn"
  6. version="2.0">
  7. <xsl:output method="text"/>
  8. <xsl:strip-space elements="*"/>
  9. <xsl:variable name="wrapCol" select="80"/>
  10. <xsl:variable name="indentSize" select="20"/>
  11. <xsl:variable name="crlf" select="codepoints-to-string((13,10))"/>
  12. <xsl:variable name="comment" select="concat($crlf,'# ')"/>
  13. <xsl:variable name="divBar" select="concat('# ',fn:padIt('=',$wrapCol - 4),' #')"/>
  14. <xsl:variable name="sctn-start" select="concat($crlf,$crlf,'##### ')"/>
  15. <xsl:variable name="sctn-end" select="concat(' PROPERTIES #####',$crlf)"/>
  16. <xsl:variable name="indentSpaces" select="fn:padIt(' ',$indentSize)"/>
  17. <xsl:function name="fn:padIt" as="xs:string">
  18. <xsl:param name="string" as="xs:string"/>
  19. <xsl:param name="len" as="xs:integer"/>
  20. <xsl:variable name="seq">
  21. <xsl:for-each select="1 to $len">
  22. <xsl:value-of select="$string"/>
  23. </xsl:for-each>
  24. </xsl:variable>
  25. <xsl:value-of select="string-join($seq,'')"/>
  26. </xsl:function>
  27. <xsl:function name="fn:breakAfter">
  28. <xsl:param name="string" as="xs:string"/>
  29. <xsl:param name="breakpoint" as="xs:integer"/>
  30. <xsl:variable name="matchExpr" select="concat('^.{1,',$breakpoint,'}(\s|$)')"/>
  31. <xsl:variable name="rest" select="replace($string,$matchExpr,'')"/>
  32. <xsl:variable name="start" select="substring-before($string,$rest)"/>
  33. <xsl:choose>
  34. <xsl:when test="$start=''">
  35. <start><xsl:value-of select="$string"/></start>
  36. <rest></rest>
  37. </xsl:when>
  38. <xsl:otherwise>
  39. <start><xsl:value-of select="$start"/></start>
  40. <rest><xsl:value-of select="$rest"/></rest>
  41. </xsl:otherwise>
  42. </xsl:choose>
  43. </xsl:function>
  44. <xsl:function name="fn:wrapAndIndent" as="xs:string">
  45. <xsl:param name="name" as="xs:string"/>
  46. <xsl:param name="description" as="xs:string"/>
  47. <xsl:variable name="step1"
  48. select="fn:breakAfter(concat(normalize-space($name),$indentSpaces,normalize-space($description)),$indentSize - 1)"/>
  49. <xsl:variable name="step2"
  50. select="fn:breakAfter(concat($step1[1],normalize-space($step1[2])),$wrapCol)"/>
  51. <xsl:choose>
  52. <xsl:when test="string-length($step2[2]) gt 0">
  53. <xsl:value-of select="concat($comment,$step2[1],fn:wrapAndIndent('',$step2[2]))"/>
  54. </xsl:when>
  55. <xsl:otherwise>
  56. <xsl:value-of select="concat($comment,$step2[1])"/>
  57. </xsl:otherwise>
  58. </xsl:choose>
  59. </xsl:function>
  60. <xsl:template match="/">
  61. <xsl:call-template name="all"/>
  62. </xsl:template>
  63. <xsl:template name="all">
  64. <xsl:text>
  65. # ============================================================================ #
  66. #
  67. # GENERATED PROPERTIES FILE FOR USE WITH THE DITA COMMAND
  68. #
  69. # Lines in this file that start with a # are comments.
  70. #
  71. # To set a build parameter, remove the commenting # at the start of the line
  72. # and specify the value for the parameter after the = sign, for example,
  73. #
  74. # args.filter = my-filter.ditaval
  75. #
  76. # Use the dita command with the -propertyfile option to use the build parameters
  77. # specified in a properties file, for example:
  78. #
  79. # dita -i my.ditamap -f html5 -propertyfile my.properties
  80. #
  81. # Build parameters in this file are grouped by transformation type.
  82. # Supported parameter values are listed in brackets [] after each description,
  83. # with an asterisk (*) indicating the default value where appropriate.
  84. #
  85. # ============================================================================ #
  86. </xsl:text>
  87. <xsl:for-each-group select="//transtype[param]" group-by="@desc">
  88. <xsl:sort select="@desc"/>
  89. <xsl:variable name="padsize" select="(ceiling( (($wrapCol - string-length(@desc)) div 2 ) ) - 2) cast as xs:integer"/>
  90. <xsl:variable name="descpad" select="fn:padIt(' ',$padsize)"/>
  91. <xsl:value-of
  92. select="upper-case(concat($crlf,$crlf,$divBar,$crlf,'#',$descpad,@desc,$crlf,$divBar))"/>
  93. <xsl:for-each-group select="current-group()/param" group-by="@name">
  94. <xsl:sort select="@name"/>
  95. <xsl:call-template name="param"/>
  96. </xsl:for-each-group>
  97. </xsl:for-each-group>
  98. </xsl:template>
  99. <xsl:template name="param">
  100. <xsl:param name="params" select="current-group()"/>
  101. <xsl:param name="desc_pre" as="xs:string*">
  102. <xsl:if test="@required = 'true'">(REQUIRED) </xsl:if>
  103. </xsl:param>
  104. <xsl:param name="desc_post" as="xs:string*">
  105. <xsl:if test="not(./@type = 'enum') and $params/val/@default='true'">
  106. <xsl:value-of select="concat(' Default value: ',distinct-values($params/val[@default='true']),'.')"/>
  107. </xsl:if>
  108. </xsl:param>
  109. <xsl:choose>
  110. <xsl:when test="@name = 'args.input' or @name = 'transtype' or @deprecated = 'true'">
  111. <!-- don't output these as they shouldn't be used in properties file -->
  112. </xsl:when>
  113. <xsl:otherwise>
  114. <xsl:variable name="exampleval">
  115. <xsl:choose>
  116. <xsl:when test="$params/val/@default='true'">
  117. <xsl:value-of select="distinct-values($params/val[@default='true'])"/>
  118. </xsl:when>
  119. <xsl:when test="./@type = 'enum'">
  120. <xsl:value-of select="distinct-values($params/val[1])"/>
  121. </xsl:when>
  122. <xsl:otherwise></xsl:otherwise>
  123. </xsl:choose>
  124. </xsl:variable>
  125. <xsl:value-of select="concat($crlf,$comment,@name,' = ',$exampleval)"/>
  126. <xsl:value-of select="fn:wrapAndIndent('',concat($desc_pre,@desc,$desc_post))"/>
  127. <xsl:choose>
  128. <xsl:when test="@type = 'enum' and $params/val">
  129. <xsl:for-each-group select="$params/val" group-by="text()">
  130. <xsl:sort select="current-grouping-key()"/>
  131. <xsl:choose>
  132. <xsl:when test="@desc and @default = 'true'">
  133. <xsl:value-of select="fn:wrapAndIndent('',concat('[ ',.,' ]* - ',@desc))"/>
  134. </xsl:when>
  135. <xsl:when test="@desc">
  136. <xsl:value-of select="fn:wrapAndIndent('',concat('[ ',.,' ] - ',@desc))"/>
  137. </xsl:when>
  138. <xsl:when test="@default='true'">
  139. <xsl:value-of select="fn:wrapAndIndent('',concat('[ ',.,' ]*'))"/>
  140. </xsl:when>
  141. <xsl:otherwise>
  142. <xsl:value-of select="fn:wrapAndIndent('',concat('[ ',.,' ]'))"/>
  143. </xsl:otherwise>
  144. </xsl:choose>
  145. </xsl:for-each-group>
  146. </xsl:when>
  147. </xsl:choose>
  148. </xsl:otherwise>
  149. </xsl:choose>
  150. </xsl:template>
  151. </xsl:stylesheet>