Ninja Params Problem
This is an open discussion with 2 replies, filed under XSLT.
Search
You have to pass that parameter along with your ninja template – remember that your li
is the child of an ul
or ol
which will be handle by the general template. Something like this should work (untested):
<xsl:apply-templates select="overview/*"> <xsl:with-param name="tcolour" select="colour"/> </xsl:apply-templates> <!-- Main ninja templates --> <xsl:template match="//*"> <xsl:param name="tcolour" /> <xsl:element name="{name()}"> <xsl:apply-templates select="* | @* | text()"> <xsl:with-param name="tcolour" select="colour" /> </xsl:apply-templates> </xsl:element> </xsl:template> <xsl:template match="//@*"> <xsl:attribute name="{name(.)}"> <xsl:value-of select="." /> </xsl:attribute> </xsl:template> <!-- Special templates --> <xsl:template match="p" priority="1"> <xsl:param name="tcolour" /> <p> <xsl:attribute name="style">color:<xsl:value-of select="$tcolour"/>;</xsl:attribute> <strong> <xsl:value-of select="."/> </strong> </p> </xsl:template> <xsl:template match="li" priority="1"> <xsl:param name="tcolour" /> <li> <xsl:attribute name="style">color:<xsl:value-of select="$tcolour"/>;</xsl:attribute> <strong> <xsl:value-of select="$tcolour"/><xsl:value-of select="."/> </strong> </li> </xsl:template>
Thanks Nils, I'd thought of this late last night but hadn't worked out how to implement it until I saw your code example.
As you can see I was passing the param from the wrong place in my code.
I also found that in this one-off template that I'm currently making I was able to just use the P and LI templates on their own without the others and it also worked when the param was passed in the style of my first try above.
Thanks again,
-andy
Create an account or sign in to comment.
Hi All,
I'm having trouble sending a single param into two templates when trying to do the ninja thing on a textarea output.
If I go like this:
To this:
Only the P tags get the colour param but both P and LI get the template applied.
What's up with that?