2012-05-10 77 views
6

我正嘗試在組件的RTF字段中使用錨按鈕並獲取意外的行爲。從設計視圖中使用Chrome瀏覽器,我突出顯示/選擇我想用作錨點的標題(即<h2>My Heading</h2>),然後按錨點按鈕並輸入錨點名稱(即my_place)。使用SDL在豐富文本字段中創建錨鏈接Tridion 2011 SP1

這將導致下面的代碼顯示在我的源標籤:

<a name="my_place" id="myplace"/><h2>My Heading</h2> 

這將導致顯示在瀏覽器的HTML由於自行閉合<a/>標記時呈現的問題。

我本來期望被插入到HTML源代碼以下三個HTML片段之一:

​​

<h2><a name="my_place" id="myplace">My Heading</a></h2> 

<a name="my_place" id="myplace"><a><h2>My Heading</h2> 

有其他人遇到這種?或者知道一種實現我所期望的方式(無需手動編輯HTML)。或者這是該產品當前版本中的一個錯誤。

回答

6

附件是我的樣品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> 

這增加了更多的不是嚴格必要的,但處理我們由於對內容分發端的XML處理其他一些問題。

本質上它匹配所有空的a標籤與name屬性,並添加一些東西,以阻止它們自動關閉。在我們的例子中,我們用XSLT發佈了所有的XML,所以我們在空標籤一直關閉的時候遇到了挑戰。所以作爲一個骯髒的黑客,我們現在插入一個隱藏的span標籤之間的空標籤,以防止這個問題。

4

它看起來像一個bug克里斯。我剛剛在Chrome,Firefox和IE上確認了它。與當前的文本選擇應該被忽略是完全相反的。 (從好的一面來看,一旦你在源代碼標籤中手動修復它,一切看起來都很完美。)

我建議你向Tridion報告這個,也許通過改變你的模板或過濾器XSLT來解決它。

+0

我認爲你是正確的@Dom - 我已經修改了我的XSLT過濾器的架構來按照您的建議處理問題。我在下面添加了我的XSLT,以便其他人可以看到 –

2

這是Tridion中的一個錯誤。一個變通,我認爲(在我們特定的安裝已經實現)是做到以下幾點:

  1. 編輯FormatAreaStyles.css文件(在外表套上CMS程序文件中找到) - 以及你的CSS文件該網站使用 - 包括像這樣的類:

.hiddenanchor { width:1px; height: 1px; display: block; text-indent:-50000px; }

  1. 發佈你的CSS文件(新類),這樣它會正確地格式化錨。
  2. 然後在您要構建錨點的組件中,您將不得不:

    a。在組件中鍵入一個單詞或一系列單詞(您希望目標位於的單元),

    b。選擇該文本並將錨標籤應用於其上,

    c。然後將您創建的新類(.hiddenanchor)應用到錨點。

最後,你的「隱形」錨應該是這樣的:

<a name="anchorname" id="anchorname" class="hiddenanchor">Anchor Name</a> 

這是一個粗的變通 - 充分肯定。但它的工作。在下一個DOM對象關閉之前,您不會超鏈接/下劃線樣式。

作爲對CSS的解釋,錨在技術上必須在DOM中可見,才能正常工作並可通過錨鏈接訪問。所以「display:none」將不起作用。除了使用文本縮進方法,您還可以絕對或固定文本在屏幕上的位置。

+0

在這種情況下,這可能是一種解決辦法,但不一定是粗略的。 +1作爲快速且有用的替代技術,用於將「合併」字段類型信息(又名數據標籤)添加到富文本格式區域。 'hiddenanchor'在這裏工作,但我們可以將業務友好的名稱「模板化」到任何演示服務器所需的名稱中。或者,您可以保留一些項目可見,但根據需要設置不同的樣式。 –

+1

可能值得注意的是,在更新FormatAreaStyles.css之後,不需要在Tridion服務器上重新啓動COM +或IIS。您可能需要清除瀏覽器緩存,才能在組件格式工具欄中使用新樣式。請注意,任何空的CSS元素(例如a。ReadMore {/ ** /})也不會顯示 - 他們必須有格式設置才能顯示。 –

6

謝謝克里斯,我已經編輯了您的解決方案,以適應我的要求,因此希望在將來與任何人分享這個問題。

注意:這將移動錨內的文本並刪除文本以外的文本。修復旨在僅包含文本的錨點,而不是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> 

希望這有助於

+0

嗨喬納森,很高興這有助於你 - 請考慮使用你的SO ID來提交我們的SDL Tridion Area 51提案,以便我們可以爲Tridion提供專門的問答區域:http://area51.stackexchange.com/proposals/38335 /外表套上?引薦= eo63snjNlUWNn9xqeeO2NA2 –

相關問題