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"
8 <xsl:output method="html"/>
10 <xsl:param name="output-root" select="'.'"/>
11 <xsl:param name="dry-run" select="'0'"/>
12 <xsl:param name="rebuild-all" select="'0'"/>
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"/>
21 <xsl:if test="$collect.xref.targets != 'only'" >
22 <xsl:apply-templates select="toc|notoc" mode="make"/>
26 <xsl:template match="toc|tocentry|notoc" mode="make">
27 <xsl:call-template name="make.tocentry"/>
28 <xsl:apply-templates select="tocentry" mode="make"/>
31 <xsl:template name="make.tocentry">
32 <xsl:variable name="srcFile" select="@page"/>
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>
40 <xsl:variable name="filename">
42 <xsl:when test="@filename">
43 <xsl:value-of select="@filename"/>
45 <xsl:otherwise>index.html</xsl:otherwise>
49 <xsl:variable name="dir">
50 <xsl:apply-templates select="." mode="calculate-dir"/>
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"/>
64 <xsl:variable name="targetFile">
65 <xsl:value-of select="$dir"/>
66 <xsl:value-of select="$filename-prefix"/>
67 <xsl:value-of select="$filename"/>
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>
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>
88 <xsl:message terminate="no">
89 <xsl:value-of select="$srcFile"/>
94 <xsl:variable name="output-file">
96 <xsl:when test="@href">
97 <xsl:value-of select="@href"/>
100 <xsl:value-of select="$output-root"/>
101 <xsl:text>/</xsl:text>
102 <xsl:value-of select="$targetFile"/>
107 <xsl:variable name="needsUpdate">
109 <xsl:when test="@href">0</xsl:when>
110 <xsl:when test="function-available('sweb:needsUpdate')">
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>
117 <xsl:otherwise>0</xsl:otherwise>
120 <xsl:when test="function-available('xweb:needsUpdate')">
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>
127 <xsl:otherwise>0</xsl:otherwise>
130 <xsl:otherwise>1</xsl:otherwise>
135 <xsl:when test="$needsUpdate != 0">
137 <xsl:text>Update: </xsl:text>
138 <xsl:value-of select="$output-file"/>
139 <xsl:text>: </xsl:text>
140 <xsl:value-of select="$srcFile"/>
143 <xsl:variable name="webpage" select="document($srcFile,.)"/>
144 <xsl:variable name="content">
145 <xsl:apply-templates select="$webpage/webpage"/>
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"/>
157 <xsl:text>Up-to-date: </xsl:text>
158 <xsl:value-of select="$output-file"/>
164 <xsl:template match="*" mode="calculate-dir">
166 <xsl:when test="@dir">
167 <!-- if there's a directory, use it -->
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, '/')"/>
174 <xsl:value-of select="@dir"/>
179 <xsl:when test="parent::*">
180 <!-- if there's a parent, try it -->
181 <xsl:apply-templates select="parent::*" mode="calculate-dir"/>
190 <xsl:template match="autolayout" mode="collect.targets">
192 <xsl:when test="$website.database.document = ''">
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.
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">
212 <xsl:apply-templates select="." mode="olink.mode"/>
218 <!-- Else write to standard output -->
219 <xsl:apply-templates select="." mode="olink.mode"/>