-
Notifications
You must be signed in to change notification settings - Fork 0
/
xsl2htmlutils.xsl
175 lines (151 loc) · 6.14 KB
/
xsl2htmlutils.xsl
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
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<!--
Copyright 2006, The Regents of The University of Michigan, All Rights Reserved
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- Utility template for building an HTML form elements) -->
<xsl:template name="BuildHtmlSelect">
<xsl:param name="id"/>
<xsl:param name="class"/>
<xsl:param name="key"/>
<!-- create main "select" element -->
<xsl:element name="select">
<xsl:attribute name="name">
<xsl:value-of select="Name"/>
</xsl:attribute>
<xsl:if test="$id">
<xsl:attribute name="id">
<xsl:value-of select="$id"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$class">
<xsl:attribute name="class">
<xsl:value-of select="$class"/>
</xsl:attribute>
</xsl:if>
<!-- onchange attribute -->
<xsl:if test="$key">
<xsl:attribute name="onchange">
<xsl:value-of select="$key"/>
</xsl:attribute>
</xsl:if>
<xsl:for-each select="Option">
<!-- create "option" element -->
<xsl:element name="option">
<xsl:attribute name="value">
<xsl:value-of select="Value"/>
</xsl:attribute>
<xsl:if test="../Default=Value">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="Label"/>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
<!-- Hidden debug -->
<xsl:template name="HiddenDebug">
<xsl:if test="/MBooksTop/MBooksGlobals/CurrentCgi/Param[@name='debug']">
<xsl:element name="input">
<xsl:attribute name="type">hidden</xsl:attribute>
<xsl:attribute name="name">debug</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="/MBooksTop/MBooksGlobals/CurrentCgi/Param[@name='debug']"/>
</xsl:attribute>
</xsl:element>
</xsl:if>
</xsl:template>
<!-- HiddenVars for search form -->
<xsl:template match="HiddenVars">
<xsl:for-each select="Variable">
<xsl:element name="input">
<xsl:attribute name="type">hidden</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="./@name"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:element>
</xsl:for-each>
<xsl:if test="/MBooksTop/MBooksGlobals/CurrentCgi/Param[@name='skin']">
<xsl:element name="input">
<xsl:attribute name="type">hidden</xsl:attribute>
<xsl:attribute name="name">skin</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="/MBooksTop/MBooksGlobals/CurrentCgi/Param[@name='skin']"/>
</xsl:attribute>
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template name="ReplaceChar">
<xsl:param name="string"/>
<xsl:param name="from_char"/>
<xsl:param name="to_char"/>
<xsl:if test="contains($string, $from_char)">
<xsl:value-of select="substring-before($string, $from_char)"/>
<xsl:value-of select="$to_char"/>
<xsl:call-template name="ReplaceChar">
<xsl:with-param name="string">
<xsl:value-of select="substring-after($string, $from_char)"/>
</xsl:with-param>
<xsl:with-param name="from_char">
<xsl:value-of select="$from_char"/>
</xsl:with-param>
<xsl:with-param name="to_char">
<xsl:value-of select="$to_char"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:if test="not(contains($string, $from_char))">
<xsl:value-of select="$string" />
</xsl:if>
</xsl:template>
<xsl:template name="GetMaybeTruncatedTitle">
<xsl:param name="titleString"/>
<xsl:param name="titleFragment"/>
<xsl:param name="maxLength"/>
<xsl:choose>
<xsl:when test="string-length($titleString) < $maxLength">
<xsl:value-of select="$titleString"/>
<xsl:value-of select="concat(' ', $titleFragment)"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="nTitleString" select="concat(normalize-space($titleString), ' ')"/>
<xsl:variable name="first" select="substring-before($nTitleString, ' ')"/>
<xsl:variable name="rest" select="substring-after($nTitleString, ' ')"/>
<xsl:choose>
<xsl:when test="string-length($first) >= $maxLength">
<xsl:value-of select="concat($first,' ', '...')"/>
<xsl:value-of select="concat(' ', $titleFragment)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($first, ' ')"/>
<xsl:call-template name="GetMaybeTruncatedTitle">
<xsl:with-param name="titleString" select="$rest"/>
<xsl:with-param name="titleFragment" select="$titleFragment"/>
<xsl:with-param name="maxLength" select="$maxLength - string-length($first)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>