htmlflag.xsl 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. This file is part of the DITA Open Toolkit project.
  4. Copyright 2012 IBM Corporation
  5. See the accompanying LICENSE file for applicable license.
  6. -->
  7. <!-- PURPOSE:
  8. Match DITAVAL information added by preprocessing and output pre-calculated flags.
  9. If a start or end flag is present, it is known to be active and should be generated.
  10. If processing the flag directly will cause out-of-context XHTML, the processing
  11. must be explicitly requested by the HTML code by processing with the "process-exception" mode.
  12. -->
  13. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  14. version="2.0">
  15. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-startprop ')]/@outputclass" mode="add-ditaval-style">
  16. <!-- Add the pre-calculated CSS style for this element -->
  17. <xsl:attribute name="style"><xsl:value-of select="."/></xsl:attribute>
  18. </xsl:template>
  19. <!-- By default, process flags where encountered: at the start and end of the element content. -->
  20. <xsl:template match="*" mode="processFlagsInline">yes</xsl:template>
  21. <!-- For lists, process out-of-line in order to keep XHTML valid. -->
  22. <xsl:template match="*[contains(@class,' topic/ol ') or
  23. contains(@class,' topic/ul ') or
  24. contains(@class,' topic/sl ')]" mode="processFlagsInline">no</xsl:template>
  25. <xsl:template match="*[contains(@class,' topic/dl ') or
  26. contains(@class,' topic/dlentry ') or
  27. contains(@class,' topic/dlhead ')]" mode="processFlagsInline">no</xsl:template>
  28. <!-- Table flags have to be moved around to maintain XHTML validity -->
  29. <xsl:template match="*[contains(@class,' topic/table ') or
  30. contains(@class,' topic/tgroup ') or
  31. contains(@class,' topic/thead ') or
  32. contains(@class,' topic/tbody ') or
  33. contains(@class,' topic/row ') or
  34. contains(@class,' topic/simpletable ') or
  35. contains(@class,' topic/sthead ') or
  36. contains(@class,' topic/strow ')]" mode="processFlagsInline">no</xsl:template>
  37. <!-- For notes, process out-of-line to keep start flag ahead of generated heading -->
  38. <xsl:template match="*[contains(@class,' topic/note ')]" mode="processFlagsInline">no</xsl:template>
  39. <!-- For fig, process out-of-line to keep start flag ahead of generated heading -->
  40. <xsl:template match="*[contains(@class,' topic/fig ')]" mode="processFlagsInline">no</xsl:template>
  41. <!-- For pre, process out-of-line to keep start flag ahead of block, otherwise it throws off spacing -->
  42. <xsl:template match="*[contains(@class,' topic/pre ')]" mode="processFlagsInline">no</xsl:template>
  43. <!-- For root topic, process out-of-line to get flags around headers/footers -->
  44. <xsl:template match="/*[contains(@class,' topic/topic ')]" mode="processFlagsInline">no</xsl:template>
  45. <!-- For body, process out-of-line to get ahead of shortdesc/abstract, after links -->
  46. <xsl:template match="*[contains(@class,' topic/body ')]" mode="processFlagsInline">no</xsl:template>
  47. <!-- For section or example, process out-of-line to get ahead flags ahead of the title -->
  48. <xsl:template match="*[contains(@class,' topic/section ') or
  49. contains(@class,' topic/example ')]" mode="processFlagsInline">no</xsl:template>
  50. <!-- For lq, process out-of-line to get end flags after citation info -->
  51. <xsl:template match="*[contains(@class,' topic/lq ')]" mode="processFlagsInline">no</xsl:template>
  52. <!-- Image should not hit this in fallthrough, but is explicitly processed before/after <img> -->
  53. <xsl:template match="*[contains(@class,' topic/image ')]" mode="processFlagsInline">no</xsl:template>
  54. <!-- If a tm symbol is generated, flag should go after -->
  55. <xsl:template match="*[contains(@class,' topic/tm ')]" mode="processFlagsInline">no</xsl:template>
  56. <!-- Link processing often works as fallthrough, but often not; do make link processing easier,
  57. handle all instances out-of-line. -->
  58. <xsl:template match="*[contains(@class,' topic/link ') or
  59. contains(@class,' topic/linklist ')]" mode="processFlagsInline">no</xsl:template>
  60. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-startprop ')]">
  61. <xsl:variable name="processnow">
  62. <xsl:apply-templates select="parent::*" mode="processFlagsInline"/>
  63. </xsl:variable>
  64. <xsl:if test="$processnow='yes'">
  65. <xsl:apply-templates select="prop/startflag" mode="ditaval-outputflag"/>
  66. <xsl:apply-templates select="revprop/startflag" mode="ditaval-outputflag"/>
  67. </xsl:if>
  68. </xsl:template>
  69. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="out-of-line">
  70. <xsl:apply-templates select="prop/startflag" mode="ditaval-outputflag"/>
  71. <xsl:apply-templates select="revprop/startflag" mode="ditaval-outputflag"/>
  72. </xsl:template>
  73. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-endprop ')]">
  74. <xsl:variable name="processnow">
  75. <xsl:apply-templates select="parent::*" mode="processFlagsInline"/>
  76. </xsl:variable>
  77. <xsl:if test="$processnow='yes'">
  78. <xsl:apply-templates select="revprop/endflag" mode="ditaval-outputflag"/>
  79. <xsl:apply-templates select="prop/endflag" mode="ditaval-outputflag"/>
  80. </xsl:if>
  81. </xsl:template>
  82. <xsl:template match="*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="out-of-line">
  83. <xsl:apply-templates select="revprop/endflag" mode="ditaval-outputflag"/>
  84. <xsl:apply-templates select="prop/endflag" mode="ditaval-outputflag"/>
  85. </xsl:template>
  86. <xsl:template match="startflag|endflag" mode="ditaval-outputflag">
  87. <xsl:choose>
  88. <xsl:when test="@imageref">
  89. <img src="{@imageref}">
  90. <xsl:apply-templates select="alt-text" mode="ditaval-outputflag"/>
  91. </img>
  92. </xsl:when>
  93. <xsl:otherwise>
  94. <xsl:value-of select="alt-text"/>
  95. </xsl:otherwise>
  96. </xsl:choose>
  97. </xsl:template>
  98. <xsl:template match="alt-text" mode="ditaval-outputflag">
  99. <xsl:attribute name="alt">
  100. <xsl:value-of select="."/>
  101. </xsl:attribute>
  102. </xsl:template>
  103. </xsl:stylesheet>