首页 文章

Tridion 2011 SP1 richtext XSLT中的命名空间问题,浏览器不受支持

提问于
浏览
6

我在模式(Tridion 2011 SP1)中有一个richtext字段,附带了一个基本的XSLT过滤器(默认的XSLT或自定义的XSLT,对于这个问题无关紧要) .

在IE9中,当我基于该模式创建组件时,Source选项卡中的XHTML被渲染得很好,没有任何名称空间,例如:

<p>a paragraph</p>
<p>
    <a href="http://www.sdltridion.com">a link</a>
</p>

我能够保存组件 .

但是在Firefox(16.0.2,不支持)中,命名空间在“源”选项卡中呈现:

<p xmlns="http://www.w3.org/1999/XSL/Transform">a paragraph</p>
<p xmlns="http://www.w3.org/1999/XSL/Transform">
    <a href="http://www.sdltridion.com">a link</a>
</p>

这导致以下XML验证错误:

名称空间“http://www.yme.com/GeneralContent”中的元素“段落”在名称空间“http://www.w3.org/1999/XSL/Transform”中具有无效的子元素“p” . 期望的可能元素列表:命名空间'http://www.w3.org/1999/xhtml'中的任何元素..

现在我知道这是一个不受支持的Firefox版本,但这个命名空间来自哪里? Richtext XSLT中定义的命名空间是 http://www.w3.org/1999/XSL/Transform ...

有没有人知道可能的解决方法?

这是过滤XSLT,但正如我已经说过的,它也发生在默认的XSLT上:

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
    <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()]))])]">
    </template>
    <template match="br[parent::div and not(preceding-sibling::node()) and not(following-sibling::node())]">
        <text></text>
    </template>
    <template match="table|td|tr|th|tbody|p|div|a">
        <element name="{name()}">
            <choose>
                <when test="name() =&apos;img&apos;">
                    <for-each select="@*">
                        <attribute name="{name()}">
                            <value-of select="."></value-of>
                        </attribute>
                    </for-each>
                </when>
                <otherwise>
                    <for-each select="@*">
                        <choose>
                            <when test="name() =&apos;border&apos;"></when>
                            <when test="name() =&apos;cellpadding&apos;"></when>
                            <when test="name() =&apos;cellspacing&apos;"></when>
                            <when test="name() =&apos;bgcolor&apos;"></when>
                            <when test="name() =&apos;bordercolor&apos;"></when>
                            <when test="name() =&apos;width&apos;"></when>
                            <when test="name() =&apos;height&apos;"></when>
                            <when test="name() =&apos;bordercolor&apos;"></when>
                            <when test="name() =&apos;span&apos;"></when>
                            <when test="name() =&apos;style&apos;"></when>
                            <when test="name() =&apos;class&apos;">
                                <choose>
                                    <when test=". =&apos;MsoNormal&apos;"></when>
                                    <otherwise>
                                        <attribute name="{name()}">
                                            <value-of select="."></value-of>
                                        </attribute>
                                    </otherwise>
                                </choose>
                            </when>
                            <otherwise>
                                <attribute name="{name()}">
                                    <value-of select="."></value-of>
                                </attribute>
                            </otherwise>
                        </choose>
                    </for-each>
                </otherwise>
            </choose>
            <apply-templates></apply-templates>
        </element>
    </template>
    <template match="h1">
        <element name="h2">
            <apply-templates></apply-templates>
        </element>
    </template>
    <template match="td/p">
        <apply-templates></apply-templates>
    </template>
    <template match="li/p">
        <apply-templates></apply-templates>
    </template>
    <template match="link|script|font|iframe|ilayer|layer|span|small">
        <apply-templates></apply-templates>
    </template>
</stylesheet>

2 回答

  • 6

    我相信这个问题与这篇文章有关

    Tridion 2011 - Filtering XSLT on Formatting Feature window

    看起来迁移过程(或者可能是奇怪的GUI行为)正在改变过滤XSLT,并且似乎会影响RTF字段的行为 . 基本上,在XSLT中使用命名空间和命名空间前缀的方式似乎已经改变 . 典型的XSLT使用 xsl 名称空间前缀,而新的XSLT似乎排除了前缀并使用默认名称空间 .

    我认为这是一个错误,应该提交给支持,但相关帖子中介绍了解决方法 .

  • 3

    那么你的样式表有 <stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform"> 然后 <element name="{name()}"><template match="table|td|tr|th|tbody|p|div|a"> 意味着它需要输入 p (和 table 等)元素并将它们转换为具有相同名称的元素(例如 p ),但是在XSLT命名空间中 .

    所以您可能需要的是使用前缀(即 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="table|td|tr|th|tbody|p|div|a"> )编写XSLT代码,以便XSLT命名空间不会干扰您要创建的结果元素 .

    另一方面,用 <xsl:copy> 替换_2682325也应该这样做 .

相关问题