[xml] xsl:apply-imports not passing on parameters
- From: Oliver Kiddle <okiddle yahoo co uk>
- To: xml gnome org
- Subject: [xml] xsl:apply-imports not passing on parameters
- Date: Wed, 07 Jul 2004 11:36:49 +0200
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
PS. I'm not subscribed to the list so please copy me in any replies.
(though, I will check the archives). Sorry if this wsn't really the
right place to post this.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]