0 users online. Create an account or sign in to join them.Users

Search

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:

    <xsl:apply-templates select="overview">
<xsl:with-param name="tcolour" select="colour"/>
</xsl:apply-templates>

To this:

<xsl:template match="overview//*">

<xsl:element name="{name()}">
    <xsl:apply-templates select="* | @* | text()"/>
</xsl:element>

</xsl:template>

<xsl:template match="overview//@*">
<xsl:attribute name="{name(.)}">
    <xsl:value-of select="."/>
    <xsl:apply-templates select="p"/>
    <xsl:apply-templates select="li"/>
</xsl:attribute>
</xsl:template>

<xsl:template match="p" priority="1">
<xsl:param name="tcolour" />

<p style="">
<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 style="">
<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>

Only the P tags get the colour param but both P and LI get the template applied.

What's up with that?

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.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details