|
Subject: RE: [xsl] Second of two consecutive call-template instructions appears to affect the first? From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Wed, 15 Mar 2006 13:03:36 -0000 |
This template:
<xsl:template name="does-image-flickr">
<xsl:choose><!-- photo is a flickr link -->
<xsl:when test="/page/images/image[@name=$name]/flickr">
<a href="{/page/images/image[@name=$name]/flickr}">
<xsl:call-template name="pass-image-params" />
contains two refences to the variable $name, which isn't in scope in this
template. If you want it to be available in this template, you need to pass
it as a parameter.
It looks as if Xalan isn't reporting this error if it occurs in a template
that isn't called. The XSLT 1.0 spec isn't very precise about which errors
are static errors and which are dynamic, so that's probably conformant: XSLT
2.0 makes it mandatory to report this as a static error.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Sebastian Tennant [mailto:sebyte@xxxxxxxxxxxxxxx]
> Sent: 15 March 2006 12:46
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Second of two consecutive call-template
> instructions appears to affect the first?
>
> "Michael Kay" <mike@xxxxxxxxxxxx> wrote:
>
> >> Regarding the problem in hand, I just don't get it.
> >
> > I suspect no-one else does either, which accounts for the
> lack of response
> > (the only answers, I think, have been wild guesses). I'd
> suggest posting the
> > complete stylesheet both with and without the offending
> lines, and telling
> > you which XSLT processor you are using. At the very least
> we can then
> > determine whether other processors report the same error.
> >
> > Michael Kay
> > http://www.saxonica.com/
>
> I'm so pleased it's not just me that thinks this is strange, *phew*,
> and you'll no doubt be pleased to hear Michael, that it isn't Saxon
> which is choking, but Xalan.
>
> I'm using:
>
> Xalan version 1.10.0
> Xerces version 2.7.0
>
> I haven't tried Saxon yet, but now I think I just might give it a
> go...
>
> The whole stylesheet is below, as requested and the offending lines
> are commented out. My original post explains the required form of the
> XML source and the exact error text I'm getting is:
>
> "XSLException Type is: XSLTProcessorException
> Message is: The variable 'name' is not defined.
>
> (file:///home/sebyte/xml/html/justonecornetto.org/xml/xsl-src/
> images.xsl,
> line 47, column 63)"
>
> sdt
>
> P.S. I tried sending it as an attachment but the list server didn't
> like it, hence here it is, no doubt all horribly wrapped :-(
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns="http://www.w3.org/1999/xhtml"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <!-- photos -->
> <xsl:template match="//photos">
> <xsl:for-each select="photo">
> <xsl:apply-templates select=".">
> <xsl:with-param name="ppos"><xsl:value-of
> select="../@ppos" /></xsl:with-param>
> <xsl:with-param name="cpos"><xsl:value-of
> select="../@cpos" /></xsl:with-param>
> <xsl:with-param name="stacked">true</xsl:with-param>
> </xsl:apply-templates>
> </xsl:for-each>
> </xsl:template>
>
> <!-- photo -->
> <xsl:template match="//photo">
> <xsl:param name="name"><xsl:value-of select="@name" /></xsl:param>
> <xsl:param name="ppos"><xsl:value-of select="@ppos" /></xsl:param>
> <xsl:param name="cpos"><xsl:value-of select="@cpos" /></xsl:param>
> <xsl:param name="caption"><xsl:value-of select="@caption"
> /></xsl:param>
> <xsl:param name="stacked" />
> <xsl:variable name="class">
> <xsl:choose><!-- photos must either be stacked or
> individual floats -->
> <xsl:when test="$stacked='true'"><xsl:value-of
> select="concat('photo stacked-',$ppos)" /></xsl:when>
> <xsl:otherwise><xsl:value-of select="concat('photo
> float-',$ppos)" /></xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <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>
>
> <xsl:template name="does-image-flickr">
> <xsl:choose><!-- photo is a flickr link -->
> <xsl:when test="/page/images/image[@name=$name]/flickr">
> <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>
>
> </xsl:stylesheet>
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Second of two consecutive, Sebastian Tennant | Thread | Re: [xsl] Second of two consecutive, Sebastian Tennant |
| Re: [xsl] Second of two consecutive, Sebastian Tennant | Date | Re: [xsl] Second of two consecutive, Sebastian Tennant |
| Month |