dita2rtf-img.xsl 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- This file is part of the DITA Open Toolkit project.
  3. See the accompanying license.txt file for applicable licenses.-->
  4. <!-- (c) Copyright IBM Corp. 2005, 2006 All Rights Reserved. -->
  5. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:java="org.dita.dost.util.ImgUtils" xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot" exclude-result-prefixes="java dita-ot">
  6. <xsl:template match="*[contains(@class,' topic/fig ')]">
  7. <xsl:apply-templates/>
  8. </xsl:template>
  9. <xsl:template match="*[contains(@class,' topic/fig ')]/*[contains(@class,' topic/title ')]">
  10. <xsl:variable name="ancestorlang">
  11. <xsl:call-template name="getLowerCaseLang"/>
  12. </xsl:variable>
  13. <xsl:variable name="fig-count-actual" select="count(preceding::*[contains(@class,' topic/fig ')]/*[contains(@class,' topic/title ')])+1"><!-- Number of fig/title's including this one --></xsl:variable>
  14. <xsl:call-template name="gen-id"/>\pard \plain\s9 \qc\f4\fs24\b <xsl:if test="ancestor::*[contains(@class,' topic/table ') or contains(@class,' topic/simpletable ')]">\intbl </xsl:if><xsl:choose><!-- Hungarian: "1. Figure " --><xsl:when test="( (string-length($ancestorlang)=5 and contains($ancestorlang,'hu-hu')) or (string-length($ancestorlang)=2 and contains($ancestorlang,'hu')) )"><xsl:value-of select="$fig-count-actual"/><xsl:text>. </xsl:text><xsl:call-template name="getStringRTF"><xsl:with-param name="stringName" select="'Figure'"/></xsl:call-template><xsl:text> </xsl:text></xsl:when><xsl:otherwise><xsl:call-template name="getStringRTF"><xsl:with-param name="stringName" select="'Figure'"/></xsl:call-template><xsl:text> </xsl:text><xsl:value-of select="$fig-count-actual"/><xsl:text>. </xsl:text></xsl:otherwise></xsl:choose><xsl:value-of select="."/>\par \plain\s0 \qj\f2\fs24
  15. </xsl:template>
  16. <xsl:template match="*[contains(@class,' topic/fig ')]/*[contains(@class,' topic/desc ')]">
  17. <xsl:call-template name="gen-id"/>\pard \plain\s0 \f2\fs24<xsl:if test="ancestor::*[contains(@class,' topic/table ') or contains(@class,' topic/simpletable ')]">\intbl </xsl:if><xsl:apply-templates/>\par \plain\s0 \f2\fs24
  18. </xsl:template>
  19. <xsl:template match="*[contains(@class,' topic/image ')]">
  20. <xsl:if test="@href and not(@href='')">
  21. <xsl:variable name="type">
  22. <xsl:choose>
  23. <xsl:when test="not(contains(@href,'://'))">
  24. <xsl:call-template name="getType">
  25. <xsl:with-param name="file" select="string(@href)"/>
  26. </xsl:call-template>
  27. </xsl:when>
  28. <xsl:otherwise/>
  29. </xsl:choose>
  30. </xsl:variable>
  31. <xsl:variable name="height" select="@dita-ot:image-height"/>
  32. <xsl:variable name="width" select="@dita-ot:image-width"/>
  33. <xsl:call-template name="gen-id"/>
  34. <xsl:choose>
  35. <xsl:when test="not(contains(@href,'://')) and $type and not($type='other') and ($height &gt; 0) and ($width &gt; 0)">
  36. <xsl:text>{\*\shppict {\pict \picw</xsl:text><xsl:value-of select="$width"/>\pich<xsl:value-of
  37. select="$height"/>\<xsl:value-of select="$type"/><xsl:text> </xsl:text><xsl:value-of
  38. select="java:getBinData($OUTPUTDIR, string(@href))"/><xsl:text>}}</xsl:text>
  39. </xsl:when>
  40. <xsl:otherwise>{\field{\*\fldinst {\s8 \f2\fs24\ul\cf1 HYPERLINK "<xsl:value-of select="@href"/>"}}{\fldrslt {\s8 \f2\fs24\ul\cf1 <xsl:call-template name="gen-img-txt"/>\s8 \f2\fs24\ul\cf1}}}</xsl:otherwise>
  41. </xsl:choose>
  42. </xsl:if>
  43. </xsl:template>
  44. <xsl:template name="gen-img-txt">
  45. <xsl:choose>
  46. <xsl:when test="*[contains(@class,' topic/alt ')]">
  47. <xsl:text>[PIC]</xsl:text><xsl:value-of select="*[contains(@class,' topic/alt ')]"/>
  48. </xsl:when>
  49. <xsl:when test="@alt and not(@alt='')"><xsl:text>[PIC]</xsl:text><xsl:value-of select="@alt"/></xsl:when>
  50. <xsl:when test="text() or *"><xsl:text>[PIC]</xsl:text><xsl:apply-templates/></xsl:when>
  51. <xsl:otherwise><xsl:text>[PIC]</xsl:text><xsl:value-of select="@href"/></xsl:otherwise>
  52. </xsl:choose>
  53. </xsl:template>
  54. <xsl:template name="getType">
  55. <xsl:param name="file"/>
  56. <xsl:variable name="f" select="lower-case($file)"/>
  57. <xsl:choose>
  58. <xsl:when test="ends-with($f, '.jpg') or ends-with($f, '.jpeg')">
  59. <xsl:text>jpegblip</xsl:text>
  60. </xsl:when>
  61. <xsl:when test="ends-with($f, '.gif') or ends-with($f, '.png')">
  62. <xsl:text>pngblip</xsl:text>
  63. </xsl:when>
  64. <xsl:otherwise>
  65. <xsl:text>other</xsl:text>
  66. <xsl:call-template name="output-message">
  67. <xsl:with-param name="msgcat" select="'DOTJ'"/>
  68. <xsl:with-param name="msgnum" select="'024'"/>
  69. <xsl:with-param name="msgsev" select="'W'"/>
  70. <xsl:with-param name="msgparams" select="concat('%1=', $file)"/>
  71. </xsl:call-template>
  72. </xsl:otherwise>
  73. </xsl:choose>
  74. </xsl:template>
  75. </xsl:stylesheet>