謝謝克里斯,我已經編輯了您的解決方案,以適應我的要求,因此希望在將來與任何人分享這個問題。
注意:這將移動錨內的文本並刪除文本以外的文本。修復旨在僅包含文本的錨點,而不是html。即 我的解決方案解決了這個標籤:
<p><a name="anchor1" id="anchor1"></a>Anchor text</p>
要
<p><a name="anchor1" id="anchor1">Anchor text</a></p>
但不是這樣的:
<p><a name="anchor1" id="anchor1"></a><h1>Anchor text</h1></p>
這裏是我的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>
這裏是我的測試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>
後變換:
<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>
希望這有助於
我認爲你是正確的@Dom - 我已經修改了我的XSLT過濾器的架構來按照您的建議處理問題。我在下面添加了我的XSLT,以便其他人可以看到 –