flagging-from-preprocess.xsl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. This file is part of the DITA Open Toolkit project.
  4. Copyright 2015 IBM Corporation
  5. See the accompanying LICENSE file for applicable license.
  6. -->
  7. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  8. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  9. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  10. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  11. version="2.0"
  12. exclude-result-prefixes="xs dita-ot">
  13. <!-- For reference, flagging info as it appears in the topics: -->
  14. <!--<ditaval-startprop class="+ topic/foreign ditaot-d/ditaval-startprop ">
  15. <prop action="flag" att="audience" val="p">
  16. <startflag imageref="yukface.jpg" dita-ot:original-imageref="yukface.jpg"><alt-text>Start P</alt-text></startflag>
  17. </prop>
  18. <prop action="flag" att="audience" backcolor="aqua" color="blue" style="italics" val="meep"/>
  19. <revprop action="flag" backcolor="maroon" changebar="|" color="olive" style="underline" val="testrev"/>
  20. </ditaval-startprop>
  21. <ditaval-endprop class="+ topic/foreign ditaot-d/ditaval-endprop ">
  22. <prop action="flag" att="audience" val="p">
  23. <endflag imageref="smileface.jpg" dita-ot:original-imageref="smileface.jpg"><alt-text>End P</alt-text></endflag>
  24. </prop>
  25. </ditaval-endprop>
  26. -->
  27. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-startprop ') or contains(@class,' ditaot-d/ditaval-endprop ')]
  28. [parent::*[contains(@class,' topic/ol ') or contains(@class,' topic/ul ') or
  29. contains(@class,' topic/sl ')]]" priority="10">
  30. <!-- Process with "outofline" in lists.xsl -->
  31. </xsl:template>
  32. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-startprop ') or contains(@class,' ditaot-d/ditaval-endprop ')]
  33. [parent::*[contains(@class,' topic/dl ') or contains(@class,' topic/dlhead ') or
  34. contains(@class,' topic/dlentry ')]]" priority="10">
  35. <!-- Process with "outofline" in tables.xsl -->
  36. </xsl:template>
  37. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-startprop ') or contains(@class,' ditaot-d/ditaval-endprop ')]
  38. [parent::*[contains(@class,' topic/table ') or contains(@class,' topic/simpletable ') or
  39. contains(@class,' topic/tgroup ') or contains(@class,' topic/tbody ') or
  40. contains(@class,' topic/thead ') or contains(@class,' topic/sthead ') or
  41. contains(@class,' topic/row ') or contains(@class,' topic/strow ')]]" priority="10">
  42. <!-- Process with "outofline" in tables.xsl -->
  43. </xsl:template>
  44. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-startprop ') or contains(@class,' ditaot-d/ditaval-endprop ')]
  45. [parent::*[contains(@class,' topic/image ') or contains(@class, ' svg-d/svgref ')]]" priority="10">
  46. <!-- Process with "outofline" in commons.xsl -->
  47. </xsl:template>
  48. <xsl:template match="*[contains(@class,' topic/stentry ')]" mode="ancestor-start-flag">
  49. <!-- If first stentry in a row, pick up start flag from the row -->
  50. <xsl:if test="not(preceding-sibling::*[contains(@class,' topic/stentry ')])">
  51. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="outofline"/>
  52. </xsl:if>
  53. </xsl:template>
  54. <xsl:template match="*[contains(@class,' topic/stentry ')]" mode="ancestor-end-flag">
  55. <!-- If last stentry in a row, pick up end flag from the row -->
  56. <xsl:if test="not(following-sibling::*[contains(@class,' topic/stentry ')])">
  57. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="outofline"/>
  58. </xsl:if>
  59. </xsl:template>
  60. <xsl:template match="*[contains(@class,' topic/entry ')]" mode="ancestor-start-flag">
  61. <xsl:if test="not(preceding-sibling::*[contains(@class,' topic/entry ')])">
  62. <!-- check tgroup, tbody or thead, row -->
  63. <xsl:apply-templates select="../../../*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="outofline"/>
  64. <xsl:apply-templates select="../../*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="outofline"/>
  65. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="outofline"/>
  66. </xsl:if>
  67. </xsl:template>
  68. <xsl:template match="*[contains(@class,' topic/entry ')]" mode="ancestor-end-flag">
  69. <xsl:if test="not(following-sibling::*[contains(@class,' topic/entry ')])">
  70. <!-- check row, tbody or thead, tgroup -->
  71. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="outofline"/>
  72. <xsl:apply-templates select="../../*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="outofline"/>
  73. <xsl:apply-templates select="../../../*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="outofline"/>
  74. </xsl:if>
  75. </xsl:template>
  76. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-startprop ')] |
  77. *[contains(@class,' ditaot-d/ditaval-endprop ')]">
  78. <!-- Style flags called from common attributes -->
  79. <!--<xsl:apply-templates select="." mode="flag-attributes"/>-->
  80. <xsl:apply-templates select="revprop[@changebar]" mode="changebar">
  81. <xsl:with-param name="changebar-id" select="dita-ot:generate-changebar-id(.)"/>
  82. </xsl:apply-templates>
  83. <xsl:apply-templates select="." mode="flag-images"/>
  84. </xsl:template>
  85. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-startprop ')] |
  86. *[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="outofline">
  87. <xsl:apply-templates select="revprop[@changebar]" mode="changebar">
  88. <xsl:with-param name="changebar-id" select="dita-ot:generate-changebar-id(.)"/>
  89. </xsl:apply-templates>
  90. <xsl:apply-templates select="." mode="flag-images"/>
  91. </xsl:template>
  92. <xsl:function name="dita-ot:generate-changebar-id" as="xs:string">
  93. <xsl:param name="current" as="element()"/>
  94. <xsl:value-of select="concat(generate-id($current/parent::*), '-cbar')"/>
  95. </xsl:function>
  96. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="flag-attributes">
  97. <xsl:apply-templates select=".//prop/@backcolor | .//prop/@color | .//prop/@style |
  98. .//revprop/@backcolor | .//revprop/@color | .//revprop/@style" mode="flag-attributes"/>
  99. </xsl:template>
  100. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="flag-attributes">
  101. <!-- No flagging at end -->
  102. </xsl:template>
  103. <xsl:template match="@backcolor" mode="flag-attributes">
  104. <xsl:attribute name="background-color" select="."/>
  105. </xsl:template>
  106. <xsl:template match="@color" mode="flag-attributes">
  107. <xsl:attribute name="color" select="."/>
  108. </xsl:template>
  109. <xsl:template match="@style" mode="flag-attributes">
  110. <xsl:choose>
  111. <xsl:when test=".='bold'">
  112. <xsl:attribute name="font-weight">bold</xsl:attribute>
  113. </xsl:when>
  114. <xsl:when test=".='italics' or .='italic'">
  115. <xsl:attribute name="font-style">italic</xsl:attribute>
  116. </xsl:when>
  117. <xsl:when test=".='double-underline'">
  118. <xsl:attribute name="text-decoration">underline</xsl:attribute>
  119. </xsl:when>
  120. <xsl:otherwise>
  121. <xsl:attribute name="text-decoration" select="."/>
  122. </xsl:otherwise>
  123. </xsl:choose>
  124. </xsl:template>
  125. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-startprop ')]/revprop" mode="changebar">
  126. <xsl:param name="changebar-id"/>
  127. <xsl:param name="changebar-style">
  128. <xsl:choose>
  129. <xsl:when test="@changebar = ('none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset')">
  130. <xsl:value-of select="@changebar"/>
  131. </xsl:when>
  132. <xsl:otherwise>groove</xsl:otherwise>
  133. </xsl:choose>
  134. </xsl:param>
  135. <xsl:param name="changebar-color">
  136. <!-- Could take color from @changebar, but for now take from @color to allow @changebar to set style; bar color matches text -->
  137. <xsl:choose>
  138. <xsl:when test="@color"><xsl:value-of select="@color"/></xsl:when>
  139. <xsl:otherwise>black</xsl:otherwise>
  140. </xsl:choose>
  141. </xsl:param>
  142. <fo:change-bar-begin
  143. change-bar-class="{$changebar-id}"
  144. change-bar-style="{$changebar-style}"
  145. change-bar-color="{$changebar-color}"
  146. change-bar-offset="2mm"/>
  147. </xsl:template>
  148. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-endprop ')]/revprop" mode="changebar">
  149. <xsl:param name="changebar-id"/>
  150. <fo:change-bar-end change-bar-class="{$changebar-id}"/>
  151. </xsl:template>
  152. <xsl:template match="*" mode="flag-images">
  153. <xsl:if test="*//startflag|*//endflag">
  154. <xsl:variable name="flags" as="element()*">
  155. <xsl:for-each select=".//startflag|.//endflag">
  156. <xsl:choose>
  157. <xsl:when test="@dita-ot:original-imageref">
  158. <image class="+ topic/image ditaot-d/flagimage " href="{@dita-ot:original-imageref}" placement="inline">
  159. <alt class="- topic/alt "><xsl:value-of select="alt-text"/></alt>
  160. </image>
  161. </xsl:when>
  162. <xsl:when test="@imageref">
  163. <image class="+ topic/image ditaot-d/flagimage " href="{@imageref}" placement="inline">
  164. <alt class="- topic/alt "><xsl:value-of select="alt-text"/></alt>
  165. </image>
  166. </xsl:when>
  167. <xsl:when test="alt-text">
  168. <text class="+ topic/text ditaot-d/flagtext "> [<xsl:value-of select="alt-text"/>] </text>
  169. </xsl:when>
  170. </xsl:choose>
  171. </xsl:for-each>
  172. </xsl:variable>
  173. <xsl:choose>
  174. <xsl:when test="parent::*[contains(@class,' topic/dl ') or
  175. contains(@class,' topic/image ') or
  176. contains(@class, ' svg-d/svgref ')]">
  177. <fo:inline xsl:use-attribute-sets="image__inline">
  178. <xsl:apply-templates select="$flags"/>
  179. </fo:inline>
  180. </xsl:when>
  181. <xsl:otherwise>
  182. <xsl:apply-templates select="$flags"/>
  183. </xsl:otherwise>
  184. </xsl:choose>
  185. </xsl:if>
  186. </xsl:template>
  187. </xsl:stylesheet>