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>