Meerdere Pagina's met XSLT 2.0

Status
Niet open voor verdere reacties.

mrWindUpBird

Nieuwe gebruiker
Lid geworden
4 jul 2008
Berichten
2
Hallo allemaal,

HelpMij met het volgende probleem. Onder mijn kort schrijven vind je listings van een XSLT, gallery_helpMij.xsl en een XML-bestand, gallery_helpMij.xml. Mijn bedoeling was om met de xsl-template uit de xml-file HTML-pagina's te genereren.

Het aantal pagina's varieert; naar gelang het aantal categorieën in gallery_helpMij.xml. De eerste pagina zal drawings.htm zijn. Deze pagina laat alle afbeeldingen zien en de categorieen waar ze zijn ingedeeld. De categorieen op deze pagina's zijn hyperlinks. Als je op één zo'n hyperlink klikt, ga je naar dezelfde XSLT gegenereerde pagina die de naam draagt van de categorie. Hierop kun je afbeeldingen zien in de bewuste categorie.

De situatie is als volgt dat alle pagina's gegenereerd worden. Zelfs alle afbeeldingen worden in drawings.htm getoond. Maar als je nu op een categorie klikt dan opent zich een pagina zonder afbeeldingen.

Ik hoop dat iemand weet wat ik fout doe.

Met vriendelijke groeten, Bas

gallery_helpMij.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="gallery_helpMij.xsl"?>
<gallery>
	<item category="landscapes">
		<picture>http://digart.img.digart.pl/data/img/10/33/miniaturki400/1712270.jpg</picture>
		<thumbnail>http://digart.img.digart.pl/data/img/10/33/miniaturki3/1712270.jpg</thumbnail>
	</item>
	<item  category="buildings">
		<picture category="buildings">http://digart.img.digart.pl/data/img/93/94/miniaturki400/1687876.jpg</picture>
		<thumbnail>http://digart.img.digart.pl/data/img/93/94/miniaturki3/1687876.jpg</thumbnail>
	</item>
	<item category="landscapes">
		<picture>http://digart.img.digart.pl/data/img/35/77/miniaturki400/1656048.jpg</picture>
		<thumbnail>http://digart.img.digart.pl/data/img/35/77/miniaturki3/1656048.jpg</thumbnail>
	</item>
	<item category="buildings">
		<picture>http://digart.img.digart.pl/data/img/29/99/miniaturki400/1818536.jpg</picture>
		<thumbnail>http://digart.img.digart.pl/data/img/29/99/miniaturki3/1818536.jpg</thumbnail>
	</item>
	<item category="buildings">
		<picture  >http://digart.img.digart.pl/data/img/72/6/miniaturki400/1882247.jpg</picture>
		<thumbnail>http://digart.img.digart.pl/data/img/72/6/miniaturki100/1882247.jpg</thumbnail>
	</item>
</gallery>

gallery_helpMij.xsl
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="html" indent="no"/>
	<!-- Page configuration variables -->
	<xsl:variable name="cellsPerRow" select="5"/>
	<!-- Key for grouping by category -->
	<xsl:key name="pictures-by-category" match="item" use="@category"/>
	<!-- Process the root node to begin the transformation-->
	<xsl:template match="/">
		<xsl:result-document href="drawings.htm">
			<html>
				<head>
					<title>Gallery</title>
					<link rel="stylesheet" href="styles.css" type="text/css"/>
					<script type="text/javascript" src="javascripts.js"/>
				</head>
				<body>
					<table width="900" bgcolor="#000000" cellspacing="0" cellpadding="0" border="0">
						<tr>
							<td width="165" align="left" valign="top">
								<table bgcolor="#000000" cellspacing="10" cellpadding="0" border="0">
									<td>
										<xsl:apply-templates select="gallery" mode="index"/>
									</td>
								</table>
							</td>
							<td width="621" align="left" valign="top">
								<table bgcolor="#000000" border="0" cellspacing="10" cellpadding="0">
									<xsl:apply-templates select="gallery"/>
								</table>
							</td>
						</tr>
					</table>
				</body>
			</html>
		</xsl:result-document>
	</xsl:template>
	<!-- Build gallery rows -->
	<xsl:template match="gallery">
		<xsl:for-each select="item [position() mod $cellsPerRow = 1]">
			<tr>
				<xsl:apply-templates select=".|following-sibling::item [position() &lt; $cellsPerRow]"/>
			</tr>
		</xsl:for-each>
	</xsl:template>
	<!-- Build gallery cells -->
	<xsl:template match="item">
		<td align="center">
			<a href="javascript:Foto('{picture}')">
				<img src="{thumbnail}" border="0" align="top"/>
			</a>
		</td>
		<xsl:if test="(position() = last()) and (position() &lt; $cellsPerRow)">
			<xsl:call-template name="FillerCells">
				<xsl:with-param name="cellCount" select="$cellsPerRow - position()"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	<!-- Show categories -->
	<xsl:template match="gallery" mode="index">
		<xsl:for-each select="item[count(. | key('pictures-by-category', @category)[1])=1]">
			<xsl:sort select="@category" order="ascending"/>
			<p>
				<a href="{@category}.htm">
					<xsl:value-of select="@category"/>
					<!--<xsl:apply-templates select="/" mode="category">-->
					<xsl:call-template name="galleryPerCategory">
						<xsl:with-param name="category" select="@category"/>
					</xsl:call-template>
					<!--</xsl:apply-templates>-->
				</a>
			</p>
		</xsl:for-each>
	</xsl:template>
	<!-- Build Gallery for each category -->
	<!--<xsl:template match="/" mode="category">-->
	<xsl:template name="galleryPerCategory">
		<xsl:param name="category"/>
		<xsl:result-document href="{$category}.htm">
			<html>
				<head>
					<title>
						<xsl:value-of select="$category"/>
					</title>
					<link rel="stylesheet" href="styles.css" type="text/css"/>
					<script type="text/javascript" src="javascripts.js"/>
				</head>
				<body>
					<table width="900" bgcolor="#000000" cellspacing="0" cellpadding="0" border="0">
						<tr>
							<td width="165" align="left" valign="top">
								<table bgcolor="#000000" cellspacing="10" cellpadding="0" border="0">
									<td>
										<p>
											<xsl:value-of select="$category"/>
										</p>
										<p>
											<a href="drawings.htm">Drawings</a>
										</p>
									</td>
								</table>
							</td>
							<td width="621" align="left" valign="top">
								<table bgcolor="#000000" border="0" cellspacing="10" cellpadding="0">
									<xsl:apply-templates select="gallery" mode="category">
									<!--<xsl:call-template name="rowPerCategory">-->
										<xsl:with-param name="category_r"><xsl:value-of select="$category"/></xsl:with-param>										 
									</xsl:apply-templates>
									<!--</xsl:call-template>-->
								</table>
							</td>
						</tr>
					</table>
				</body>
			</html>
		</xsl:result-document>
		</xsl:template>
		<!-- Build gallery rows for each category -->
		<xsl:template match="gallery" mode="category">
		<!--<xsl:template name="rowPerCategory">-->
			<xsl:param name="category_r"/>
			<xsl:for-each select="item/@category[.=$category_r] [position() mod $cellsPerRow = 1]">
			<p><xsl:value-of select="."/></p>
				<tr>
					<xsl:apply-templates select=".|following-sibling::item [position() &lt; $cellsPerRow]" mode="category"/>
				</tr>
			</xsl:for-each>
		</xsl:template>
		<!-- Build gallery cells for each category -->
		<xsl:template match="item" mode="category">
			<td align="center">
				<a href="javascript:Foto('{picture}')">
					<img src="{thumbnail}" border="0" align="top"/>
				</a>
			</td>
			<xsl:if test="(position() = last()) and (position() &lt; $cellsPerRow)">
				<xsl:call-template name="FillerCells">
					<xsl:with-param name="cellCount" select="$cellsPerRow - position()"/>
				</xsl:call-template>
			</xsl:if>
		</xsl:template>
	<!-- Fillercells -->
	<xsl:template name="FillerCells">
		<xsl:param name="cellCount"/>
		<!--<td> </td>-->
		<xsl:if test="$cellCount > 1">
			<xsl:call-template name="FillerCells">
				<xsl:with-param name="cellCount" select="$cellCount - 1"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan