2012-07-03 13 views
4

我想在一個Tridion模式中應用一些額外的過濾xslt。對RTF字段的模式源應用限制

我有一個名爲「圖像」的字段。這是一個RTF,它已被配置爲允許通過在編輯格式化功能下選擇圖像和超鏈接。

它背後的想法是在RTF中插入圖像並將其作爲RTF字段。

樣品有效的源:

1.<a title="google site" href="http://google.com"><img style="width: 141px; height: 167px;" alt="Image" title="Image" src="tcm:202-11587"/></a> 
2.<a title="Internal link" href="tcm:202-9720"><img style="width: 141px; height: 167px;" alt="Image" title="Image" src="tcm:202-11587"/></a> 

由於RTF是允許超鏈接和圖像可能有機會,用戶可以不同的格式輸入它們。 無效:

1.<a title="google site" href="http://google.com"></a> 
    <img style="width: 141px; height: 167px;" alt="Image" title="Image" src="tcm:202-11587"/> 

2.<img style="width: 141px; height: 167px;" alt="Image" title="Image" src="tcm:202-11587"/> 
<a title="google site" href="http://google.com"></a> 

3.<a title="google site" href="http://google.com"><img style="width: 141px; height: 167px;" alt="Image" title="Image" src="tcm:202-11587"/></a> 
    <a title="Internal link" href="tcm:202-9720"><img style="width: 141px; height: 167px;" alt="Image" title="Image" src="tcm:202-11587"/></a> 

規則:

1.Only one Image should be allowed and it should be hyperlink. 
2.There should be one <img> tag wrapped by one <a> tag. 
3. Multiple images are not allowed. 

我知道這可能使用事件系統來完成。但我仍然想通過應用XSLT過濾來實現。

XSLT過濾來源:

<xsd:element name="image" minOccurs="0" maxOccurs="1" type="tcmi:XHTML"> 
      <xsd:annotation> 
       <xsd:appinfo> 
        <tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml> 
        <tcm:Size xmlns:tcm="http://www.tridion.com/ContentManager/5.0">2</tcm:Size> 
        <tcm:FilterXSLT xmlns:tcm="http://www.tridion.com/ContentManager/5.0"> 
         <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()])  )])  ]"> 
           <!-- 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 name="FormattingFeatures"> 
           <FormattingFeatures xmlns="http://www.tridion.com/ContentManager/5.2/FormatArea" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
            <Doctype>Transitional</Doctype> 
            <AccessibilityLevel>0</AccessibilityLevel> 
            <DisallowedActions> 
             <Bold></Bold> 
             <Italic></Italic> 
             <Underline></Underline> 
             <Strikethrough></Strikethrough> 
             <Subscript></Subscript> 
             <Superscript></Superscript> 
             <AlignLeft></AlignLeft> 
             <Center></Center> 
             <AlignRight></AlignRight> 
             <Bullets></Bullets> 
             <Numbering></Numbering> 
             <IndentDecrease></IndentDecrease> 
             <IndentIncrease></IndentIncrease> 
             <Font></Font> 
             <Background></Background> 
             <InsertCharacter></InsertCharacter> 
             <Anchor></Anchor> 
             <Table></Table> 
             <TableWidth></TableWidth> 
             <TableHeight></TableHeight> 
             <TableCellSpacing></TableCellSpacing> 
             <TableCellPadding></TableCellPadding> 
             <TableHAlign></TableHAlign> 
             <TableBorderSize></TableBorderSize> 
             <TableBorderStyle></TableBorderStyle> 
             <TableBorderColor></TableBorderColor> 
             <TableBackground></TableBackground> 
             <TableCellWidth></TableCellWidth> 
             <TableCellHeight></TableCellHeight> 
             <TableCellHAlign></TableCellHAlign> 
             <TableCellVAlign></TableCellVAlign> 
             <TableCellBackground></TableCellBackground> 
             <HLine></HLine> 
             <SectionType></SectionType> 
             <H1></H1> 
             <H2></H2> 
             <H3></H3> 
             <H4></H4> 
             <H5></H5> 
             <H6></H6> 
             <Style></Style> 
             <Language></Language> 
             <Abbreviation></Abbreviation> 
             <CurrentElement></CurrentElement> 
            </DisallowedActions> 
            <DisallowedStyles></DisallowedStyles> 
           </FormattingFeatures> 
          </template> 
         </stylesheet> 
        </tcm:FilterXSLT> 
       </xsd:appinfo> 
      </xsd:annotation> 
     </xsd:element> 

我想知道,我是否可以通過寫一些醫藥XSLT代碼做到這一點:架構源的FilterXSLT。

任何人都可以幫助如何做到這一點。

謝謝。

+1

考慮組件鏈接作爲一種替代方法,因爲它提供了有效的模式和包裹鏈接標記控制(通過模板代碼)。 ''應該指向什麼?您可以在另一個組件,多媒體元數據或可能使用自定義鏈接類型的GUI擴展中管理超鏈接(和其他元數據)。 –

回答

4

這應該工作。它具有以下功能:

  • 在富文本
  • 如果裏面有它的「IMG」元素查找第一個「A」的元素,它保持它作爲是
  • 如果沒有,它看起來在富文本第一img元素其他任何地方,並將其移動到所有其他元素被刪除

測試在2011 SP1的一個元素

  • 。我不得不說,這是樂趣XSLT打再次,它已經太長時間:)

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
        <xsl:output omit-xml-declaration="yes" method="xml" cdata-section-elements="script"></xsl:output> 
    
        <xsl:template match="body"> 
        <xsl:copy> 
         <xsl:apply-templates select="//a[1]"></xsl:apply-templates> 
        </xsl:copy> 
        </xsl:template> 
    
        <xsl:template match="node() | @*"> 
         <xsl:copy> 
         <xsl:apply-templates select="node() | @*"></xsl:apply-templates> 
        </xsl:copy> 
        </xsl:template> 
        <xsl:template match="//a"> 
         <xsl:copy> 
         <xsl:apply-templates select="@*"></xsl:apply-templates> 
          <xsl:choose> 
          <xsl:when test="not(img)"> 
           <xsl:copy-of select="//img"></xsl:copy-of> 
         </xsl:when> 
          <xsl:otherwise> 
           <xsl:apply-templates select="node()"></xsl:apply-templates> 
         </xsl:otherwise> 
         </xsl:choose> 
        </xsl:copy> 
        </xsl:template> 
    </xsl:stylesheet> 
    
  • +0

    我已將它添加到XSLT篩選下,但它不按預期工作。我只是想知道,如何處理多個Image字段,如果沒有標籤,它的行爲如何。因爲我試過了,它不能正常工作。 – Patan

    +1

    您應該看到這是一個示例實現,並帶有我指出的業務規則。如果您必須實施不同的業務規則,您至少可以將其作爲起點。有一點XSLT知識在這裏有很長的路要走。 – Quirijn