Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

Does anyone have a good, production proven XSLT for cleaning up pasted content in Rich Text Fields (Tridion 2013 SP1). I had a hunt around, could only find this one from Bart which may be good enough, but I wondered if anyone had any other good ones. I am particularly interested in ensuring that content copy-pasted from web pages and MS word documents is cleaned down to semantic/structural markup only.

share|improve this question
    
Are you looking for XSLT only or GUI extension(with its own textbox) work for you? –  Raj Kumar Jun 17 at 8:35
    
Not sure what you mean by GUI extension, but I was thinking of just a cleanup XSLT –  Will Price Jun 17 at 8:38
    
i mean we are using GUI extension for cleanup purpose before copying it into the RTF. so it cleanup content pasted from word or html doc. –  Raj Kumar Jun 17 at 8:43

1 Answer 1

Here is one I used a while ago (quite similair to the one before, but with a little extra ;o), it removes the font element and attributes like align, valign, border, cellpadding, cellspacing. It also removes all style attributes, unless they contain text-align, since that is what the default table editor uses to center align text in a cell.

The last bit of cleanup is removing rowspan and colspan attributes if their value is 1 (which is pointless ;o) and I remove some well know Microsoft Word classes like MsoNormal and MsoTableGrid

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.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>
    <!-- remove disallowed elements but keep its children -->
    <xsl:template match="font">
        <xsl:apply-templates></xsl:apply-templates>
    </xsl:template>
    <!-- remove disallowed attributes -->
    <xsl:template match="@align | @valign | @border | @cellpadding | @cellspacing"></xsl:template>
    <!-- remove all style attributes except those for a table cell to allow center alignment -->    
    <xsl:template match="*[not(local-name() = &apos;td&apos;)]/@style"></xsl:template>
    <xsl:template match="td/@style">
        <xsl:if test="contains(.,&apos;text-align&apos;)">
            <xsl:attribute name="style">
                <xsl:text>text-align:center;</xsl:text>
            </xsl:attribute>
        </xsl:if>
    </xsl:template>
    <!-- remove rowspan and collspan when set to 1 -->
    <xsl:template match="@colspan[.=&apos;1&apos;] | @rowspan[.=&apos;1&apos;]"></xsl:template>
    <!-- remove well known Microsoft Word classes -->
    <xsl:template match="@class[.=&apos;MsoNormal&apos;] | @class[.=&apos;MsoTableGrid&apos;]"></xsl:template>    
</xsl:stylesheet>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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