Modifying an attribute

This recipe demonstrates modifying an img href to use a thumbnail.

Rules

<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://namespaces.plone.org/diazo"
       xmlns:css="http://namespaces.plone.org/diazo/css"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <replace css:theme="#target" css:content="#content" />

    <xsl:template match="img/@src[not(contains(., '@@'))]">
        <xsl:attribute name="src"><xsl:value-of select="." />/@@/images/image/thumb</xsl:attribute>
    </xsl:template>

</rules>

Theme

<div id="target">
    <div>Content</div>
</div>

Content

<div id="content">
    Text
    <img src="foo.jpg" class="myimage" />
    Some more text
</div>

Output

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <body>
    <div id="content">
    Text
    <img src="foo.jpg/@@/images/image/thumb" class="myimage" />
    Some more text
</div>
  </body>
</html>