4 added 2236 characters in body
source | link

Filtering XSLT:

<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="*[      (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>
    <template match="*[contains(@class, &apos;cta-button-primary&apos;)]">
        <copy>
            <attribute name="href">
                <value-of select="./@href"></value-of>
            </attribute>
            <attribute name="class">cta-button primary</attribute>
            <element name="span">
                <value-of select="."></value-of>
            </element>
        </copy>
    </template>
    <template match="*[contains(@class, &apos;cta-button-secondary&apos;)]">
        <copy>
            <attribute name="href">
                <value-of select="./@href"></value-of>
            </attribute>
            <attribute name="class">cta-button secondary</attribute>
            <element name="span">
                <value-of select="."></value-of>
            </element>
        </copy>
    </template>
</stylesheet>

Filtering XSLT:

<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="*[      (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>
    <template match="*[contains(@class, &apos;cta-button-primary&apos;)]">
        <copy>
            <attribute name="href">
                <value-of select="./@href"></value-of>
            </attribute>
            <attribute name="class">cta-button primary</attribute>
            <element name="span">
                <value-of select="."></value-of>
            </element>
        </copy>
    </template>
    <template match="*[contains(@class, &apos;cta-button-secondary&apos;)]">
        <copy>
            <attribute name="href">
                <value-of select="./@href"></value-of>
            </attribute>
            <attribute name="class">cta-button secondary</attribute>
            <element name="span">
                <value-of select="."></value-of>
            </element>
        </copy>
    </template>
</stylesheet>
    Tweeted twitter.com/#!/StackTridion/status/335089781262385152
3 added 23 characters in body
source | link

I have the following mark-up in a rich text field in Tridion:

<a href="#" class="cta-button-secondary">My text</a>

I have filtering XSLT on the field that transforms the mark-up into this (splitting the class and injecting a <span>):

<a href="#" class="cta-button secondary"><span>My text</span></a>

This works as expected and renders correctly. However, if I go back into the rich text editor and add a linebreak after the link in design view, the rich text editor moves the <span> from inside the <a> to outside resulting in the following mark-up:

<span><a href="#" class="cta-button secondary">My Text</a></span>

I assume this is because the rich text editor doesn't like tags within the <a>. How can I override this behaviour so that my mark-up is not broken?

I have the following mark-up in a rich text field in Tridion:

<a href="#" class="cta-button-secondary">My text</a>

I have XSLT that transforms the mark-up into this (splitting the class and injecting a <span>):

<a href="#" class="cta-button secondary"><span>My text</span></a>

This works as expected and renders correctly. However, if I go back into the rich text editor and add a linebreak after the link in design view, the rich text editor moves the <span> from inside the <a> to outside resulting in the following mark-up:

<span><a href="#" class="cta-button secondary">My Text</a></span>

I assume this is because the rich text editor doesn't like tags within the <a>. How can I override this behaviour so that my mark-up is not broken?

I have the following mark-up in a rich text field in Tridion:

<a href="#" class="cta-button-secondary">My text</a>

I have filtering XSLT on the field that transforms the mark-up into this (splitting the class and injecting a <span>):

<a href="#" class="cta-button secondary"><span>My text</span></a>

This works as expected and renders correctly. However, if I go back into the rich text editor and add a linebreak after the link in design view, the rich text editor moves the <span> from inside the <a> to outside resulting in the following mark-up:

<span><a href="#" class="cta-button secondary">My Text</a></span>

I assume this is because the rich text editor doesn't like tags within the <a>. How can I override this behaviour so that my mark-up is not broken?

2 edited tags
| link
1
source | link