|
1 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
|
2 xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="exslt" > |
|
3 <xsl:param name="dict"/> <!-- the dictionary file --> |
|
4 <xsl:param name="include" select="1"/> <!-- boolean indicates if any linked abbrev files from a model file should be included. Can turn it off to avoid creating a file which linked (recursion bad) --> |
|
5 <xsl:variable name="d" select="document($dict,/)/dict/word"/> |
|
6 |
|
7 <xsl:variable name="WordCut" select="10"/> |
|
8 <xsl:variable name="Cut" select="22"/> |
|
9 <xsl:variable name="Cut2" select="25"/> |
|
10 |
|
11 <xsl:template match="*" priority="-1"><xsl:apply-templates select="*|@href"/></xsl:template> |
|
12 |
|
13 <xsl:template match="@href"> |
|
14 <xsl:apply-templates select="document(.,.)/SystemDefinition/*"/> |
|
15 </xsl:template> |
|
16 |
|
17 <xsl:template match="/*" priority="1"> |
|
18 <display-names><xsl:apply-templates select="*"/> |
|
19 </display-names> |
|
20 </xsl:template> |
|
21 |
|
22 <xsl:template match="/model/*" priority="5"/> |
|
23 <xsl:template match="/model/sysdef" priority="5"> |
|
24 <xsl:apply-templates select="@href"/> |
|
25 </xsl:template> |
|
26 <xsl:template match="/model/layout" priority="5"> |
|
27 <xsl:if test="$include"> |
|
28 <xsl:copy-of select="document(info[@type='abbrev']/@href,.)/display-names/*"/> |
|
29 </xsl:if> |
|
30 </xsl:template> |
|
31 |
|
32 <xsl:template match="*[@name]"> |
|
33 <xsl:variable name="list"> |
|
34 <xsl:call-template name="wordlist"/> |
|
35 </xsl:variable> |
|
36 <xsl:variable name="w"> |
|
37 <xsl:apply-templates select="exslt:node-set($list)/w" mode="word"/> |
|
38 </xsl:variable> |
|
39 <xsl:variable name="v"> |
|
40 <xsl:call-template name="print"> |
|
41 <xsl:with-param name="words" select="exslt:node-set($w)"/> |
|
42 </xsl:call-template> |
|
43 </xsl:variable> |
|
44 |
|
45 <xsl:variable name="txt" > |
|
46 <xsl:call-template name="breaks"> |
|
47 <xsl:with-param name="text"> |
|
48 <xsl:choose> |
|
49 <xsl:when test="string-length($v) > $Cut"> <!-- too long total, use abbreviation instead of display form, starting from the end --> |
|
50 <xsl:variable name="w2"> |
|
51 <xsl:apply-templates select="exslt:node-set($w)/w[last()]" mode="pass2"/> |
|
52 </xsl:variable> |
|
53 <xsl:variable name="v2"> |
|
54 <xsl:call-template name="print"> |
|
55 <xsl:with-param name="words" select="exslt:node-set($w2)"/> |
|
56 </xsl:call-template> |
|
57 </xsl:variable> |
|
58 <xsl:choose> |
|
59 <xsl:when test="string-length($v2) > $Cut2"> |
|
60 <xsl:variable name="w3"> |
|
61 <xsl:apply-templates select="exslt:node-set($w2)/w[last()]" mode="pass2"> |
|
62 <xsl:with-param name="at">s</xsl:with-param> |
|
63 </xsl:apply-templates> |
|
64 </xsl:variable> |
|
65 <xsl:call-template name="print"> |
|
66 <xsl:with-param name="words" select="exslt:node-set($w3)"/> |
|
67 </xsl:call-template> |
|
68 </xsl:when> |
|
69 <xsl:otherwise> |
|
70 <xsl:value-of select="$v2"/> |
|
71 </xsl:otherwise> |
|
72 </xsl:choose> |
|
73 </xsl:when> |
|
74 <xsl:when test="$v != '' and $v != @name"> |
|
75 <xsl:value-of select="$v"/> |
|
76 </xsl:when> |
|
77 </xsl:choose> |
|
78 </xsl:with-param> |
|
79 </xsl:call-template> |
|
80 </xsl:variable> |
|
81 |
|
82 <xsl:if test="$txt != '' and $txt != @name"> |
|
83 <abbrev name="{@name}" abbrev="{$txt}"/> |
|
84 </xsl:if> |
|
85 |
|
86 <xsl:apply-templates select="@href|*"/> |
|
87 </xsl:template> |
|
88 |
|
89 <xsl:template name="print"> |
|
90 <xsl:param name="words"/> |
|
91 <xsl:apply-templates select="$words/w" mode="print"/> |
|
92 </xsl:template> |
|
93 |
|
94 |
|
95 |
|
96 <xsl:template mode="print" match="w"> |
|
97 <xsl:value-of select="@use"/> |
|
98 <xsl:if test="not(@use)"> |
|
99 <xsl:value-of select="."/> |
|
100 </xsl:if> |
|
101 <xsl:if test="following-sibling::w"> |
|
102 <xsl:text> </xsl:text> |
|
103 </xsl:if> |
|
104 </xsl:template> |
|
105 |
|
106 |
|
107 <xsl:template match="layer" priority="2"><!-- don't abbreviate layer names --> |
|
108 <xsl:apply-templates select="*"/> |
|
109 </xsl:template> |
|
110 |
|
111 <xsl:template mode="word" match="w"> |
|
112 <xsl:variable name="match" select="$d[@term=current()]"/> |
|
113 <xsl:copy> |
|
114 <xsl:choose> |
|
115 <xsl:when test="(string-length(.) > $WordCut) and $match/@abbrev"> |
|
116 <xsl:attribute name="use"> |
|
117 <xsl:value-of select="$match/@abbrev"/> |
|
118 </xsl:attribute> |
|
119 </xsl:when> |
|
120 <xsl:when test="$match/@d"> |
|
121 <xsl:attribute name="use"> |
|
122 <xsl:value-of select="$match/@d"/> |
|
123 </xsl:attribute> |
|
124 </xsl:when> |
|
125 </xsl:choose> |
|
126 <xsl:value-of select="."/> |
|
127 </xsl:copy> |
|
128 </xsl:template> |
|
129 |
|
130 |
|
131 |
|
132 <xsl:template name="wordlist"> |
|
133 <xsl:param name="words" select="normalize-space(@name)"/> |
|
134 <w> |
|
135 <xsl:choose> |
|
136 <xsl:when test="contains($words,' ')"> |
|
137 <xsl:value-of select="substring-before($words,' ')"/> |
|
138 </xsl:when> |
|
139 <xsl:otherwise> |
|
140 <xsl:value-of select="$words"/> |
|
141 </xsl:otherwise> |
|
142 </xsl:choose> |
|
143 </w> |
|
144 <xsl:if test="contains($words,' ')"> |
|
145 <xsl:call-template name="wordlist"> |
|
146 <xsl:with-param name="words" select="substring-after($words,' ')"/> |
|
147 </xsl:call-template> |
|
148 </xsl:if> |
|
149 </xsl:template> |
|
150 |
|
151 |
|
152 <xsl:template match="w" mode="pass2"> <!-- 2nd pass --> |
|
153 <xsl:param name="len" select="0"/> |
|
154 <xsl:param name="at">abbrev</xsl:param> |
|
155 <xsl:variable name="match" select="$d[@term=current()]"/> |
|
156 <xsl:variable name="cur"> |
|
157 <xsl:copy> |
|
158 <xsl:choose> |
|
159 <xsl:when test="$match/@*[name()=$at]"> |
|
160 <xsl:attribute name="use"> |
|
161 <xsl:value-of select="$match/@*[name()=$at]"/> |
|
162 </xsl:attribute> |
|
163 </xsl:when> |
|
164 <xsl:otherwise> |
|
165 <xsl:copy-of select="@use"/> |
|
166 </xsl:otherwise> |
|
167 </xsl:choose> |
|
168 <xsl:value-of select="."/> |
|
169 </xsl:copy> |
|
170 </xsl:variable> |
|
171 |
|
172 <xsl:variable name="mytxt"> |
|
173 <xsl:value-of select="exslt:node-set($cur)/w"/> |
|
174 </xsl:variable> |
|
175 |
|
176 <xsl:variable name="prev"> <!-- unprocessed text --> |
|
177 <xsl:apply-templates select="preceding-sibling::w" mode="print"/> |
|
178 </xsl:variable> |
|
179 <xsl:choose> |
|
180 <xsl:when test="string-length($prev) + string-length($mytxt) +$len <= $Cut"> <!-- shrunk all that's needed. just output the words --> |
|
181 <xsl:copy-of select="preceding-sibling::w"/> |
|
182 </xsl:when> |
|
183 <xsl:otherwise> |
|
184 <xsl:apply-templates select="preceding-sibling::w[1]" mode="pass2"> |
|
185 <xsl:with-param name="len" select="string-length($mytxt) +$len"/> |
|
186 <xsl:with-param name="at" select="$at"/> |
|
187 </xsl:apply-templates> |
|
188 </xsl:otherwise> |
|
189 </xsl:choose> |
|
190 <xsl:copy-of select="$cur"/> |
|
191 </xsl:template> |
|
192 |
|
193 |
|
194 <xsl:template name="breaks"><xsl:param name="text"/> |
|
195 <xsl:value-of select="$text"/> |
|
196 </xsl:template> |
|
197 |
|
198 </xsl:stylesheet> |