Subject: RE: [xsl] what am I missing? From: "Chris Bayes" <Chris@xxxxxxxxxxx> Date: Fri, 11 May 2001 23:50:37 +0100 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] what am I missing?, Chris Bayes | Thread | RE: [xsl] what am I missing?, Michael Kay |
Re: [xsl] what am I missing?, Mike Brown | Date | RE: [xsl] Display or hide headings , Chris Bayes |
Month |