This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Nestled Template Surrealism
- To: "dante" <dante at vianet dot net dot au>
- Subject: Re: [xsl] Nestled Template Surrealism
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Fri, 20 Jul 2001 16:39:43 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <OF03C7FA0C.4D794053-ON86256A8F.004CA29E@mmm.com><01db01c11126$bb933220$fd01a8c0@dante>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Oliver,
> I've created individual templates for each element in my xml
> document, with these nestled within several book[test] templates.
> Somewhere along the line I've made a mistake & now the document
> fails to display at all.
> What the problem is escapes me completely.
I think the root of your problem here is that you never apply
templates to the book elements. You need to have something like:
<div align="center">
<xsl:apply-templates />
</div>
where at the moment you have a commented-out xsl:for-each.
> There is also a continuing problem getting the image_link template to
> process properly.
Your image_link template looks like:
<xsl:template match="image_link">
<table>
<tr>
<td>
<img>
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="image_link != ''">
<xsl:value-of select="image_link" />
</xsl:when>
<xsl:otherwise>null.gif</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</img>
</td>
</tr>
</table>
</xsl:template>
Aside from the fact that you're producing a table with a single row
and a single cell in it (which is a bit weird) your problem here is
that when you try to set the value of the src attribute, you're
testing whether the *current node* has an image_link child element.
In this template, the current node *is* an image_link element, so
really you want to test, and use the value of, the current node
instead. So swap 'image_link' for '.' in the template:
<xsl:template match="image_link">
...
<img>
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test=". != ''">
<xsl:value-of select="." />
</xsl:when>
<xsl:otherwise>null.gif</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</img>
...
</xsl:template>
or, equivalently:
<xsl:template match="image_link">
...
<img>
<xsl:attribute name="src">
<xsl:value-of select="." />
<xsl:if test="not(string())">null.gif</xsl:if>
</xsl:attribute>
</img>
...
</xsl:template>
or even:
<xsl:template match="image_link">
...
<img src="{concat(., substring('null.gif',
1 div not(string())))}" />
...
</xsl:template>
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list