Search

I have some code that helps produce the pagination for a blog I'm working on, but I'm getting an error I've never seen before, and I'm not entirely sure what it's trying to tell me. Anyone know how to get around it?

The error:

xsl:attribute: Cannot add attributes to an element if children have been already added to the element.

The code:

<a id="blog-newer">
    <xsl:choose>
        <xsl:when test="$url-keywords">
            <xsl:attribute name="href">?p=<xsl:value-of select="feed/pagination/@current-page - 1" />&#38;?keywords=<xsl:value-of select="$url-keywords" /></xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
            ?p=<xsl:value-of select="feed/pagination/@current-page - 1" />
        </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="feed/pagination/@current-page = 1">
        <xsl:attribute name="class">disabled</xsl:attribute>
    </xsl:if>
    Newer
</a>

The error only triggers when the last if statement resolves as true - so I'm assuming the problem is adding two attr to the same element. However they're different attributes, and I'm not sure it would be possible to do the same thing any other way? Also the error doesn't actually say that, so who knows!

Edit: As is often the case I noticed the problem as soon as I posted the question. The otherwise clause in the choose statement didn't contain the attribute declaration, so that string was being output as the child, hence the error (which although still oddly worded, now makes perfect sense).

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