admon.xsl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  4. version='1.0'>
  5. <!-- ********************************************************************
  6. $Id$
  7. ********************************************************************
  8. This file is part of the XSL DocBook Stylesheet distribution.
  9. See ../README or http://docbook.sf.net/release/xsl/current/ for
  10. copyright and other information.
  11. ******************************************************************** -->
  12. <xsl:template match="note|important|warning|caution|tip">
  13. <xsl:choose>
  14. <xsl:when test="$admon.graphics != 0">
  15. <xsl:call-template name="graphical.admonition"/>
  16. </xsl:when>
  17. <xsl:otherwise>
  18. <xsl:call-template name="nongraphical.admonition"/>
  19. </xsl:otherwise>
  20. </xsl:choose>
  21. </xsl:template>
  22. <xsl:template match="*" mode="admon.graphic.width">
  23. <xsl:param name="node" select="."/>
  24. <xsl:text>36pt</xsl:text>
  25. </xsl:template>
  26. <xsl:template name="admon.graphic">
  27. <xsl:param name="node" select="."/>
  28. <xsl:variable name="filename">
  29. <xsl:value-of select="$admon.graphics.path"/>
  30. <xsl:choose>
  31. <xsl:when test="local-name($node)='note'">note</xsl:when>
  32. <xsl:when test="local-name($node)='warning'">warning</xsl:when>
  33. <xsl:when test="local-name($node)='caution'">caution</xsl:when>
  34. <xsl:when test="local-name($node)='tip'">tip</xsl:when>
  35. <xsl:when test="local-name($node)='important'">important</xsl:when>
  36. <xsl:otherwise>note</xsl:otherwise>
  37. </xsl:choose>
  38. <xsl:value-of select="$admon.graphics.extension"/>
  39. </xsl:variable>
  40. <xsl:choose>
  41. <xsl:when test="$passivetex.extensions != 0
  42. or $fop.extensions != 0
  43. or $arbortext.extensions != 0">
  44. <xsl:value-of select="$filename"/>
  45. </xsl:when>
  46. <xsl:otherwise>
  47. <xsl:text>url(</xsl:text>
  48. <xsl:value-of select="$filename"/>
  49. <xsl:text>)</xsl:text>
  50. </xsl:otherwise>
  51. </xsl:choose>
  52. </xsl:template>
  53. <xsl:template name="graphical.admonition">
  54. <xsl:variable name="id">
  55. <xsl:call-template name="object.id"/>
  56. </xsl:variable>
  57. <xsl:variable name="graphic.width">
  58. <xsl:apply-templates select="." mode="admon.graphic.width"/>
  59. </xsl:variable>
  60. <fo:block id="{$id}"
  61. xsl:use-attribute-sets="graphical.admonition.properties">
  62. <fo:list-block provisional-distance-between-starts="{$graphic.width} + 18pt"
  63. provisional-label-separation="18pt">
  64. <fo:list-item>
  65. <fo:list-item-label end-indent="label-end()">
  66. <fo:block>
  67. <fo:external-graphic width="auto" height="auto"
  68. content-width="{$graphic.width}" >
  69. <xsl:attribute name="src">
  70. <xsl:call-template name="admon.graphic"/>
  71. </xsl:attribute>
  72. </fo:external-graphic>
  73. </fo:block>
  74. </fo:list-item-label>
  75. <fo:list-item-body start-indent="body-start()">
  76. <xsl:if test="$admon.textlabel != 0 or title or info/title">
  77. <fo:block xsl:use-attribute-sets="admonition.title.properties">
  78. <xsl:apply-templates select="." mode="object.title.markup">
  79. <xsl:with-param name="allow-anchors" select="1"/>
  80. </xsl:apply-templates>
  81. </fo:block>
  82. </xsl:if>
  83. <fo:block xsl:use-attribute-sets="admonition.properties">
  84. <xsl:apply-templates/>
  85. </fo:block>
  86. </fo:list-item-body>
  87. </fo:list-item>
  88. </fo:list-block>
  89. </fo:block>
  90. </xsl:template>
  91. <xsl:template name="nongraphical.admonition">
  92. <xsl:variable name="id">
  93. <xsl:call-template name="object.id"/>
  94. </xsl:variable>
  95. <fo:block id="{$id}"
  96. xsl:use-attribute-sets="nongraphical.admonition.properties">
  97. <xsl:if test="$admon.textlabel != 0 or title or info/title">
  98. <fo:block keep-with-next.within-column='always'
  99. xsl:use-attribute-sets="admonition.title.properties">
  100. <xsl:apply-templates select="." mode="object.title.markup">
  101. <xsl:with-param name="allow-anchors" select="1"/>
  102. </xsl:apply-templates>
  103. </fo:block>
  104. </xsl:if>
  105. <fo:block xsl:use-attribute-sets="admonition.properties">
  106. <xsl:apply-templates/>
  107. </fo:block>
  108. </fo:block>
  109. </xsl:template>
  110. <xsl:template match="note/title"></xsl:template>
  111. <xsl:template match="important/title"></xsl:template>
  112. <xsl:template match="warning/title"></xsl:template>
  113. <xsl:template match="caution/title"></xsl:template>
  114. <xsl:template match="tip/title"></xsl:template>
  115. </xsl:stylesheet>