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

Second of two consecutive call-template instructions

Subject: Second of two consecutive call-template instructions appears to affect the first?
From: Sebastian Tennant <sebyte@xxxxxxxxxxxxxxx>
Date: Tue, 14 Mar 2006 17:38:58 +0000
call template with params
Hi all,

This is a section of a stylesheet I'm working on to convert a simple
custom markup to XHTML.  The section essentially deals with a line
such as:

  <photo name="beach" ppos="right" cpos"below" caption="Wish you weren't here!" />

where 'ppos' indicates the position of the photo on the page, and
'cpos' indicates the presence of a caption as well as its position.
Details of the images themselves are included much lower down in the
XML source like so:

  <images>
  .
    <image name="beach">
      <desc>Sunny day on beach</desc>
      <width>300</width>
      <file>images/beach.jpeg</file>
      <flickr>http://static.flickr.com....</flickr>
    </image>
  .
  </images>

If a 'cpos' attribute is specified, but no 'caption' attribute, then
the caption is the description found in <desc> element.  Captions are
optional and not all of the images have flickr addresses.

Basically, my problem is this.  If I comment out the four lines I've
marked with an asterix, the stylesheet processes the source without
any problems whatsoever (and does exactly what I want).  With these
four lines present however, I get the following error at the point
indicated.

  "The variable 'name' is not defined"

This seems very strange to me, and needless to say I can't figure out
why it is.  I am simply trying to wrap an <img> element in an anchor
if the image has a flickr address and then write the caption below the
image (in the containing <div>).

Any help much, much appreciated, as always.

sdt.

  * All the variables are defined by this point in the stylesheet *

  <xsl:choose>
    <xsl:when test="$cpos!=''"><!-- there's a caption which requires a surrounding div -->
      <div class="{$class}" style="{concat('width:',/page/images/image[@name=$name]/width,'px')}">
        <xsl:call-template name="does-image-flickr" />
*       <xsl:call-template name="write-caption">
*         <xsl:with-param name="cpos"><xsl:value-of select="$cpos" /></xsl:with-param>
*         <xsl:with-param name="caption"><xsl:value-of select="$caption" /></xsl:with-param>
*       </xsl:call-template>
      </div></xsl:when>
    <xsl:otherwise><!-- or there isn't -->
      <xsl:call-template name="does-image-flickr" />
    </xsl:otherwise>
  </xsl:choose>

  <xsl:template name="does-image-flickr">
    <xsl:choose><!-- photo is a flickr link -->
      <xsl:when test="/page/images/image[@name=$name]/flickr">   <-- "The variable 'name' is not defined"
        <a href="{/page/images/image[@name=$name]/flickr}">
          <xsl:call-template name="pass-image-params" />
      </a></xsl:when>
      <xsl:otherwise><!-- or it isn't-->
      <xsl:call-template name="pass-image-params" /></xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="pass-image-params">
    <xsl:apply-templates select="/page/images/image[@name=$name]">
      <xsl:with-param name="cpos"><xsl:value-of select="$cpos" /></xsl:with-param>
      <xsl:with-param name="caption"><xsl:value-of select="$caption" /></xsl:with-param>
      <xsl:with-param name="class"><xsl:value-of select="$class" /></xsl:with-param>
    </xsl:apply-templates>
  </xsl:template>

  <!-- images -->
  <xsl:template match="//image">
    <xsl:param name="cpos" />
    <xsl:param name="caption" />
    <xsl:param name="class" />
    <xsl:element name="img">
      <xsl:attribute name="alt"><xsl:choose><!-- alt attribute defaults to desc -->
        <xsl:when test="$caption!=''"><xsl:value-of select="$caption" /></xsl:when>
        <xsl:otherwise><xsl:value-of select="desc" /></xsl:otherwise>
      </xsl:choose></xsl:attribute>
      <!-- src attribute -->
      <xsl:attribute name="src"><xsl:value-of select="file" /></xsl:attribute>
      <!-- class attribute required if no caption and hence no containing div -->
      <xsl:if test="$cpos=''">
        <xsl:attribute name="class"><xsl:value-of select="$class" /></xsl:attribute>
      </xsl:if>
    </xsl:element>
  </xsl:template>

  <xsl:template name="write-caption">
    <xsl:param name="cpos" />
    <xsl:param name="caption" />
    <xsl:if test="$cpos='below'"><br /></xsl:if>
    <xsl:if test="$cpos!=''"><!-- caption-position specified -->
      <xsl:choose><!-- but no caption specified, use desc as default -->
        <xsl:when test="$caption!=''"><xsl:value-of select="$caption" /></xsl:when>
        <xsl:otherwise><xsl:value-of select="desc" /></xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>

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.