topic2textonly.xsl 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?xml version="1.0"?>
  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 Corporation 2010. All Rights Reserved. -->
  6. <xsl:stylesheet version="2.0"
  7. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  8. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  9. exclude-result-prefixes="dita-ot"
  10. >
  11. <!-- DEFAULT RULE: FOR EVERY ELEMENT, ONLY PROCESS TEXT CONTENT -->
  12. <xsl:template match="*" mode="dita-ot:text-only">
  13. <xsl:apply-templates select="text()|*|processing-instruction()" mode="dita-ot:text-only"/>
  14. </xsl:template>
  15. <xsl:template match="text()" mode="dita-ot:text-only">
  16. <xsl:value-of select="."/>
  17. </xsl:template>
  18. <!-- add "'" for q -->
  19. <xsl:template match="*[contains(@class,' topic/q ')]" mode="dita-ot:text-only">
  20. <xsl:call-template name="getVariable">
  21. <xsl:with-param name="id" select="'OpenQuote'"/>
  22. </xsl:call-template>
  23. <xsl:apply-templates mode="dita-ot:text-only"/>
  24. <xsl:call-template name="getVariable">
  25. <xsl:with-param name="id" select="'CloseQuote'"/>
  26. </xsl:call-template>
  27. </xsl:template>
  28. <xsl:template match="processing-instruction()" mode="dita-ot:text-only"/>
  29. <!-- ELEMENTS THAT SHOULD BE DROPPED FROM DEFAULT TEXT-ONLY RENDITIONS -->
  30. <xsl:template match="*[contains(@class,' topic/indexterm ')]" mode="dita-ot:text-only"/>
  31. <xsl:template match="*[contains(@class,' topic/draft-comment ')]" mode="dita-ot:text-only"/>
  32. <xsl:template match="*[contains(@class,' topic/required-cleanup ')]" mode="dita-ot:text-only"/>
  33. <xsl:template match="*[contains(@class,' topic/data ')]" mode="dita-ot:text-only"/>
  34. <xsl:template match="*[contains(@class,' topic/data-about ')]" mode="dita-ot:text-only"/>
  35. <xsl:template match="*[contains(@class,' topic/unknown ')]" mode="dita-ot:text-only"/>
  36. <xsl:template match="*[contains(@class,' topic/foreign ')]" mode="dita-ot:text-only"/>
  37. <!-- EXCEPTIONS -->
  38. <xsl:template match="*[contains(@class,' topic/image ')]" mode="dita-ot:text-only">
  39. <xsl:choose>
  40. <xsl:when test="*[contains(@class,' topic/alt ')]"><xsl:apply-templates mode="dita-ot:text-only"/></xsl:when>
  41. <xsl:when test="@alt"><xsl:value-of select="@alt"/></xsl:when>
  42. </xsl:choose>
  43. </xsl:template>
  44. <!-- Footnote as text-only: should just create the number in parens -->
  45. <xsl:template match="*[contains(@class,' topic/fn ')]" mode="dita-ot:text-only">
  46. <xsl:variable name="fnid"><xsl:number from="/" level="any"/></xsl:variable>
  47. <xsl:choose>
  48. <xsl:when test="@callout">(<xsl:value-of select="@callout"/>)</xsl:when>
  49. <xsl:otherwise>(<xsl:value-of select="$fnid"/>)</xsl:otherwise>
  50. </xsl:choose>
  51. </xsl:template>
  52. <xsl:template match="*[contains(@class,' topic/xref ')]" mode="dita-ot:text-only">
  53. <xsl:apply-templates select="node()[not(contains(@class,' topic/desc '))]" mode="dita-ot:text-only"/>
  54. </xsl:template>
  55. <xsl:template match="*[contains(@class,' topic/boolean ')]" mode="dita-ot:text-only">
  56. <xsl:value-of select="name()"/><xsl:text>: </xsl:text><xsl:value-of select="@state"/>
  57. </xsl:template>
  58. <xsl:template match="*[contains(@class,' topic/state ')]" mode="dita-ot:text-only">
  59. <xsl:value-of select="name()"/><xsl:text>: </xsl:text><xsl:value-of select="@name"/><xsl:text>=</xsl:text><xsl:value-of select="@value"/>
  60. </xsl:template>
  61. </xsl:stylesheet>