I am trying to replace a particular string in the href
attribute within a Tridion RTF source. I built the following XSLT and it works without issues, when I run locally but the replacement is not working in the CME XSLT filter.
What am I missing in the below? Please note that I am using XSLT 2.0 for transformation.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output omit-xml-declaration="yes" method="xml" cdata-section-elements="script"></xsl:output>
<xsl:template match="/ | node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"></xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl: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 -->
</xsl:template>
<xsl: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 -->
<xsl:text> </xsl:text>
</xsl:template>
<!-- My Custom Replacement -->
<xsl:template match="a">
<xsl:copy>
<!-- This enables us to retain the parent attributes -->
<xsl:apply-templates select="@* | node()"></xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="a/@href">
<xsl:attribute name="href">
<xsl:value-of select="replace(.,'MYSEARCHSTRING','MYREPLACEMENTSTRING','i')"></xsl:value-of>
</xsl:attribute>
</xsl:template>
I am also aware that the same can be accomplished in numerous extensions points within Tridion (event, TBBs, URLRewrites etc.) but would like to understand why the above is not working?