This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Nestled <xsl:choose>


Oliver,
You have the wrong idea about the xsl:apply-templates
<xsl:when test="@variant = 'Book'">
  <xsl:apply-templates select="book_type_template" />
</xsl:when>
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="/">
<html>
	<head>
		<title>My Library 6-07-2001</title>
		<link rel="stylesheet" href="library.css" type="text/css" />
	</head>
<body>
<br /><br />
<div align="center">
	<xsl:apply-templates />
</div>
</body>
</html>
</xsl:template>

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>
		</tr>
		<tr>
			<td><b>Author:</b><xsl:value-of select="@first_name"/>
<xsl:value-of select="@initial"/>
						<xsl:value-of select="@lastname"/>
			</td>
		</tr>
		<tr><td><b>Description:</b><xsl:value-of select="description"/></td>
		</tr>
		<tr><td><b>Subject:</b><xsl:value-of select="subject"/></td>
		</tr>
		<tr><td><b>Style:</b><xsl:value-of select="style"/></td>
		</tr>
		<tr><td><b>Genre:</b><xsl:value-of select="genre"/></td>
		</tr>
		<tr><td><b>Publisher:</b><xsl:value-of select="publisher"/></td>
		</tr>
	</table>

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

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>
</xsl:template>

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" />
</xsl:apply-templates>

Simple huh?

Ciao Chris

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


>-----Original Message-----
>From: owner-xsl-list@lists.mulberrytech.com
>[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of dante
>Sent: 14 July 2001 15:45
>To: xsl-list@lists.mulberrytech.com
>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:
>http://www.vianet.net.au/~dante/concepts/concepts.html
>
>Thanks,
>            Oliver
>
>
><tip type="html">
>    To disable the Microsoft Smart Tags use:
>    <meta name="MSSmartTagsPreventParsing" content="TRUE">
></tip>
>
>
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]