Jump to content

Generate Index.html page


tombliboo

Recommended Posts

HiI'm generating the webpages for my website as per my code below, I'm having difficulty generating an Index.html page to go alongside these files, can anyone help?

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"><xsl:output method="html" indent="yes" name="html"/><xsl:template match="/"><html>	<style type="text/css">		table {		border: solid 3px #000000;}					 th,td {		border: solid 3px #000000;}	</style>				<body>					<table><th>Title</th><th>Sub Department</th><th></th>		<xsl:apply-templates select="departments"/>	</table>	</body></html>	</xsl:template>		<xsl:template match="department">		<xsl:apply-templates select="department"/>	</xsl:template>	<xsl:template match="department">		<xsl:apply-templates select="subdepartment">		<xsl:with-param name="title" select="title"/>		</xsl:apply-templates>	</xsl:template>	<xsl:template match="subdepartment">		<xsl:param name="title"/>		<xsl:variable name="subdept" select="(.)"/>		<xsl:variable name="filename" select="concat('output/',$title,' - ',.,'.html')"/>		<tr><td><xsl:value-of select="$title"/></td>		<td><xsl:value-of select="concat(.,'.html')"/></td>		<td><a href="{$filename}">select</a></td></tr>		<!-- webpages in html file -->		<xsl:result-document href="{$filename}" format="html">		<html>			<body>									  <!-- my page code sits here-->			</body>		</html>		</xsl:result-document>	</xsl:template></xsl:stylesheet>

This generates my pages in the form of:Department 1 - Sub Department 1.htmlDepartment 1 - Sub Department 2.htmlDepartment 2 - Sub Department 1.htmlDepartment 2 - Sub Department 2.html...and so on. I would like an Index which for the time being just includes hyperlinks to each page, and preferably a higher level link for each department which takes you to the first sub department within it.I'm still trying to achieve this but in the meantime any assistance is much appreciated, my current attempts fail with errors such as:Cannot write one than one result document to the same URI;Or my variables store both sub departments in the same stringBy the way I'm parsing this stylesheet through Saxon.Many thanks

Link to comment
Share on other sites

Further info, example of input xml:

<?xml version = "1.0" encoding = "UTF-8"?><departments>	<department>		<title>Department 1</title>		<subdepartment>Dept 1 Sub Dept 1</subdepartment>		<subdepartment>Dept 1 Sub Dept 2</subdepartment>	</department>	<department>		<title>Department 2</title>		<subdepartment>Dept 2 Sub Dept 1</subdepartment>		<subdepartment>Dept 2 Sub Dept 2</subdepartment>	</department>	<department>		<title>Department 3</title>		<subdepartment>Dept 3 Sub Dept 1</subdepartment>		<subdepartment>Dept 3 Sub Dept 2</subdepartment>	</department></departments>

The code I'm currently working on I have positioned immediately after the last result-document tag in my above stylessheet:

<!-- Creating the index file--><xsl:result-document href="output/index.html" format="html"><html><head><title>Index Page</title></head>	<body>	<xsl:for-each select="departments/department/subdepartment">		<xsl:variable name="varDept" select="../title"/>		<a href="'{$varDept}, - ',{.}'.html"><xsl:value-of select="concat($varDept,' - ',.,'.html')"/>		</a><br/>	</xsl:for-each>	</body></html>		</xsl:result-document>

This generates a blank index.html, only two of the sub department pages where there should be 16 (and works if I remove my Index creating code) and returns the error:Error at xsl:result-document on line 44 of copystylesheet.xslt:XTDE1490: Cannot write more than one result document to the same URI:file:/C:/websites/diecastcars/webpages/index.html at xsl:apply-templates (file:/C:/websites/diecastcars/copystylesheet.xslt#23) processing /categories/category[1]/subcategory[2] at xsl:apply-templates (file:/C:/websites/diecastcars/copystylesheet.xslt#19) processing /categories/category[1] at xsl:apply-templates (file:/C:/websites/diecastcars/copystylesheet.xslt#12) processing /categoriesTransformation failed: Run-time errors were reportedNB: line 44 is:<xsl:result-document href="output/index.html" format="html">

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...