2011-11-07 36 views
0

我想運行此XSL:帶HTML和截斷

<!-- This will remove the tag --> 
<xsl:template name="remove-html"> 
    <xsl:param name="text"/> 
    <xsl:choose> 
     <xsl:when test="contains($text, '&lt;')"> 
      <xsl:value-of select="normalize-space(substring-before($text, '&lt;'))"/> 
      <xsl:text> </xsl:text> 
      <xsl:call-template name="remove-html"> 
       <xsl:with-param name="text" select="normalize-space(substring-after($text, '&gt;'))"/> 
      </xsl:call-template> 
     </xsl:when> 
     <xsl:otherwise> 
      <xsl:value-of select="normalize-space($text)"/> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 

<xsl:choose> 
    <xsl:when test="string-length(header) > 22"> 
     <xsl:value-of select="substring(header, 0, 22)" /> 
     <xsl:text>&#8230;</xsl:text> 
    </xsl:when> 
    <xsl:otherwise> 
     <xsl:value-of select="header" /> 
    </xsl:otherwise> 
</xsl:choose> 

在一起..我該怎麼辦呢?

+0

你的意思是你想要的代碼的頂部位匹配對'body'元素和對'head'元素底位替換???? –

+0

不,我想運行一個文本通過,並刪除HTML並截斷結果 –

+1

我不評論你的方法是否正確,但這兩個動作的純粹組成可以自然地實現捕獲變量中第一個動作的輸出並將第二個動作應用於該變量。 –

回答

1
<xsl:variable name="stripped"> 
    <xsl:call-template name="remove-html"> 
     <xsl:with-param name="text" select="???"/> 
    </xsl:call-template> 
</xsl:variable> 
<xsl:choose> 
    <xsl:when test="string-length($stripped) > 22"> 
     <xsl:value-of select="substring($stripped, 0, 22)" /> 
     <xsl:text>&#8230;</xsl:text> 
    </xsl:when> 
    <xsl:otherwise> 
     <xsl:value-of select="$stripped" /> 
    </xsl:otherwise> 
</xsl:choose> 

與適當的節點

0

將您的第二個選擇放在一個已命名的模板中,然後將第一個值替換爲第一個調用模板。