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

Re: Nestled Template Surrealism

Subject: Re: Nestled Template Surrealism
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 20 Jul 2001 16:39:43 +0100
nestled div
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


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.