markdownflag.xsl 5.6 KB

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