2

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(., &apos; &apos;, &apos;&apos;)) = &apos;&apos;     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(., &apos; &apos;, &apos;&apos;)) = &apos;&apos;        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(.,&apos;MYSEARCHSTRING&apos;,&apos;MYREPLACEMENTSTRING&apos;,&apos;i&apos;)"></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?

3

I can't find the relevant information in the documentation but if I recall correctly the Filtering XSLT of a Schema is limited to XSLT 1.0 only.

The reason behind this is that the XSL transformation is being executed by the Microsoft XML Core Services (MSXML 4.0 SP3 for 2013 SP1, and MSXML 6.0 for Web 8, I think). MSXML versions 4.0 and 6.0 fully implement and support XSL Transformations (XSLT) Version 1.0, W3C Recommendation 16 November 1999 (see also https://msdn.microsoft.com/en-us/library/ms757858(v=vs.85).aspx#Anchor_8).

  • I would have to replace my code with XSLT 1.0. Ancient but it works :). Thanks for nudging me in the right direction. – Shiva Dec 19 '17 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.