flagging-from-preprocess.xsl 9.7 KB

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