2011-11-07 34 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

将您的第二个选择放在一个已命名的模板中,然后将第一个值替换为第一个调用模板。