5

I am trying to remove html markup (any html tags) from rich text field in tridion 2011 but somehow nothing is working for me. Is it achievable? If yes any examples would help me out. I tried below script and it is removing the content of the tags as well.

<xsl:template match="/">
  <xsl:apply-templates select="*"/>
 </xsl:template>

 <xsl:template match="*">
  <xsl:apply-templates select="node()"/>
 </xsl:template>
 <xsl:template match="text()">
  <xsl:value-of select="."/>
 </xsl:template>
  • It would have been great if you have shared what all you have done. May be just small search on this site itself for the RTF keyword might have give you the answer. Would you like to visit this Question on this site and various answers provided there: How-to-restrict-html-tags-in-rtf-fields If this does not work for you, would you mind share what you really want to achieve, what all you have done and what specific thing is not working with few example and we would be in better condition to help yo – Pankaj Gaur Nov 11 '13 at 6:58
  • Added more info – Guest19876 Nov 11 '13 at 7:06
  • 2
    Might I ask why you are using an RTF field in the first place, if you do not want any HTML? A multi-line text field without formatting would be more appropriate, no? – Peter Kjaer Nov 11 '13 at 9:07
  • 1
    In future they might use formatting as well. Now the problem is with copy pasted text from word document. – Guest19876 Nov 11 '13 at 9:48
  • 1
    Siva has a good approach--start with text and add the RTF option later. You can also have authors set their paste special defaults to plain text or to remove unrecognized styles. – Alvin Reyes Nov 15 '13 at 6:01
5

I am trying to remove html markup (any html tags) from rich text field in tridion 2011

In the first place, if you are trying to remove all html tags then what is the use of being the field as "Rich Text".

Follow this way:

  1. Add a text field (Example: ABC Field)
  2. Set "Height of the Text Area" as 5 Rows

With these steps, field will allow only Text (If though content authors copy pasted from word).

Later stage, if you want to allow Rich Text content on the ABC Field then follow below steps:

  1. Open the schema
  2. Select ABC field
  3. Under Field details, check the "Allow Rich Text Formatting" checkbox and select the "Accessibility Level"
  4. Save & Close the schema

Now field will transform to Rich Text field and you can start adding Rich text content.

1

If it was a normal XSLT question, I would suggest you to use something like:

<template match="/">
    <value-of select="."/>
</template>

But unfortunately the Filtering XSLT seems to be called by something and not simply applied to the field. Using the above example would simply clean out all content of the field (at least that is what it does for me).

So the best thing I could come up with was to filter out all unwanted HTML tags, using something silly like this:

<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="a | b | br | del | div | em | font | h1 | h2 | h3 | h4 | h5 | h6 | i | img | li | ol | p | strong | span | sup | table | td | th | tr | ul">
        <value-of select="."></value-of>
    </template>
</stylesheet>

Now this is no where near complete, it misses all kinds of HTML tags not even speaking of uppercase variants.

So I would have to conclude that the answer given by Siva is your best option.

  • same happened with me and hence accepting siva's answer – Guest19876 Nov 18 '13 at 9:09

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.