See related question (Using XSLT within Schema to manipulate HTML output from Component)
I have added the following to the XSLT for a content field within a schema...
<template match="*[contains(@class, 'cta-button-secondary')]">
<copy>
<attribute name="href">
<value-of select="./@href"></value-of>
</attribute>
<attribute name="class">cta-button secondary</attribute>
<element name="span" namespace="http://www.w3.org/1999/xhtml">
<value-of select="."></value-of>
</element>
</copy>
</template>
This works perfectly in the W3C XSLT debugger but when I try and use it in Tridion it doesn't seem to be applying. I am aware that this should be executed when the field content is updated rather than on publish but it doesn't seem to work...
The XSLT should find any <a>
elements with a class="cta-button-secondary"
and replace the class with class="cta-button secondary"
(note: 2 classes instead of 1) and inject a <span>
element around the <a>
value.
Full XSLT:
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
<output omit-xml-declaration="yes" method="xml" cdata-section-elements="script"></output>
<template match="/ | node() | @*">
<copy>
<apply-templates select="node() | @*"></apply-templates>
</copy>
</template> <template match="*[ (self::br or self::p or self::div) and normalize-space(translate(., ' ', '')) = '' and not(@*) and not(processing-instruction()) and not(comment()) and not(*[not(self::br) or @* or * or node()]) and not(following::node()[not( (self::text() or self::br or self::p or self::div) and normalize-space(translate(., ' ', '')) = '' and not(@*) and not(processing-instruction()) and not(comment()) and not(*[not(self::br) or @* or * or node()]) )]) ]">
<!-- ignore all paragraphs and line-breaks at the end that have nothing but (non-breaking) spaces and line breaks -->
</template>
<template match="br[parent::div and not(preceding-sibling::node()) and not(following-sibling::node())]">
<!-- Chrome generates <div><br/></div>. Renders differently in different browsers. Replace it with a non-breaking space -->
<text> </text>
</template>
<template match="*[contains(@class, 'cta-button-primary')]">
<copy>
<attribute name="href">
<value-of select="./@href"></value-of>
</attribute>
<attribute name="class">cta-button primary</attribute>
<element name="span" namespace="http://www.w3.org/1999/xhtml">
<value-of select="."></value-of>
</element>
</copy>
</template>
<template match="*[contains(@class, 'cta-button-secondary')]">
<copy>
<attribute name="href">
<value-of select="./@href"></value-of>
</attribute>
<attribute name="class">cta-button secondary</attribute>
<element name="span" namespace="http://www.w3.org/1999/xhtml">
<value-of select="."></value-of>
</element>
</copy>
</template>
</stylesheet>
Full XML:
<Content xmlns="uuid:3f71252b-6e99-47f2-8906-ff4488c188a1">
<body>
<p xmlns="http://www.w3.org/1999/xhtml">Thanks to the hard work of our supporters we increased what we spent on cancer services to a record £105.9 million in 2011. That's £10 million more than in 2010.</p>
<p xmlns="http://www.w3.org/1999/xhtml">For a full breakdown of these charts, take a look at our <a href="#" class="cta-button-primary">Annual report and accounts 2011</a> or <a href="#" class="cta-button-secondary">Our 2011 achievements.</a></p>
</body>
</Content>
Any help with this would be appreciated...