common.xsl 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  4. <!-- normalized screens, courtesy of Peter Kullmann [email protected] -->
  5. <xsl:template match="screen/text()|literallayout/text()|programlisting/text()">
  6. <xsl:variable name="before" select="preceding-sibling::node()"/>
  7. <xsl:variable name="after" select="following-sibling::node()"/>
  8. <xsl:variable name="conts" select="."/>
  9. <xsl:variable name="contsl">
  10. <xsl:choose>
  11. <xsl:when test="count($before) = 0">
  12. <xsl:call-template name="remove-lf-left">
  13. <xsl:with-param name="astr" select="$conts"/>
  14. </xsl:call-template>
  15. </xsl:when>
  16. <xsl:otherwise>
  17. <xsl:value-of select="$conts"/>
  18. </xsl:otherwise>
  19. </xsl:choose>
  20. </xsl:variable>
  21. <xsl:variable name="contslr">
  22. <xsl:choose>
  23. <xsl:when test="count($after) = 0">
  24. <xsl:call-template name="remove-ws-right">
  25. <xsl:with-param name="astr" select="$contsl"/>
  26. </xsl:call-template>
  27. </xsl:when>
  28. <xsl:otherwise>
  29. <xsl:value-of select="$contsl"/>
  30. </xsl:otherwise>
  31. </xsl:choose>
  32. </xsl:variable>
  33. <xsl:value-of select="$contslr"/>
  34. </xsl:template>
  35. <!-- eats linefeeds from the left -->
  36. <xsl:template name="remove-lf-left">
  37. <xsl:param name="astr"/>
  38. <xsl:choose>
  39. <xsl:when test="starts-with($astr,'&#xA;') or
  40. starts-with($astr,'&#xD;')">
  41. <xsl:call-template name="remove-lf-left">
  42. <xsl:with-param name="astr" select="substring($astr, 2)"/>
  43. </xsl:call-template>
  44. </xsl:when>
  45. <xsl:otherwise>
  46. <xsl:value-of select="$astr"/>
  47. </xsl:otherwise>
  48. </xsl:choose>
  49. </xsl:template>
  50. <!-- eats whitespace from the right -->
  51. <xsl:template name="remove-ws-right">
  52. <xsl:param name="astr"/>
  53. <xsl:variable name="last-char">
  54. <xsl:value-of select="substring($astr, string-length($astr), 1)"/>
  55. </xsl:variable>
  56. <xsl:choose>
  57. <xsl:when test="($last-char = '&#xA;') or
  58. ($last-char = '&#xD;') or
  59. ($last-char = '&#x20;') or
  60. ($last-char = '&#x9;')">
  61. <xsl:call-template name="remove-ws-right">
  62. <xsl:with-param name="astr"
  63. select="substring($astr, 1, string-length($astr) - 1)"/>
  64. </xsl:call-template>
  65. </xsl:when>
  66. <xsl:otherwise>
  67. <xsl:value-of select="$astr"/>
  68. </xsl:otherwise>
  69. </xsl:choose>
  70. </xsl:template>
  71. </xsl:stylesheet>