home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / apache_2.2.8-win32-x86-no_ssl.msi / Data1.cab / _D53AE40DBB78D59E09B5A0C4F817858D (.txt) < prev    next >
LaTeX Document  |  2006-07-11  |  10KB  |  288 lines

  1. <?xml version="1.0"?>
  2.  Licensed to the Apache Software Foundation (ASF) under one or more
  3.  contributor license agreements.  See the NOTICE file distributed with
  4.  this work for additional information regarding copyright ownership.
  5.  The ASF licenses this file to You under the Apache License, Version 2.0
  6.  (the "License"); you may not use this file except in compliance with
  7.  the License.  You may obtain a copy of the License at
  8.      http://www.apache.org/licenses/LICENSE-2.0
  9.  Unless required by applicable law or agreed to in writing, software
  10.  distributed under the License is distributed on an "AS IS" BASIS,
  11.  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12.  See the License for the specific language governing permissions and
  13.  limitations under the License.
  14. <xsl:stylesheet version="1.0"
  15.               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  16.                   xmlns="http://www.w3.org/1999/xhtml">
  17. <!-- ==================================================================== -->
  18. <!-- Ordinary HTML that must be converted to latex                        -->
  19. <!-- ==================================================================== -->
  20. <xsl:template match="ul">
  21. <xsl:text>\begin{itemize}
  22. </xsl:text>
  23. <xsl:apply-templates/>
  24. <xsl:text>\end{itemize}
  25. </xsl:text>
  26. </xsl:template>
  27. <xsl:template match="ol">
  28. <xsl:text>\begin{enumerate}
  29. </xsl:text>
  30. <xsl:apply-templates/>
  31. <xsl:text>\end{enumerate}
  32. </xsl:text>
  33. </xsl:template>
  34. <xsl:template match="li">
  35. <xsl:text>\item </xsl:text>
  36. <xsl:apply-templates/>
  37. <xsl:text>
  38. </xsl:text>
  39. </xsl:template>
  40. <xsl:template match="dl">
  41. <xsl:text>\begin{description}
  42. </xsl:text>
  43. <xsl:apply-templates/>
  44. <xsl:text>\end{description}
  45. </xsl:text>
  46. </xsl:template>
  47. <xsl:template match="dt">
  48. <xsl:text>\item[</xsl:text><xsl:apply-templates/>
  49. <xsl:text>] </xsl:text>
  50. </xsl:template>
  51. <xsl:template match="dd">
  52. <xsl:apply-templates/>
  53. </xsl:template>
  54. <!-- Latex doesn't like successive line breaks, so replace any
  55.      sequence of two or more br separated only by white-space with
  56.      one line break followed by smallskips. -->
  57. <xsl:template match="br">
  58. <xsl:choose>
  59. <xsl:when test="name(preceding-sibling::node()[1])='br' or name(preceding-sibling::node()[1])='indent'">
  60. <xsl:text>\smallskip </xsl:text>
  61. </xsl:when>
  62. <xsl:when test="name(preceding-sibling::node()[2])='br' or name(preceding-sibling::node()[2])='indent'">
  63.   <xsl:choose>
  64.   <xsl:when test="normalize-space(preceding-sibling::node()[1])=''">
  65.     <xsl:text>\smallskip </xsl:text>
  66.   </xsl:when>
  67.   <xsl:otherwise>
  68.     <!-- Don't put a line break if we are the last thing -->
  69.     <xsl:if test="not(position()=last()) and not(position()=last()-1 and normalize-space(following-sibling::node()[1])='')">
  70.       <xsl:text>\\ </xsl:text>
  71.     </xsl:if>
  72.   </xsl:otherwise>
  73.   </xsl:choose>
  74. </xsl:when>
  75. <xsl:otherwise>
  76.     <!-- Don't put a line break if we are the last thing -->
  77.     <xsl:if test="not(position()=last()) and not(position()=last()-1 and normalize-space(following-sibling::node()[1])='')">
  78.       <xsl:text>\\ </xsl:text>
  79.     </xsl:if>
  80. </xsl:otherwise>
  81. </xsl:choose>
  82. </xsl:template>
  83. <xsl:template match="p">
  84. <xsl:apply-templates/>
  85. <xsl:text>\par
  86. </xsl:text>
  87. </xsl:template>
  88. <xsl:template match="code">
  89. <xsl:text>\texttt{</xsl:text>
  90. <xsl:apply-templates/>
  91. <xsl:text>}</xsl:text>
  92. </xsl:template>
  93. <xsl:template match="strong">
  94. <xsl:text>\textbf{</xsl:text>
  95. <xsl:apply-templates/>
  96. <xsl:text>}</xsl:text>
  97. </xsl:template>
  98. <xsl:template match="em">
  99. <xsl:text>\textit{</xsl:text>
  100. <xsl:apply-templates/>
  101. <xsl:text>}</xsl:text>
  102. </xsl:template>
  103. <!-- Value-of used here explicitly because we don't wan't latex-escaping
  104. performed.  Of course, this will conflict with html where some tags are
  105. interpreted in pre -->
  106. <xsl:template match="pre">
  107. <xsl:text>\begin{verbatim}
  108. </xsl:text>
  109. <xsl:value-of select="."/>
  110. <xsl:text>\end{verbatim}
  111. </xsl:text>
  112. </xsl:template>
  113. <xsl:template match="blockquote">
  114. <xsl:text>\begin{quotation}
  115. </xsl:text>
  116. <xsl:apply-templates/>
  117. <xsl:text>\end{quotation}
  118. </xsl:text>
  119. </xsl:template>
  120. <!-- XXX: We need to deal with table headers -->
  121. <xsl:template match="table">
  122. <xsl:variable name="table-type">
  123.   <xsl:choose>
  124.   <xsl:when test="count(tr) > 15">longtable</xsl:when>
  125.   <xsl:otherwise>tabular</xsl:otherwise>
  126.   </xsl:choose>
  127. </xsl:variable>
  128. <xsl:text>\begin{</xsl:text><xsl:value-of select="$table-type"/>
  129. <xsl:text>}{|</xsl:text>
  130. <xsl:choose>
  131. <xsl:when test="columnspec">
  132.   <xsl:for-each select="columnspec/column">
  133.     <xsl:text>l</xsl:text>
  134.     <xsl:if test="../../@border and not(position()=last())">
  135.       <xsl:text>|</xsl:text>
  136.     </xsl:if>
  137.   </xsl:for-each>
  138. </xsl:when>
  139. <xsl:otherwise>
  140.   <xsl:for-each select="tr[1]/*">
  141.     <xsl:text>l</xsl:text>
  142.     <xsl:if test="../../@border and not(position()=last())">
  143.       <xsl:text>|</xsl:text>
  144.     </xsl:if>
  145.   </xsl:for-each>
  146. </xsl:otherwise>
  147. </xsl:choose>
  148. <xsl:text>|}\hline
  149. </xsl:text>
  150. <xsl:apply-templates select="tr"/>
  151. <xsl:text>\hline\end{</xsl:text>
  152. <xsl:value-of select="$table-type"/>
  153. <xsl:text>}
  154. </xsl:text>
  155. </xsl:template>
  156. <xsl:template match="tr">
  157.   <xsl:apply-templates select="td|th"/>
  158.   <xsl:text>\\</xsl:text>
  159.   <xsl:if test="../@border and not(position()=last())">
  160.     <xsl:text>\hline</xsl:text>
  161.   </xsl:if>
  162.   <xsl:text>
  163. </xsl:text>
  164. </xsl:template>
  165. <xsl:template match="td">
  166.     <xsl:variable name="pos" select="position()"/>
  167.     <xsl:text>\begin{minipage}[t]{</xsl:text>
  168.     <xsl:choose>
  169.     <xsl:when test="../../columnspec">
  170.       <xsl:value-of select="../../columnspec/column[$pos]/@width"/>
  171.     </xsl:when>
  172.     <xsl:otherwise>
  173.       <xsl:value-of select=".95 div last()"/>
  174.     </xsl:otherwise>
  175.     </xsl:choose>
  176.     <xsl:text>\textwidth}\small </xsl:text>
  177.     <xsl:apply-templates/>
  178.     <xsl:text>\end{minipage}</xsl:text>
  179.     <xsl:if test="not(position()=last())">
  180.       <xsl:text> & </xsl:text>
  181.     </xsl:if>
  182. </xsl:template>
  183. <xsl:template match="th">
  184.     <xsl:variable name="pos" select="position()"/>
  185.     <xsl:text>\begin{minipage}[t]{</xsl:text>
  186.     <xsl:choose>
  187.     <xsl:when test="../../columnspec">
  188.       <xsl:value-of select="../../columnspec/column[$pos]/@width"/>
  189.     </xsl:when>
  190.     <xsl:otherwise>
  191.       <xsl:value-of select=".95 div last()"/>
  192.     </xsl:otherwise>
  193.     </xsl:choose>
  194.     <xsl:text>\textwidth}\bfseries </xsl:text>
  195.     <xsl:apply-templates/>
  196.     <xsl:text>\end{minipage}</xsl:text>
  197.     <xsl:if test="not(position()=last())">
  198.       <xsl:text> & </xsl:text>
  199.     </xsl:if>
  200. </xsl:template>
  201.    This is a horrible hack, but it seems to mostly work.  It does a
  202.    few things:
  203.    1. Transforms references starting in http:// to footnotes with the
  204.       appropriate hyperref macro to make them clickable.  (This needs
  205.       to be expanded to deal with news: and needs to be adjusted to
  206.       deal with "#", which is creating bad links at the moment.)
  207.    2. For intra-document references, constructs the appropriate absolute
  208.       reference using a latex \pageref.  
  209.       This involves applying a simplified version of the
  210.       general URL resolution rules to deal with ../.  It only works for
  211.       one level of subdirectory.
  212.    3. It is also necessary to deal with the fact that index pages
  213.       get references as "/".
  214. <xsl:template match="a">
  215. <xsl:apply-templates/>
  216. <xsl:if test="@href">
  217. <xsl:variable name="relpath" select="document(/*/@metafile)/metafile/relpath" />
  218. <xsl:variable name="path" select="document(/*/@metafile)/metafile/path" />
  219. <xsl:variable name="fileref">
  220.   <xsl:choose>
  221.   <xsl:when test="contains(@href, '.html')">
  222.     <xsl:value-of select="substring-before(@href, '.html')"/>
  223.   </xsl:when>
  224.   <xsl:otherwise>
  225.     <xsl:value-of select="concat(@href, 'index')"/>
  226.   </xsl:otherwise>
  227.   </xsl:choose>
  228. </xsl:variable>
  229. <xsl:choose>
  230. <xsl:when test="starts-with(@href, 'http:') or starts-with(@href, 'news:') or starts-with(@href, 'mailto:')">
  231.   <xsl:if test="not(.=@href)">
  232.     <xsl:text>\footnote{</xsl:text>
  233.       <xsl:text>\href{</xsl:text>
  234.       <xsl:call-template name="replace-string">
  235.         <xsl:with-param name="text" select="@href"/>
  236.         <xsl:with-param name="replace" select="'#'"/>
  237.         <xsl:with-param name="with" select="'\#'"/>
  238.       </xsl:call-template>
  239.       <xsl:text>}{</xsl:text>
  240.     <xsl:call-template name="ltescape">
  241.       <xsl:with-param name="string" select="@href"/>
  242.     </xsl:call-template>
  243.     <xsl:text>}}</xsl:text>
  244.   </xsl:if>
  245. </xsl:when>
  246. <xsl:when test="starts-with(@href, '#')">
  247. <!-- Don't do inter-section references -->
  248. </xsl:when>
  249. <xsl:otherwise>
  250.   <xsl:text> (p.\ \pageref{</xsl:text>
  251.     <xsl:call-template name="replace-string">
  252.       <xsl:with-param name="replace" select="'#'"/>
  253.       <xsl:with-param name="with" select="':'"/>
  254.       <xsl:with-param name="text">
  255.       <xsl:choose>
  256.       <xsl:when test="$relpath='.'">
  257.         <xsl:value-of select="concat('/',$fileref)"/>
  258.       </xsl:when>
  259.       <xsl:otherwise>
  260.         <xsl:choose>
  261.         <xsl:when test="starts-with($fileref,'..')">
  262.           <xsl:value-of select="substring-after($fileref,'..')"/>
  263.         </xsl:when>
  264.         <xsl:otherwise>
  265.           <xsl:value-of select="concat($path,$fileref)"/>
  266.         </xsl:otherwise>
  267.         </xsl:choose>
  268.       </xsl:otherwise>
  269.       </xsl:choose>
  270.       </xsl:with-param>
  271.      </xsl:call-template>
  272.   <xsl:text>}) </xsl:text>
  273. </xsl:otherwise>
  274. </xsl:choose>
  275. </xsl:if>
  276. </xsl:template>
  277. <xsl:template match="img">
  278. <xsl:variable name="path" select="document(/*/@metafile)/metafile/path" />
  279. <xsl:text>\includegraphics{</xsl:text>
  280.       <xsl:call-template name="replace-string">
  281.         <xsl:with-param name="text" select="concat('.',$path,@src)"/>
  282.         <xsl:with-param name="replace" select="'.gif'"/>
  283.         <xsl:with-param name="with" select="''"/>
  284.       </xsl:call-template>
  285. <xsl:text>}</xsl:text>
  286. </xsl:template>
  287. </xsl:stylesheet>
  288.