~ubuntu-branches/ubuntu/wily/dblatex/wily

« back to all changes in this revision

Viewing changes to xsl/url.xsl

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Hoenen
  • Date: 2008-08-11 20:28:56 UTC
  • mfrom: (4.1.7 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080811202856-d2qjg24ut53mgufx
Tags: 0.2.9-3
* Improve CJK (Chinese/Japanese/Korean) support:
  + Let XSL configuration parameter cjk.font default to gkai (instead of the
    cyberbit font not included in Debian).
  + Add Suggests dependency on latex-cjk-all for the gkai fonts.
  + Fix the db2latex style not to collide with the CJKutf8.sty file.
  Thanks to W. Martin Borgert for reporting and hints.
  Closes: #482857, #492350
* Fix a name clash with TeXLive for spanish documents in native style.
  Thanks to W. Martin Borgert for reporting.  Closes: #492304
* Support underscore characters in xreflabel attributes.  Thanks to
  Sébastien Villemot for reporting.  Closes: #492959

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version='1.0'?>
 
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
 
3
 
 
4
<!--############################################################################
 
5
    XSLT Stylesheet DocBook -> LaTeX 
 
6
    ############################################################################ -->
 
7
 
 
8
<xsl:template name="nolinkurl">
 
9
  <xsl:param name="url" select="@url"/>
 
10
  <xsl:text>\nolinkurl{</xsl:text>
 
11
  <xsl:call-template name="scape-encode">
 
12
    <xsl:with-param name="string" select="$url"/>
 
13
  </xsl:call-template>
 
14
  <xsl:text>}</xsl:text>
 
15
</xsl:template>
 
16
 
 
17
<!-- The funny thing is that in table cells, it fails if the URL ends with a
 
18
     '\'. The workaround is to append a space. Moreover, the problem occurs only
 
19
     if the ending '\'s are non a multiple of 2!
 
20
-->
 
21
<xsl:template name="nolinkurl2">
 
22
  <xsl:param name="url" select="@url"/>
 
23
  <xsl:variable name="bscount">
 
24
    <xsl:call-template name="bslash-end-count">
 
25
      <xsl:with-param name="url" select="$url"/>
 
26
    </xsl:call-template>
 
27
  </xsl:variable>
 
28
  <xsl:text>\nolinkurl{</xsl:text>
 
29
  <xsl:call-template name="scape-encode">
 
30
    <xsl:with-param name="string" select="$url"/>
 
31
  </xsl:call-template>
 
32
  <xsl:if test="$bscount mod 2">
 
33
    <xsl:text> </xsl:text>
 
34
  </xsl:if>
 
35
  <xsl:text>}</xsl:text>
 
36
</xsl:template>
 
37
 
 
38
 
 
39
<!-- Count the number of '\' ending the url (only for entries) -->
 
40
<xsl:template name="bslash-end-count">
 
41
  <xsl:param name="count" select="0"/>
 
42
  <xsl:param name="url"/>
 
43
 
 
44
  <xsl:choose>
 
45
  <xsl:when test="$url = ''">
 
46
    <xsl:value-of select="$count"/>
 
47
  </xsl:when>
 
48
  <xsl:when test="substring($url,string-length($url))='\'">
 
49
    <xsl:call-template name="bslash-end-count">
 
50
      <xsl:with-param name="url" select="substring($url,1,string-length($url)-1)"/>
 
51
      <xsl:with-param name="count" select="$count + 1"/>
 
52
    </xsl:call-template>
 
53
  </xsl:when>
 
54
  <xsl:otherwise>
 
55
    <xsl:value-of select="$count"/>
 
56
  </xsl:otherwise>
 
57
  </xsl:choose>
 
58
</xsl:template>
 
59
 
 
60
 
 
61
<!-- Only URLs in table cells must be escaped (mostly because of multicolumn) -->
 
62
<xsl:template name="nolinkurl-output">
 
63
  <xsl:param name="url" select="@url"/>
 
64
  <xsl:choose>
 
65
  <xsl:when test="ancestor::entry or ancestor::revision">
 
66
    <xsl:call-template name="nolinkurl-escape">
 
67
      <xsl:with-param name="url" select="$url"/>
 
68
    </xsl:call-template>
 
69
    <!-- FIXME: do something with '&' and revision if needed -->
 
70
  </xsl:when>
 
71
  <xsl:otherwise>
 
72
    <xsl:call-template name="nolinkurl">
 
73
      <xsl:with-param name="url" select="$url"/>
 
74
    </xsl:call-template>
 
75
  </xsl:otherwise>
 
76
  </xsl:choose>
 
77
</xsl:template>
 
78
 
 
79
 
 
80
<!-- Find the first special char position in the string -->
 
81
<xsl:template name="find-first">
 
82
  <xsl:param name="string"/>
 
83
  <xsl:param name="chars" select="'#%'"/>
 
84
 
 
85
  <xsl:choose>
 
86
  <xsl:when test="$string = ''">
 
87
    <xsl:value-of select="0"/>
 
88
  </xsl:when>
 
89
  <xsl:when test="string-length($chars)=1">
 
90
    <xsl:choose>
 
91
    <xsl:when test="contains($string, $chars)">
 
92
      <xsl:value-of select="string-length(substring-before($string, $chars))"/>
 
93
    </xsl:when>
 
94
    <xsl:otherwise>
 
95
      <xsl:value-of select="string-length($string)"/>
 
96
    </xsl:otherwise>
 
97
    </xsl:choose>
 
98
  </xsl:when>
 
99
  <xsl:otherwise>
 
100
    <xsl:variable name="charset" select="substring($chars, 2)"/>
 
101
    <xsl:variable name="char" select="substring($chars, 1, 1)"/>
 
102
    <xsl:choose>
 
103
    <xsl:when test="contains($string, $char)">
 
104
      <xsl:call-template name="find-first">
 
105
        <xsl:with-param name="string" select="substring-before($string, $char)"/>
 
106
        <xsl:with-param name="chars" select="$charset"/>
 
107
      </xsl:call-template>
 
108
    </xsl:when>
 
109
    <xsl:otherwise>
 
110
      <xsl:call-template name="find-first">
 
111
        <xsl:with-param name="string" select="$string"/>
 
112
        <xsl:with-param name="chars" select="$charset"/>
 
113
      </xsl:call-template>
 
114
    </xsl:otherwise>
 
115
    </xsl:choose>
 
116
  </xsl:otherwise>
 
117
  </xsl:choose>
 
118
</xsl:template>
 
119
  
 
120
<xsl:template name="nolinkurl-escape">
 
121
  <xsl:param name="escchars"/>
 
122
  <xsl:param name="url"/>
 
123
 
 
124
  <xsl:variable name="len" select="string-length($url)"/>
 
125
 
 
126
  <xsl:variable name="pos">
 
127
    <xsl:call-template name="find-first">
 
128
      <xsl:with-param name="string" select="$url"/>
 
129
    </xsl:call-template>
 
130
  </xsl:variable>
 
131
 
 
132
  <xsl:choose>
 
133
  <xsl:when test="$pos = $len">
 
134
    <xsl:if test="$escchars != ''">
 
135
      <xsl:text>\texttt{</xsl:text>
 
136
      <xsl:value-of select="$escchars"/>
 
137
      <xsl:text>}</xsl:text>
 
138
    </xsl:if>
 
139
    <xsl:if test="$len != 0">
 
140
      <xsl:call-template name="nolinkurl2">
 
141
        <xsl:with-param name="url" select="$url"/>
 
142
      </xsl:call-template>
 
143
    </xsl:if>
 
144
  </xsl:when>
 
145
  <xsl:when test="$pos = 0">
 
146
    <xsl:call-template name="nolinkurl-escape">
 
147
      <xsl:with-param name="escchars"
 
148
                      select="concat($escchars, '\', substring($url,1,1))"/>
 
149
      <xsl:with-param name="url" select="substring($url, 2)"/>
 
150
    </xsl:call-template>
 
151
  </xsl:when>
 
152
  <xsl:otherwise>
 
153
    <xsl:if test="$escchars != ''">
 
154
      <xsl:text>\texttt{</xsl:text>
 
155
      <xsl:value-of select="$escchars"/>
 
156
      <xsl:text>}</xsl:text>
 
157
    </xsl:if>
 
158
    <xsl:call-template name="nolinkurl2">
 
159
      <xsl:with-param name="url" select="substring($url, 1, $pos)"/>
 
160
    </xsl:call-template>
 
161
    <xsl:call-template name="nolinkurl-escape">
 
162
      <xsl:with-param name="escchars"
 
163
                      select="concat('\', substring($url,$pos+1,1))"/>
 
164
      <xsl:with-param name="url" select="substring($url, $pos+2)"/>
 
165
    </xsl:call-template>
 
166
  </xsl:otherwise>
 
167
  </xsl:choose>
 
168
</xsl:template>
 
169
 
 
170
 
 
171
<!-- Template for a unit-test:
 
172
     <u>
 
173
       <nolinkurl>ab%cde%#%fg</nolinkurl>
 
174
       <nolinkurl>#ab%cde%#%fg###</nolinkurl>
 
175
       <nolinkurl>nothing special</nolinkurl>
 
176
       <entry>
 
177
         <nolinkurl>ab%cde%#%fg</nolinkurl>
 
178
         <nolinkurl>#%#ab%cde%#%fg###</nolinkurl>
 
179
         <nolinkurl>nothing special</nolinkurl>
 
180
         <nolinkurl>#########</nolinkurl>
 
181
         <nolinkurl>%%%%%%%%%</nolinkurl>
 
182
         <nolinkurl>#%#%%#%##</nolinkurl>
 
183
       </entry>
 
184
     </u>
 
185
-->
 
186
<xsl:template match="nolinkurl">
 
187
  <xsl:call-template name="nolinkurl-output">
 
188
    <xsl:with-param name="url" select="."/>
 
189
  </xsl:call-template>
 
190
</xsl:template>
 
191
 
 
192
</xsl:stylesheet>