scape.xsl coverage = 76/164 (46.34%)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>

<!--############################################################################
    XSLT Stylesheet DocBook -> LaTeX 
    ############################################################################ -->

<xsl:template match="text()">
  <xsl:call-template name="scape">
  <xsl:with-param name="string" select="."/>
  </xsl:call-template>
</xsl:template>

<xsl:template match="text()" mode="latex.verbatim">
  <xsl:value-of select="."/> 
</xsl:template>

<xsl:template name="do.slash.hyphen">
  <xsl:param name="str"/>
  <xsl:choose>
  <xsl:when test="contains($str,'/')">
    <xsl:call-template name="scape">
      <xsl:with-param name="string" select="substring-before($str,'/')"/>
    </xsl:call-template>
    <xsl:text>/\-</xsl:text>
    <xsl:call-template name="do.slash.hyphen">
      <xsl:with-param name="str" select="substring-after($str,'/')"/>
    </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
    <xsl:call-template name="scape">
      <xsl:with-param name="string" select="$str"/>
    </xsl:call-template>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="text()" mode="slash.hyphen">
  <xsl:choose>
  <xsl:when test="contains(.,'://')">
    <xsl:call-template name="scape">
      <xsl:with-param name="string">
        <xsl:value-of select="substring-before(.,'://')"/>
      </xsl:with-param>
    </xsl:call-template>
    <xsl:value-of select="'://'"/>
    <xsl:call-template name="do.slash.hyphen">
      <xsl:with-param name="str" select="substring-after(.,'://')"/>
    </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
    <xsl:call-template name="do.slash.hyphen">
      <xsl:with-param name="str" select="."/>
    </xsl:call-template>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<!-- Beware, we must replace some text in an escaped string -->
<xsl:template name="scape.index">
  <xsl:param name="string"/>
  <xsl:call-template name="scape-replace">
  <xsl:with-param name="from">@</xsl:with-param>
  <xsl:with-param name="to">"@</xsl:with-param>
  <xsl:with-param name="string">
    <xsl:call-template name="scape-replace">
    <xsl:with-param name="from">!</xsl:with-param>
    <xsl:with-param name="to">"!</xsl:with-param>
    <xsl:with-param name="string">
      <xsl:call-template name="scape-replace">
      <xsl:with-param name="from">|</xsl:with-param>
      <xsl:with-param name="to">\ensuremath{"|}</xsl:with-param>
      <xsl:with-param name="string">
        <!-- if '\{' and '\}' count is not in the same in the
             index term, latex indexing fails.
             so use a macro to avoid this side effect -->
        <xsl:call-template name="scape-replace">
        <xsl:with-param name="from">\tbleft </xsl:with-param>
        <xsl:with-param name="to">\textbraceleft{}</xsl:with-param>
        <xsl:with-param name="string">
          <xsl:call-template name="scape-replace">
          <xsl:with-param name="from">\tbright </xsl:with-param>
          <xsl:with-param name="to">\textbraceright{}</xsl:with-param>
          <xsl:with-param name="string">
            <!-- need two passes to avoid mess with macro ending with {} -->
            <xsl:call-template name="scape-replace">
            <xsl:with-param name="from">{</xsl:with-param>
            <xsl:with-param name="to">\tbleft </xsl:with-param>
            <xsl:with-param name="string">
              <xsl:call-template name="scape-replace">
              <xsl:with-param name="from">}</xsl:with-param>
              <xsl:with-param name="to">\tbright </xsl:with-param>
              <xsl:with-param name="string">
                <xsl:call-template name="scape-replace">
                <xsl:with-param name="from">"</xsl:with-param>
                <xsl:with-param name="to">""</xsl:with-param>
                <xsl:with-param name="string">
                   <xsl:call-template name="normalize-scape">
                    <xsl:with-param name="string" select="$string"/>
                  </xsl:call-template>
                </xsl:with-param>
                </xsl:call-template></xsl:with-param>
              </xsl:call-template></xsl:with-param>
            </xsl:call-template></xsl:with-param>
          </xsl:call-template></xsl:with-param>
        </xsl:call-template></xsl:with-param>
      </xsl:call-template></xsl:with-param>
    </xsl:call-template></xsl:with-param>
  </xsl:call-template>
</xsl:template>

<!-- TODO: how to scape tabs? xt plants -->
<!-- If probing is required the text is silently skipped.
     See verbatim.xsl for an overview of the verbatim environment design
     that explains the need of probing.
-->
<xsl:template match="text()" mode="latex.programlisting">
  <xsl:param name="probe" select="0"/>
  <xsl:if test="$probe = 0">
    <xsl:value-of select="."/> 
  </xsl:if>
</xsl:template>

<xsl:template name="normalize-scape" >
  <xsl:param name="string"/>
  <xsl:call-template name="scape">
    <xsl:with-param name="string" select="normalize-space($string)"/>
  </xsl:call-template>
</xsl:template>


<!-- So many lines to do so little: removing spurious blank lines
     before and after actual text, but keeping in-between blank lines.
-->
<xsl:template name="normalize-border" >
  <xsl:param name="string"/>
  <xsl:param name="step" select="'start'"/>
  <xsl:variable name="left" select="substring-before($string,'&#10;')"/>

  <xsl:choose>
  <xsl:when test="not(contains($string,'&#10;'))">
    <xsl:value-of select="$string"/>
  </xsl:when>
  <xsl:when test="$step='start'">
    <xsl:choose>
    <xsl:when test="string-length(normalize-space($left))=0">
      <xsl:call-template name="normalize-border">
        <xsl:with-param name="string" select="substring-after($string,'&#10;')"/>
        <xsl:with-param name="step" select="$step"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$left"/>
      <xsl:text>&#10;</xsl:text>
      <xsl:call-template name="normalize-border">
        <xsl:with-param name="string" select="substring-after($string,'&#10;')"/>
        <xsl:with-param name="step" select="'cont'"/>
      </xsl:call-template>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="$left"/>
    <xsl:text>&#10;</xsl:text>
    <xsl:variable name="right" select="substring-after($string,'&#10;')"/>
    <xsl:if test="string-length(normalize-space($right))!=0">
      <xsl:call-template name="normalize-border">
        <xsl:with-param name="string" select="$right"/>
        <xsl:with-param name="step" select="'cont'"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<!--  (c) David Carlisle
      replace all occurences of the character(s) `from'
      by the string `to' in the string `string'.
  -->
<xsl:template name="string-replace" >
  <xsl:param name="string"/>
  <xsl:param name="from"/>
  <xsl:param name="to"/>
  <xsl:choose>
    <xsl:when test="contains($string,$from)">
      <xsl:value-of select="substring-before($string,$from)"/>
      <xsl:value-of select="$to"/>
      <xsl:call-template name="string-replace">
        <xsl:with-param name="string" select="substring-after($string,$from)"/>
        <xsl:with-param name="from" select="$from"/>
        <xsl:with-param name="to" select="$to"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$string"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>