2

I have a component with a rich text field.

In the Source tab I type the bellow html source to the rich text field.

<a><span>test<span></a>

then I switch to the Design tab and then I switch to the Source tab and My typing html source is not change.(This behavior is my desire.)

<a><span>test<span></a>

But, next

In the Source tab I type the bellow html source to the rich text field.

<a><div>test</div></a>

then I switch to the Design tab and then I switch to the Source tab and My typing html source is change.

<a>&#160;</a>
<div>test</div>

But I want to not change HTML Structure.

The configuration of rich text field is described below.

Document Type: Transitional

Accessibility Level: None

Filtering XSLT is described below.(default)

<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>
</xsl:stylesheet>

I think that the above Filtering XSLT configuration is wrong, maybe.

But I don't know where is wrong.

So, please tell me how to configurate the Filtering XSLT and limitation of rich text field (for example, <head> tag can not be used. )

  • The Rich Text Format area is not HTML but rather (as Dominic Cronin's pointed out) "XML in the XHTML namespace" (XHTML in practice). So we can't put a <div> inside an a or anchor by default. Consider a span or changing the configuration (see KB post or Nick's post). For a product perspective, see Nuno's post. – Alvin Reyes Jul 3 '14 at 18:43
1

It sounds like you're wishing for someone to write your XSLT code for you. You would get a lot more help from the community if you attempted to solve your problem and pasted your question here with code that you have tested and an explanation of the bugs you've found.

Regarding <head>, I did a simple test in my CMS (2013 Sp1) with <head>test</head> and the tags we're stripped out. As there's no way to insert a <head> tag into the RTF using the WYSIWYG tools, I think you're safe here.

1

Rich text format area fields are not only processed by the XSLT, but by Tidy (I'm not sure exactly which implementation it is, but the documentation here should give some clues.)

As it is plainly not the XSLT that is making these changes, I'd assume that Tidy is to blame. Note that the content of a rich text format area is wrapped in a <body/> element before processing (it needs a single root to be loaded into a DOM for the XSLT). I would not expect Tidy to allow a <head/> element within a <body/>, nor indeed a <div/> within an <a/>.

I don't know exactly what parameters Tidy is invoked with, but I don't think there's much you can do to influence this. (I think changing the Document Type of your RTF probably influences the parameters, but not in this regard.)

It's not always necessary to control the RTF quite so tightly. After all, it's a means of capturing input, not of specifying your output. It is very common for implementors to transform the RTF data in their templates if the required output is not close enough to the native XML format.

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.