Chr*_*ers 6 tridion tridion-2011
我试图在组件的RTF字段中使用锚点按钮,并获得意外的行为.在设计视图中使用Chrome浏览器,我突出显示/选择<h2>My Heading</h2>我想用作锚点的标题(即),然后按下锚点按钮并输入锚点名称(即my_place).
这导致以下代码显示在我的源选项卡中:
<a name="my_place" id="myplace"/><h2>My Heading</h2>
Run Code Online (Sandbox Code Playgroud)
由于自闭<a/>标签,这会在浏览器中显示HTML时导致渲染问题.
我原本期望将以下三个HTML片段中的一个插入到HTML源代码中:
<a name="my_place" id="myplace"><h2>My Heading</h2></a>
Run Code Online (Sandbox Code Playgroud)
要么
<h2><a name="my_place" id="myplace">My Heading</a></h2>
Run Code Online (Sandbox Code Playgroud)
要么
<a name="my_place" id="myplace"><a><h2>My Heading</h2>
Run Code Online (Sandbox Code Playgroud)
还有其他人经历过这个吗?或者知道如何实现我的预期(无需手动编辑HTML).或者这是当前版本产品中的错误.
附件是我的示例XSLT模板:
<template match="a[(@name) and (count(node()) = 0)]">
<copy>
<apply-templates select="@*"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" class="hidden"> </xhtml:span>
</copy>
</template>
Run Code Online (Sandbox Code Playgroud)
这增加了一些比严格需要的更多,但由于Content Delivery方面的XML操作,我们处理了一些其他问题.
基本上它将所有空a标签与name属性匹配,并在它们之间添加一些内容以阻止它们自动关闭.在我们的例子中,我们使用XSLT发布处理所有XML,因此我们遇到了空标记一直关闭的挑战.因此,作为一个肮脏的黑客,我们现在span在空标签之间插入隐藏标签以防止问题.
谢谢Chris,我已经编辑了您的解决方案以满足我的要求,因此希望将来能够与任何有此问题的人分享.
注意:这会移动锚点内的文本并删除外部文本.修复了仅包含文本的锚点,而不是html.即我的解决方案修复此标记:
<p><a name="anchor1" id="anchor1"></a>Anchor text</p>
Run Code Online (Sandbox Code Playgroud)
至
<p><a name="anchor1" id="anchor1">Anchor text</a></p>
Run Code Online (Sandbox Code Playgroud)
但不是这个:
<p><a name="anchor1" id="anchor1"></a><h1>Anchor text</h1></p>
Run Code Online (Sandbox Code Playgroud)
这是我的xsl.希望它能为你提供一个基础,我相信你可以轻松更新它以寻找下面的标签(我不需要这个我的解决方案).
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" method="html" cdata-section-elements="script"/>
<xsl:template match="/ | node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<!-- fixes Tridion bug when using interface button to insert anchor in rich text field -->
<!-- gets all empty anchor tags with an id and takes any following text and copies it inside anchor -->
<xsl:template match="a[(@id) and (count(node()) = 0)]">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:value-of select="normalize-space(following-sibling::text())"/>
</xsl:copy>
</xsl:template>
<!-- delete any text after an empty anchor (template above has already copied this text inside the anchor) -->
<xsl:template match="text()[preceding-sibling::a[(@id) and (count(node()) = 0)]]" ></xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
这是我的测试XML
<?xml version ="1.0"?>
<?xml-stylesheet type="text/xsl" href="tridionhtmlfield.xsl"?>
<html>
<head></head>
<body>
<p><a id="anchorlink" name="anchorlink" title="Anchor link" href="#Anchor">Anchor link</a>Some text after</p>
<p><a name="broken-with-html-name" id="broken-with-html-id"></a><h1>Anchor - broken with html</h1></p>
<p><a name="broken-text-only-name" id="broken-text-only-id"></a>Anchor - broken text only</p>
<p><a name="broken-notext-name" id="broken-notext-id"></a></p>
<p><a name="correct-name" id="correct-id">Anchor - correctly rendered</a> Some text after</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
改造后:
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body>
<p><a id="anchorlink" name="anchorlink" title="Anchor link" href="#Anchor">Anchor link</a>Some text after</p>
<p><a name="broken-with-html-name" id="broken-with-html-id"></a><h1>Anchor - broken with html</h1></p>
<p><a name="broken-text-only-name" id="broken-text-only-id">Anchor - broken text only</a></p>
<p><a name="broken-notext-name" id="broken-notext-id"></a></p>
<p><a name="correct-name" id="correct-id">Anchor - correctly rendered</a> Some text after</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
| 归档时间: |
|
| 查看次数: |
2124 次 |
| 最近记录: |