Replacing attributes from Plone in your XDV theme

A few months ago at the Plone West Coast Sprint we started to work on a few new themes for Plone using XDV and came upon a road block:  How do you replace attributes within elements in XDV?

We wanted to replace the href tag in the logo of our theme:

<div id="logo">
  <a href="#">
     <img src="logo.png" alt="" title="Plone Theme" height="57" width="252" /></a>

with the href tag Plone dynamically generates in “portal-logo”:

<a id="portal-logo" accesskey="1" href="">
  <img src=""
       alt="" title="Plone" height="57" width="252" /></a>

Should be pretty simple, right?  Just use the <replace> rule in our rules.xml file and specify the href attribute as follows:

<replace content="//*[@id="portal-logo"]/@href" theme="//*[@id="logo"]/a"/>

WRONG. For some reason, you need to use the <prepend> rule:

<prepend content="//*[@id="portal-logo"]/@href" theme="//*[@id="logo"]/a"/>

Normally, <prepend> copies specified elements from Plone as the very first child of an element in the theme. What we found is that this is apparently only true with elements. For some reason, when the selecting attributes, XDV alters the behavior of <prepend> and it acts like <replace>.

Here’s what the output of the theme should look like with the correct XDV rule applied:

<div id="logo">
  <a href="">
  <img src="logo.png" alt="" title="Plone Theme" height="57" width="252" /></a>

Go Back

Comments (4)
  • Laurence Rowe October 27th, 2010 8:52 am

    This is a limitation of the XDV compiler, it’s only able to apply rules to elements, not attributes. It’s only really a problem when you want to drop an attribute from the theme. If I work out how to fix that I will.

    (Note that you’re actually telling XDV to replace the whole theme element with the attribute “//*[@id=”logo”]/a” you probably meant “//*[@id=”logo”]/a/@href”, though this still doesn’t work due to the limitation above.)


  • Mike Takahashi October 27th, 2010 9:14 am

    Thanks Lawrence, great to know.

    Attributes would also be useful for pulling in the classes for the body tag that Plone generates for each section.


  • Laurence Rowe October 28th, 2010 5:22 am

    Yup, there’s an example of setting the body class attribute using prepend here:


  • Peter November 16th, 2010 9:13 pm

    I really thins xdv is a stupid idea.
    It just maps one html to another html.
    I cannot believe that there is such an idea in Plone community to solve the theming problem.


What's on your mind?

Your email is never shared. Required fields are marked *