I am writing a template that “extends” templates, but it has some issues.
<xsl:template match="*[@condition]" mode="#all">
<xsl:element name="condition">
<xsl:attribute name="name">
<xsl:value-of select="@condition"></xsl:value-of>
</xsl:attribute>
<xsl:apply-imports>
</xsl:apply-imports>
</xsl:element>
The problem with this is templates called using <xsl:apply-imports> are missing params.
The list of params are not known since there are many different templates that this template is trying to extend (hence the mode="#all").
Is there a good way around this?
Additional example:
Consider two final templates (read-only):
<xsl:template match="*" mode="mode1">
<param name="p1"/>
</xsl:template>
<xsl:template match="*" mode="mode2">
<param name="p2"/>
</xsl:template>
they are called somewhere (read-only):
<xsl:apply-templates mode="mode1">
<xsl:with-param name="mode1" select="$mode1"/>
</xsl:apply-templates>
<xsl:apply-templates mode="mode2">
<xsl:with-param name="mode2" select="$mode2"/>
</xsl:apply-templates>
There might be 100s of mode1, mode2, mode3, mode4 … and the names do not have a pattern.
I would like to have a global template that wraps additional info around the final templates. Something like:
<xsl:template match="*" mode="#all">
<xsl:next-match/>
</xsl:element>
The problem is the above global template does not pass the params to the templates.
If your problem is that when you call
<xsl:apply-imports>it doesn’t include the parameters passed to the current template, you can use tunnel parameters. In the template you are extending mark your parameters like this:Also, when you pass the parameters:
I also suggest using
<xsl:next-match>instead of<xsl:apply-imports>.