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.
-
Are you looking for XSLT only or GUI extension(with its own textbox) work for you? – Raj Kumar Jun 17 '14 at 8:35
-
Not sure what you mean by GUI extension, but I was thinking of just a cleanup XSLT – Will Price Jun 17 '14 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 '14 at 8:43
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(., ' ', '')) = '' 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>
<!-- 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() = 'td')]/@style"></xsl:template>
<xsl:template match="td/@style">
<xsl:if test="contains(.,'text-align')">
<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[.='1'] | @rowspan[.='1']"></xsl:template>
<!-- remove well known Microsoft Word classes -->
<xsl:template match="@class[.='MsoNormal'] | @class[.='MsoTableGrid']"></xsl:template>
</xsl:stylesheet>