RE: [xsl] Nestled <xsl:choose>

Subject: RE: [xsl] Nestled <xsl:choose>
From: "Chris Bayes" <Chris@xxxxxxxxxxx>
Date: Sat, 14 Jul 2001 17:53:47 +0100
You have the wrong idea about the xsl:apply-templates
<xsl:when test="@variant = 'Book'">
  <xsl:apply-templates select="book_type_template" />
This is saying apply templates to the element called book_type_template. As
you don't have one of those it won't work.
To get it to work as it looks like you want you should do
<xsl:call-template name="book_type_template" />

But that would be *completely* the wrong way of doing it. What you should do
is change your root template to be

<xsl:template match="/">
		<title>My Library 6-07-2001</title>
		<link rel="stylesheet" href="library.css" type="text/css" />
<br /><br />
<div align="center">
	<xsl:apply-templates />

Just let xsl do it's job and let it go off and apply templates.
Next you want to add templates that will only match the specific types of
books you have in your library i.e.

<xsl:template match="book[@variant = 'Book' and @style = 'Fiction']">
	<table cellspacing="4px">
		<tr>  <td align="center" valign="middle" rowspan="7" width="120px">
<img src="{image_link}" /></td>
			<td><b>Title:</b> <xsl:value-of select="title"/></td>
			<td><b>Author:</b><xsl:value-of select="@first_name"/>
<xsl:value-of select="@initial"/>
						<xsl:value-of select="@lastname"/>
		<tr><td><b>Description:</b><xsl:value-of select="description"/></td>
		<tr><td><b>Subject:</b><xsl:value-of select="subject"/></td>
		<tr><td><b>Style:</b><xsl:value-of select="style"/></td>
		<tr><td><b>Genre:</b><xsl:value-of select="genre"/></td>
		<tr><td><b>Publisher:</b><xsl:value-of select="publisher"/></td>

<xsl:template match="book[@variant = 'Book' and @style = 'Non-Fiction']">
<xsl:template match="book[@variant = 'Graphic_Novel' and @style =
<xsl:template match="book[@variant = 'Magazine' and @style =

That gets rid of all those horrible xsl:choose and the despicable
xsl:for-each you have liberaly scattered around.
You probably want to add a default book template to catch any books that
don't match your templates

<xsl:template match="book">
<b>Error Trapped Undefined Book Type</b>

Put this before all the other book templates so that it only matches book
types you don't have templates for. If you put it at the end it will match
all book elements.

In your root template it looks like you are trying to specify the order the
books are displayed so change the xsl:apply-templates in your root template
so that it works on book elements in order

<xsl:apply-templates select="book">
	<xsl:sort select="@variant" order="ascending" />

Simple huh?

Ciao Chris

XML/XSL Portal

>-----Original Message-----
>From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of dante
>Sent: 14 July 2001 15:45
>To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>Subject: Re: [xsl] Nestled <xsl:choose>
>Ok, I seem to misunderstand something fundimental 'bout xsl.
>I'm following the suggestions from people on this list (thanks everone) but
>I'm not achieving the result I want.
>The concept I trying for is simple:
>A xml library of my books with different html tables being output from the
>xsl stylesheet, depending on which of the following four variants
>of books -
>fiction, non-fiction, graphic novel or magazine that the xml refers to.
>Yet - I'm missing something in the execution.
>If anyone is interested could you please have a look at my xml & xslt
>documents at my site:
>            Oliver
><tip type="html">
>    To disable the Microsoft Smart Tags use:
>    <meta name="MSSmartTagsPreventParsing" content="TRUE">
> XSL-List info and archive:

 XSL-List info and archive:

Current Thread