[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: what am I missing?

Subject: RE: what am I missing?
From: "Chris Bayes" <Chris@xxxxxxxxxxx>
Date: Fri, 11 May 2001 23:50:37 +0100
sort by name missing
Carlton,
1. You have the wrong namespace. Use
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
instead of
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/xsl/transform">
2. There is no "match" attribute on apply-templates. Use
<xsl:apply-templates select="Contact" />
instead of
<xsl:apply-templates match="Contact" />
3. Beginners rule #1 *Don't* use xsl:for-each. Especialy in this case. What
will happen is the apply-templates will cause each Contact to be formatted
as per the Contact template. You then do a xsl:for-each on book/Contact
which does nothing because there are no book children of Contact. I guess
you meant /book/Contact but then you would just get Contact squared outputs.
So remove it all together.
It looks like you want to sort on LName going by order-by="+LName">.
order-by doesn't exist in the namespace you are using. Use a sort on the
apply-templates as per the first 2 lessons in the example.

<xsl:apply-templates select="Contact">
	<xsl:sort select="LName" order="ascending" />
</xsl:apply-templates>

When you say you patterned it on my filtering example what did you do run it
through a randomiser?

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml

Original filtering stylesheet

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="column" select="'name'" />
<xsl:param name="name" select="''" />
	<xsl:template match="*|@*">
	 	<xsl:copy>
	 		<xsl:apply-templates select="@* | * | comment() |
processing-instruction() | text()"/>
	 	</xsl:copy>
	</xsl:template>
	<xsl:template match="beers">
		<html>
		<head>
			<link rel="stylesheet" type="text/css" href="filter.css" />
			<script language="javascript" src="filter.js"></script>
		</head>
		<body>
			<center><h1>Beers</h1>
			<xsl:choose>
				<xsl:when test="$name">
					<xsl:apply-templates select="beer[name=$name]" mode="single" />
				</xsl:when>
				<xsl:otherwise>
					<table width="80%" bgcolor="#FF8800">
						<tr><td class="head" onclick="sort('name');">Name</td>
						<td class="head" onclick="sort('origin');">Origin</td>
						<td class="head" onclick="sort('type');">Type</td>
						<td class="head" onclick="sort('quality');">Quality</td></tr>
						<xsl:if test="$column='name'">
							<xsl:apply-templates select="beer">
								<xsl:sort select="name" order="ascending" />
							</xsl:apply-templates>
						</xsl:if>
						<xsl:if test="$column='origin'">
							<xsl:apply-templates select="beer">
								<xsl:sort select="origin" order="ascending" />
							</xsl:apply-templates>
						</xsl:if>
						<xsl:if test="$column='type'">
							<xsl:apply-templates select="beer">
								<xsl:sort select="type" order="ascending" />
							</xsl:apply-templates>
						</xsl:if>
						<xsl:if test="$column='quality'">
							<xsl:apply-templates select="beer">
								<xsl:sort select="quality/@rating" data-type="number"
order="ascending" />
							</xsl:apply-templates>
						</xsl:if>
					</table>
				</xsl:otherwise>
			</xsl:choose>
			</center>
		</body>
		</html>
	</xsl:template>
	<xsl:template match="beer">
		<tr>
			<td>
				<xsl:attribute name="onclick">filter('<xsl:value-of select="name"
/>');</xsl:attribute>
				<u><xsl:value-of select="name" /></u></td>
			<td><xsl:value-of select="origin" /></td>
			<td><xsl:value-of select="type" /></td>
			<td align="right"><xsl:value-of select="quality/@rating" /></td>
		</tr>
	</xsl:template>
	<xsl:template match="beer" mode="single">
		<table width="80%" bgcolor="#FF8800">
			<tr>
				<td align="center" width="50%"><img src="{image}" /></td>
				<td>
					Name: <xsl:value-of select="name" /><br />
					Origin: <xsl:value-of select="origin" /><br />
					Type: <xsl:value-of select="type" /><br />
					Quality: <xsl:value-of select="quality" /><br />
				</td>
			</tr>
			<tr>
				<td colspan="2"><xsl:apply-templates select="description" /></td>
			</tr>
		</table>
		<center><a href="JavaScript:sort('name')">Back</a></center>
	</xsl:template>
</xsl:stylesheet>


<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="beer6.xsl"?>
<beers>
	<beer>
		<name>Stella Artois</name>
		<type>Lager</type>
		<origin>Belgium</origin>
		<quality>Excelent</quality>
		<rating>10</rating>
		<image>stellaartois.gif</image>
		<description>A beautiful lager. Strong, clean tasting and a joy to drink.
		Although it is better to drink canned or draught even the bottled with
it's somehow
		weeker taste is wonderful.</description>
	</beer>
.
.
.
</beers>

How could you mangle it so badly?


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.