1 | <?xml version="1.0"?>
|
---|
2 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
---|
3 | xmlns:xweb="xalan://com.nwalsh.xalan.Website"
|
---|
4 | xmlns:sweb="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Website"
|
---|
5 | exclude-result-prefixes="sweb xweb"
|
---|
6 | version="1.0">
|
---|
7 |
|
---|
8 | <xsl:output method="html"/>
|
---|
9 |
|
---|
10 | <xsl:param name="output-root" select="'.'"/>
|
---|
11 | <xsl:param name="dry-run" select="'0'"/>
|
---|
12 | <xsl:param name="rebuild-all" select="'0'"/>
|
---|
13 |
|
---|
14 | <xsl:template match="autolayout">
|
---|
15 | <!-- Regenerate olink database? -->
|
---|
16 | <xsl:if test="$collect.xref.targets = 'yes' or
|
---|
17 | $collect.xref.targets = 'only'">
|
---|
18 | <xsl:apply-templates select="." mode="collect.targets"/>
|
---|
19 | </xsl:if>
|
---|
20 |
|
---|
21 | <xsl:if test="$collect.xref.targets != 'only'" >
|
---|
22 | <xsl:apply-templates select="toc|notoc" mode="make"/>
|
---|
23 | </xsl:if>
|
---|
24 | </xsl:template>
|
---|
25 |
|
---|
26 | <xsl:template match="toc|tocentry|notoc" mode="make">
|
---|
27 | <xsl:call-template name="make.tocentry"/>
|
---|
28 | <xsl:apply-templates select="tocentry" mode="make"/>
|
---|
29 | </xsl:template>
|
---|
30 |
|
---|
31 | <xsl:template name="make.tocentry">
|
---|
32 | <xsl:variable name="srcFile" select="@page"/>
|
---|
33 |
|
---|
34 | <xsl:if test="@page and @href">
|
---|
35 | <xsl:message terminate="yes">
|
---|
36 | <xsl:text>Fail: tocentry has both page and href attributes.</xsl:text>
|
---|
37 | </xsl:message>
|
---|
38 | </xsl:if>
|
---|
39 |
|
---|
40 | <xsl:variable name="filename">
|
---|
41 | <xsl:choose>
|
---|
42 | <xsl:when test="@filename">
|
---|
43 | <xsl:value-of select="@filename"/>
|
---|
44 | </xsl:when>
|
---|
45 | <xsl:otherwise>index.html</xsl:otherwise>
|
---|
46 | </xsl:choose>
|
---|
47 | </xsl:variable>
|
---|
48 |
|
---|
49 | <xsl:variable name="dir">
|
---|
50 | <xsl:apply-templates select="." mode="calculate-dir"/>
|
---|
51 | </xsl:variable>
|
---|
52 |
|
---|
53 | <!--
|
---|
54 | <xsl:message>
|
---|
55 | <xsl:text>!!</xsl:text>
|
---|
56 | <xsl:value-of select="$dir"/>
|
---|
57 | <xsl:text>!!</xsl:text>
|
---|
58 | <xsl:value-of select="$filename-prefix"/>
|
---|
59 | <xsl:text>!!</xsl:text>
|
---|
60 | <xsl:value-of select="$filename"/>
|
---|
61 | </xsl:message>
|
---|
62 | -->
|
---|
63 |
|
---|
64 | <xsl:variable name="targetFile">
|
---|
65 | <xsl:value-of select="$dir"/>
|
---|
66 | <xsl:value-of select="$filename-prefix"/>
|
---|
67 | <xsl:value-of select="$filename"/>
|
---|
68 | </xsl:variable>
|
---|
69 |
|
---|
70 | <xsl:choose>
|
---|
71 | <xsl:when test="function-available('sweb:exists')">
|
---|
72 | <xsl:if test="not(@href) and not(sweb:exists($srcFile))">
|
---|
73 | <xsl:message terminate="yes">
|
---|
74 | <xsl:value-of select="$srcFile"/>
|
---|
75 | <xsl:text> does not exist.</xsl:text>
|
---|
76 | </xsl:message>
|
---|
77 | </xsl:if>
|
---|
78 | </xsl:when>
|
---|
79 | <xsl:when test="function-available('xweb:exists')">
|
---|
80 | <xsl:if test="not(@href) and not(xweb:exists($srcFile))">
|
---|
81 | <xsl:message terminate="yes">
|
---|
82 | <xsl:value-of select="$srcFile"/>
|
---|
83 | <xsl:text> does not exist.</xsl:text>
|
---|
84 | </xsl:message>
|
---|
85 | </xsl:if>
|
---|
86 | </xsl:when>
|
---|
87 | <xsl:otherwise>
|
---|
88 | <xsl:message terminate="no">
|
---|
89 | <xsl:value-of select="$srcFile"/>
|
---|
90 | </xsl:message>
|
---|
91 | </xsl:otherwise>
|
---|
92 | </xsl:choose>
|
---|
93 |
|
---|
94 | <xsl:variable name="output-file">
|
---|
95 | <xsl:choose>
|
---|
96 | <xsl:when test="@href">
|
---|
97 | <xsl:value-of select="@href"/>
|
---|
98 | </xsl:when>
|
---|
99 | <xsl:otherwise>
|
---|
100 | <xsl:value-of select="$output-root"/>
|
---|
101 | <xsl:text>/</xsl:text>
|
---|
102 | <xsl:value-of select="$targetFile"/>
|
---|
103 | </xsl:otherwise>
|
---|
104 | </xsl:choose>
|
---|
105 | </xsl:variable>
|
---|
106 |
|
---|
107 | <xsl:variable name="needsUpdate">
|
---|
108 | <xsl:choose>
|
---|
109 | <xsl:when test="@href">0</xsl:when>
|
---|
110 | <xsl:when test="function-available('sweb:needsUpdate')">
|
---|
111 | <xsl:choose>
|
---|
112 | <xsl:when test="$rebuild-all != 0
|
---|
113 | or sweb:needsUpdate($autolayout-file, $output-file)
|
---|
114 | or sweb:needsUpdate($srcFile, $output-file)">
|
---|
115 | <xsl:text>1</xsl:text>
|
---|
116 | </xsl:when>
|
---|
117 | <xsl:otherwise>0</xsl:otherwise>
|
---|
118 | </xsl:choose>
|
---|
119 | </xsl:when>
|
---|
120 | <xsl:when test="function-available('xweb:needsUpdate')">
|
---|
121 | <xsl:choose>
|
---|
122 | <xsl:when test="$rebuild-all != 0
|
---|
123 | or xweb:needsUpdate($autolayout-file, $output-file)
|
---|
124 | or xweb:needsUpdate($srcFile, $output-file)">
|
---|
125 | <xsl:text>1</xsl:text>
|
---|
126 | </xsl:when>
|
---|
127 | <xsl:otherwise>0</xsl:otherwise>
|
---|
128 | </xsl:choose>
|
---|
129 | </xsl:when>
|
---|
130 | <xsl:otherwise>1</xsl:otherwise>
|
---|
131 | </xsl:choose>
|
---|
132 | </xsl:variable>
|
---|
133 |
|
---|
134 | <xsl:choose>
|
---|
135 | <xsl:when test="$needsUpdate != 0">
|
---|
136 | <xsl:message>
|
---|
137 | <xsl:text>Update: </xsl:text>
|
---|
138 | <xsl:value-of select="$output-file"/>
|
---|
139 | <xsl:text>: </xsl:text>
|
---|
140 | <xsl:value-of select="$srcFile"/>
|
---|
141 | </xsl:message>
|
---|
142 |
|
---|
143 | <xsl:variable name="webpage" select="document($srcFile,.)"/>
|
---|
144 | <xsl:variable name="content">
|
---|
145 | <xsl:apply-templates select="$webpage/webpage"/>
|
---|
146 | </xsl:variable>
|
---|
147 |
|
---|
148 | <xsl:if test="$dry-run = 0">
|
---|
149 | <xsl:call-template name="write.chunk">
|
---|
150 | <xsl:with-param name="filename" select="$output-file"/>
|
---|
151 | <xsl:with-param name="content" select="$content"/>
|
---|
152 | </xsl:call-template>
|
---|
153 | </xsl:if>
|
---|
154 | </xsl:when>
|
---|
155 | <xsl:otherwise>
|
---|
156 | <xsl:message>
|
---|
157 | <xsl:text>Up-to-date: </xsl:text>
|
---|
158 | <xsl:value-of select="$output-file"/>
|
---|
159 | </xsl:message>
|
---|
160 | </xsl:otherwise>
|
---|
161 | </xsl:choose>
|
---|
162 | </xsl:template>
|
---|
163 |
|
---|
164 | <xsl:template match="*" mode="calculate-dir">
|
---|
165 | <xsl:choose>
|
---|
166 | <xsl:when test="@dir">
|
---|
167 | <!-- if there's a directory, use it -->
|
---|
168 | <xsl:choose>
|
---|
169 | <xsl:when test="starts-with(@dir, '/')">
|
---|
170 | <!-- if the directory on this begins with a "/", we're done... -->
|
---|
171 | <xsl:value-of select="substring-after(@dir, '/')"/>
|
---|
172 | </xsl:when>
|
---|
173 | <xsl:otherwise>
|
---|
174 | <xsl:value-of select="@dir"/>
|
---|
175 | </xsl:otherwise>
|
---|
176 | </xsl:choose>
|
---|
177 | </xsl:when>
|
---|
178 |
|
---|
179 | <xsl:when test="parent::*">
|
---|
180 | <!-- if there's a parent, try it -->
|
---|
181 | <xsl:apply-templates select="parent::*" mode="calculate-dir"/>
|
---|
182 | </xsl:when>
|
---|
183 |
|
---|
184 | <xsl:otherwise>
|
---|
185 | <!-- nop -->
|
---|
186 | </xsl:otherwise>
|
---|
187 | </xsl:choose>
|
---|
188 | </xsl:template>
|
---|
189 |
|
---|
190 | <xsl:template match="autolayout" mode="collect.targets">
|
---|
191 | <xsl:choose>
|
---|
192 | <xsl:when test="$website.database.document = ''">
|
---|
193 | <xsl:message>
|
---|
194 | Must specify a $website.database.document parameter when
|
---|
195 | $collect.xref.targets is set to 'yes' or 'only'.
|
---|
196 | The xref targets were not collected.
|
---|
197 | </xsl:message>
|
---|
198 | </xsl:when>
|
---|
199 | <xsl:otherwise>
|
---|
200 | <xsl:choose>
|
---|
201 | <xsl:when test="$website.database.document">
|
---|
202 | <xsl:call-template name="write.chunk">
|
---|
203 | <xsl:with-param name="filename"
|
---|
204 | select="$website.database.document"/>
|
---|
205 | <xsl:with-param name="method" select="'xml'"/>
|
---|
206 | <xsl:with-param name="encoding" select="'utf-8'"/>
|
---|
207 | <xsl:with-param name="omit-xml-declaration" select="'no'"/>
|
---|
208 | <xsl:with-param name="indent" select="'yes'"/>
|
---|
209 | <xsl:with-param name="quiet" select="0"/>
|
---|
210 | <xsl:with-param name="content">
|
---|
211 | <targetset>
|
---|
212 | <xsl:apply-templates select="." mode="olink.mode"/>
|
---|
213 | </targetset>
|
---|
214 | </xsl:with-param>
|
---|
215 | </xsl:call-template>
|
---|
216 | </xsl:when>
|
---|
217 | <xsl:otherwise>
|
---|
218 | <!-- Else write to standard output -->
|
---|
219 | <xsl:apply-templates select="." mode="olink.mode"/>
|
---|
220 | </xsl:otherwise>
|
---|
221 | </xsl:choose>
|
---|
222 | </xsl:otherwise>
|
---|
223 | </xsl:choose>
|
---|
224 |
|
---|
225 | </xsl:template>
|
---|
226 |
|
---|
227 | </xsl:stylesheet>
|
---|