[xslt] Re: [xml] xsl:apply-imports not passing on parameters



On Wed, 2004-07-07 at 11:36 +0200, Oliver Kiddle wrote:
> I was going to raise this as a bug until I noticed that sablotron and
> Xalan do the same. apply-imports is supposed to allow templates to be
> modified so it seems quite bad to me that parameters are not passed on
> automatically.
> 
> I've cut down the stylesheets I was using but I'll show them here to
> demonstrate what I was trying to do:
> 
> This is the main stylesheet. The default value for $style in the p
> template was actually a complex bit of xsl:choose that I wouldn't want
> to duplicate.
> 
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> 
>   <xsl:template match="p">
>     <xsl:param name="style">default</xsl:param>
> 
>     <text style="{$style}">
>       <xsl:apply-templates/>
>     </text>
>   </xsl:template>
> 
>   <xsl:template match="top">
>     <xsl:apply-templates>
>       <xsl:with-param name="style">in top</xsl:with-param>
>     </xsl:apply-templates>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 
> Now I have another stylesheet which marks up changes:
> 
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> 
>  <xsl:import href="main.xsl"/>
> 
>  <xsl:template match="*[ chg]">
>     <change-start change-id="{generate-id(.)}"/>
>     <xsl:apply-imports/>
>     <change-end change-id="{generate-id(.)}"/>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 
> For the input, try this:
> 
> <top><p chg="del">Changed paragraph</p><p>Unchanged paragraph</p></top>
> 
> If you compare the two stylesheets, with the second the overriden style
> gets lost (and becomes just "default"). This is because apply-imports
> does not pass on the $style parameter.
> 
> Given that apply-templates is described as a way to override a
> template, this really doesn't seem ideal to me. It isn't obvious that
> this will happen so it is an easy source of bugs in stylesheets.
> xsltproc actually lets me pass $style on with a with-param inside
> apply-imports but I think that isn't proper XSLT 1.0.
> 
> This will be even more unexpected with XSLT 2.0's xsl:next-match. Do
> you agree with me that this is not ideal? Should I be mentioning this
> to someone at w3.org? If so, who? 
> 
> Oliver

The correct list for this is xslt gnome org   I'm CCing both the XML and
XSLT mailing lists so the reply is in the archives.  Followups to the
XSLT list please.

At a cursory glance through the XSLT 1.0 Recommendation, I think this is
the correct behavior.  The spec says that xsl:apply-imports processes
the current node using imported templates.  There's no mention of trying
to merge imported templates into the current template.  So the imported
template should be called exactly as if you had given it a name and
called xsl:call-template on it.  Parameters are never implicitly passed
through in XSLT (not that there haven't been times I've wanted them to).

You're correct that using xsl:with-param inside xsl:apply-imports is not
valid XSLT 1.0, which is really a damn shame.  It is, however, valid
XSLT 1.1, which never made it past Working Draft status at W3C.  There
are a few known 1.1-isms in libxslt, and this would seem to be another.

--
Shaun




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]