cssstyles.xslt 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: cpscrn
  5. (C) Copyright IBM Corp. 2005, 2011
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <!--
  9. Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  10. Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  11. -->
  12. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt" exclude-result-prefixes="xtsext">
  13. <xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>
  14. <xsl:param name="skinfile"/>
  15. <xsl:param name="overrides_path"/>
  16. <xsl:param name="comments" select="true()"/>
  17. <xsl:param name="debug" select="false()"/>
  18. <xsl:param name="webcontent"/>
  19. <xsl:param name="cgi"/>
  20. <xsl:param name="skin"/>
  21. <xsl:preserve-space elements="set"/>
  22. <xsl:variable name="skindoc">
  23. <xsl:if test="string($skinfile) != ''">
  24. <xsl:copy-of select="document($skinfile)"/>
  25. </xsl:if>
  26. </xsl:variable>
  27. <xsl:variable name="overrides_doc">
  28. <xsl:if test="string($overrides_path) !=''">
  29. <xsl:copy-of select="document($overrides_path)"/>
  30. </xsl:if>
  31. </xsl:variable>
  32. <xsl:variable name="colors" select="$skindoc/skin/colors/color"/>
  33. <xsl:variable name="values" select="$skindoc/skin/values/value"/>
  34. <xsl:variable name="classes" select="$overrides_doc/cssskin/class"/>
  35. <xsl:variable name="palette" select="$skindoc/skin/palette/color"/>
  36. <xsl:variable name="images" select="$skindoc/skin/images/image"/>
  37. <xsl:template match="/">
  38. <xsl:text>/*&#10; (C) Copyright IBM Corp. 2005, 2011.&#10; Licensed Material - Property of IBM Corp. IBM, the IBM logo, and Cognos are trademarks of IBM Corp., registered in many jurisdictions worldwide.&#10;*/&#10;</xsl:text>
  39. <xsl:text>&#10;/*****************************************************************************************&#10;</xsl:text>
  40. <xsl:text> This is a generated file. Any changes you make to it will not be upgraded.</xsl:text>
  41. <xsl:text>&#10;/*****************************************************************************************/&#10;</xsl:text>
  42. <xsl:if test="$debug='true'">
  43. <xsl:text>/*&#10;Parameters:</xsl:text>
  44. <xsl:text>&#10; skin: </xsl:text>
  45. <xsl:value-of select="$skin"/>
  46. <xsl:text>&#10; debug: </xsl:text>
  47. <xsl:value-of select="$debug"/>
  48. <xsl:text>&#10; comments: </xsl:text>
  49. <xsl:value-of select="$comments"/>
  50. <xsl:text>&#10; webcontent: </xsl:text>
  51. <xsl:value-of select="$webcontent"/>
  52. <xsl:text>&#10; cgi: </xsl:text>
  53. <xsl:value-of select="$cgi"/>
  54. <xsl:text>&#10;*/&#10;</xsl:text>
  55. </xsl:if>
  56. <xsl:variable name="excludes" select="/css/class/@name"/>
  57. <xsl:apply-templates select="/css/import | /css/class | /css/comment"/>
  58. <xsl:if test="$debug='true'">
  59. <xsl:text>/* new skin-specific classes */&#10;</xsl:text>
  60. </xsl:if>
  61. <xsl:apply-templates select="$classes[not(@name=$excludes)]"/>
  62. </xsl:template>
  63. <xsl:template match="comment">
  64. <xsl:if test="$comments='true'">
  65. <xsl:text>&#10;/* </xsl:text>
  66. <xsl:value-of select="."/>
  67. <xsl:text> */&#10;</xsl:text>
  68. </xsl:if>
  69. </xsl:template>
  70. <xsl:template match="import">
  71. <xsl:text>@import url(</xsl:text>
  72. <xsl:value-of select="."/>
  73. <xsl:text>);&#10;</xsl:text>
  74. </xsl:template>
  75. <xsl:template match="class">
  76. <xsl:if test="$debug='true'">
  77. <xsl:call-template name="xpath"/>
  78. <xsl:text>&#10;</xsl:text>
  79. </xsl:if>
  80. <xsl:value-of select="@name"/>
  81. <xsl:if test="@comment and $comments='true'">
  82. <xsl:text> /* </xsl:text>
  83. <xsl:value-of select="@comment"/>
  84. <xsl:text> */</xsl:text>
  85. </xsl:if>
  86. <xsl:text> {&#10;</xsl:text>
  87. <xsl:variable name="redefines" select="$classes[@name=current()/@name]"/>
  88. <xsl:choose>
  89. <xsl:when test="$redefines">
  90. <xsl:call-template name="gen-attributes">
  91. <xsl:with-param name="adds" select="$redefines/set"/>
  92. <xsl:with-param name="removes" select="$redefines/remove"/>
  93. </xsl:call-template>
  94. </xsl:when>
  95. <xsl:otherwise>
  96. <xsl:call-template name="gen-attributes"/>
  97. </xsl:otherwise>
  98. </xsl:choose>
  99. <xsl:text>}&#10;</xsl:text>
  100. </xsl:template>
  101. <xsl:template name="gen-attributes">
  102. <xsl:param name="tag" select="."/>
  103. <xsl:param name="adds" select=".[false()]"/>
  104. <xsl:param name="removes" select=".[false()]"/>
  105. <xsl:variable name="uses" select="concat(' ', @uses, ' ')"/>
  106. <xsl:variable name="sets" select="/css/type[contains($uses, concat(' ',@name,' '))]/set | $tag/set"/>
  107. <xsl:variable name="list" select="$sets[not(@name=$adds/@name or @name=$removes/@name)]"/>
  108. <xsl:apply-templates select="$list"/>
  109. <xsl:apply-templates select="$adds"/>
  110. </xsl:template>
  111. <xsl:template match="set">
  112. <xsl:text>&#9;</xsl:text>
  113. <xsl:value-of select="@name"/>
  114. <xsl:text>: </xsl:text>
  115. <xsl:apply-templates mode="attribute"/>
  116. <xsl:text>;</xsl:text>
  117. <xsl:if test="$debug='true'">
  118. <xsl:text>&#32;</xsl:text>
  119. <xsl:call-template name="xpath"/>
  120. </xsl:if>
  121. <xsl:text>&#10;</xsl:text>
  122. </xsl:template>
  123. <xsl:template match="remove"/>
  124. <xsl:template match="color" mode="attribute">
  125. <xsl:variable name="color" select="$colors[@name=current()/@name]"/>
  126. <xsl:choose>
  127. <xsl:when test="not($color)">
  128. <xsl:text>/* MISSING: </xsl:text>
  129. <xsl:value-of select="@name"/>
  130. <xsl:text> */ red</xsl:text>
  131. </xsl:when>
  132. <xsl:when test="$color/@paletteColor">
  133. <xsl:value-of select="$palette[@name=$color/@paletteColor]"/>
  134. </xsl:when>
  135. <xsl:when test="$color/@baseColor">
  136. <xsl:apply-templates select="$colors[@name=$color/@baseColor]" mode="attribute"/>
  137. </xsl:when>
  138. <xsl:otherwise>
  139. <xsl:value-of select="$color"/>
  140. </xsl:otherwise>
  141. </xsl:choose>
  142. </xsl:template>
  143. <xsl:template match="value" mode="attribute">
  144. <xsl:variable name="value" select="$values[@name=current()/@name]"/>
  145. <xsl:choose>
  146. <xsl:when test="not($value)">
  147. <xsl:text>/* MISSING VALUE: </xsl:text>
  148. <xsl:value-of select="@name"/>
  149. <xsl:text> */</xsl:text>
  150. </xsl:when>
  151. <xsl:when test="$value/@baseValue">
  152. <xsl:apply-templates select="$values[@name=$value/@baseValue]" mode="attribute"/>
  153. </xsl:when>
  154. <xsl:otherwise>
  155. <xsl:value-of select="$value"/>
  156. </xsl:otherwise>
  157. </xsl:choose>
  158. </xsl:template>
  159. <xsl:template match="image" mode="attribute">
  160. <xsl:variable name="image" select="$images[@name=current()/@name]"/>
  161. <xsl:choose>
  162. <xsl:when test="not($image)">
  163. <xsl:text>/* MISSING: </xsl:text>
  164. <xsl:value-of select="@name"/>
  165. <xsl:text> */ none</xsl:text>
  166. </xsl:when>
  167. <xsl:when test="$image=''">
  168. <xsl:text>none</xsl:text>
  169. </xsl:when>
  170. <xsl:otherwise>
  171. <xsl:variable name="imagePath" select="$images[@name=current()/@name]"/>
  172. <xsl:variable name="webmacro" select="'$WEB$'"/>
  173. <xsl:variable name="webdir" select="'../../..'"/>
  174. <xsl:variable name="skinmacro" select="'$WEB$/skins/$SKIN$'"/>
  175. <xsl:variable name="skindir" select="'..'"/>
  176. <xsl:variable name="updatedText" select="xtsext:replace(string($imagePath), string($skinmacro), string($skindir))"/>
  177. <xsl:value-of select="xtsext:replace(string($updatedText), string($webmacro), string($webdir))"/>
  178. </xsl:otherwise>
  179. </xsl:choose>
  180. </xsl:template>
  181. <xsl:template name="gen-text" match="text()" mode="attribute">
  182. <xsl:param name="text" select="."/>
  183. <xsl:variable name="webmacro" select="'$WEB$'"/>
  184. <xsl:variable name="webdir" select="'../../..'"/>
  185. <xsl:variable name="skinmacro" select="'$WEB$/skins/$SKIN$'"/>
  186. <xsl:variable name="skindir" select="'..'"/>
  187. <xsl:variable name="updatedText" select="xtsext:replace(string($text), string($skinmacro), string($skindir))"/>
  188. <xsl:value-of select="xtsext:replace(string($updatedText), string($webmacro), string($webdir))"/>
  189. </xsl:template>
  190. <xsl:template name="xpath">
  191. <xsl:text>/* xpath: </xsl:text>
  192. <xsl:for-each select="ancestor-or-self::node()[name()!='']">
  193. <xsl:text>/</xsl:text>
  194. <xsl:value-of select="name()"/>
  195. <xsl:text>[</xsl:text>
  196. <xsl:value-of select="count(preceding-sibling::*[name()=name(current())]) + 1"/>
  197. <xsl:text>]</xsl:text>
  198. </xsl:for-each>
  199. <xsl:text> */</xsl:text>
  200. </xsl:template>
  201. </xsl:stylesheet>