admon.xsl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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: admon.xsl 9647 2012-10-26 17:42:03Z bobstayton $
  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="$fop.extensions != 0
  42. or $arbortext.extensions != 0">
  43. <xsl:value-of select="$filename"/>
  44. </xsl:when>
  45. <xsl:otherwise>
  46. <xsl:text>url(</xsl:text>
  47. <xsl:value-of select="$filename"/>
  48. <xsl:text>)</xsl:text>
  49. </xsl:otherwise>
  50. </xsl:choose>
  51. </xsl:template>
  52. <xsl:template name="graphical.admonition">
  53. <xsl:variable name="id">
  54. <xsl:call-template name="object.id"/>
  55. </xsl:variable>
  56. <xsl:variable name="graphic.width">
  57. <xsl:apply-templates select="." mode="admon.graphic.width"/>
  58. </xsl:variable>
  59. <fo:block id="{$id}"
  60. xsl:use-attribute-sets="graphical.admonition.properties">
  61. <fo:list-block provisional-distance-between-starts="{$graphic.width} + 18pt"
  62. provisional-label-separation="18pt">
  63. <fo:list-item>
  64. <fo:list-item-label end-indent="label-end()">
  65. <fo:block>
  66. <fo:external-graphic width="auto" height="auto"
  67. content-width="{$graphic.width}" >
  68. <xsl:attribute name="src">
  69. <xsl:call-template name="admon.graphic"/>
  70. </xsl:attribute>
  71. </fo:external-graphic>
  72. </fo:block>
  73. </fo:list-item-label>
  74. <fo:list-item-body start-indent="body-start()">
  75. <xsl:if test="$admon.textlabel != 0 or title or info/title">
  76. <fo:block xsl:use-attribute-sets="admonition.title.properties">
  77. <xsl:apply-templates select="." mode="object.title.markup">
  78. <xsl:with-param name="allow-anchors" select="1"/>
  79. </xsl:apply-templates>
  80. </fo:block>
  81. </xsl:if>
  82. <fo:block xsl:use-attribute-sets="admonition.properties">
  83. <xsl:apply-templates/>
  84. </fo:block>
  85. </fo:list-item-body>
  86. </fo:list-item>
  87. </fo:list-block>
  88. </fo:block>
  89. </xsl:template>
  90. <xsl:template name="nongraphical.admonition">
  91. <xsl:variable name="id">
  92. <xsl:call-template name="object.id"/>
  93. </xsl:variable>
  94. <fo:block id="{$id}"
  95. xsl:use-attribute-sets="nongraphical.admonition.properties">
  96. <xsl:if test="$admon.textlabel != 0 or title or info/title">
  97. <fo:block keep-with-next.within-column='always'
  98. xsl:use-attribute-sets="admonition.title.properties">
  99. <xsl:apply-templates select="." mode="object.title.markup">
  100. <xsl:with-param name="allow-anchors" select="1"/>
  101. </xsl:apply-templates>
  102. </fo:block>
  103. </xsl:if>
  104. <fo:block xsl:use-attribute-sets="admonition.properties">
  105. <xsl:apply-templates/>
  106. </fo:block>
  107. </fo:block>
  108. </xsl:template>
  109. <xsl:template match="note/title"></xsl:template>
  110. <xsl:template match="important/title"></xsl:template>
  111. <xsl:template match="warning/title"></xsl:template>
  112. <xsl:template match="caution/title"></xsl:template>
  113. <xsl:template match="tip/title"></xsl:template>
  114. </xsl:stylesheet>