5

I have problem in SDL Tridion 2013 rich text editor for Component, since it automatically convert an iframe tag to be self-close:

from <iframe></iframe>

to <iframe/>

I have looked for other similar cases but none of the solution works for me. Technically, the way is to make sure that there is something in between the opening tag and closing tag to prevent it to self-close.

Any proposed way to solve this?

Added: my current Filtering XSLT for the Component <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="iframe"> <element name="iframe"> <apply-templates select="*"></apply-templates> </element> </template> <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 --> </template> <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 --> <text> </text> </template> </stylesheet>

3 Answers 3

2

You should check the Schema RTF field, it usually has a XSLT fillter tab. This fillter uses <xsl:copy> which I have found leaves behind self closing tags.

The portion of the xslt that does this will look similar to

<xsl:template match="/ | node() | @*">
  <xsl:copy>
     <xsl:apply-templates select="node() | @*"></xsl:apply-templates>
   </xsl:copy>
</xsl:template>

below this block of text add the block below

<xsl:template match="iframe">
   <xsl:element name="iframe">&nbsp;</xsl:element>
</xsl:template>
9
  • I tried this, but the iframe tag is still self closed. Any idea?
    – AXT
    Commented Feb 22, 2018 at 5:57
  • I have now edited the xslt to make it more specific to iframe, since you only want this for iframes, with the correct xslt you can get this done. Commented Feb 22, 2018 at 8:19
  • @AXT: Is that self-closing happening on CME Richtext Editor after you saving the component or after the publishing on the presentation side?
    – Velmurugan
    Commented Feb 22, 2018 at 8:26
  • @Velmurugan, this self-closing is happened in the RTE, you have 3 tabs of design, source, and preview, and after you put your source (in this case the iframe tag), if you change to another tab and go back to source tab, it is formatted already as self-closed.
    – AXT
    Commented Feb 22, 2018 at 10:08
  • @Headoo, does it mean that I need to replace the codes in first block to the one specifically for iframe?
    – AXT
    Commented Feb 22, 2018 at 10:10
2

There are 2 ways I can think of that you can tackle this issue:

  • Update Tidy to parse <iframe> tag as block tag. For this I suggest you check Nikoli's blog.
  • create HTML parser (some sort of C# code which can parse your HTML code and replace self closing tags with correct opening and closing tags) on publish time. Honestly, this is not the best approach, since parsing HTML is reaaaaaly tricky and hard at best, but you can identify all self-closing tags and override them. You can use regex like this to identify all self-closed tags:

String regexString = "<(?:\"[^\"]\"[\'\"]|\'[^\']\'[\'\"]|[^\'\">])+(\/\s*)>";

Please keep in mind that with this approach, your content will still have self-closed iframe tag, but its representation after publishing will be OK. Also, I would still go with option 1 if possible.

1
  • I am aware about option 1 which I can't take at the moment, because it will change all the RTF for all components to ignore any tags. I am looking for a solution where I can edit and filter it on certain schema within the RTF itself using XSLT filtering.
    – AXT
    Commented Feb 22, 2018 at 5:56
-1

Alternatively, a simple workaround to fix this issue.

  • open the component and switch to the Source tab for component (not the RTF field), update as below and Save and Close Component.
<iframe src="http://www.google.com" xmlns="http://www.w3.org/1999/xhtml">&nbsp;</iframe>
1
  • this work only because this is not empty tag (because it has one empty space withing its tags). Tidy will do it. The only problem with this approach is that technically its not the same tag as empty iframe tag, so it can break your layout (with a single linespace)
    – Marko Milic
    Commented Feb 23, 2018 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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