htmlflag.xsl 6.2 KB

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