2010-07-22 19 views
0

我想寫一些xsl風格的RSS訂閱源。我需要修剪每個項目標題的前10個字符。修剪前10個字符的RSS飼料標題

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:template match="/rss"> 
<ul> 
<xsl:for-each select="channel/item"> 
<li><strong><xsl:value-of select="title"/> 
</strong> 
<a href="{link}">More</a></li> 
</xsl:for-each> 
</ul> 
</xsl:template> 

<xsl:template name="trimtitle"> 
<xsl:param name="string" select="." /> 
<xsl:if test="$string"> 
<xsl:text>Foo</xsl:text> 
<xsl:call-template name="trimtitle"> 
<xsl:with-param name="string" select="substring($string, 10)" /> 
</xsl:call-template> 
</xsl:if> 
</xsl:template> 

<xsl:template match="title"> 
<xsl:call-template name="title" /> 
<xsl:value-of select="." /> 
</xsl:template> 


</xsl:stylesheet> 
+0

你忘了提供源XML文檔(短,請)。 – 2010-07-23 12:45:00

回答

1

你是什麼在你的微縮模板中做什麼? 你爲什麼要調用trimtitle遞歸..?

顯示修剪字符串的最簡單的方法是:

<xsl:value-of select="substring(title,0,10)"/> 
+0

謝謝 - 這正是我所需要的,以簡化我嘗試的混亂。我很感激。 – 2010-07-26 12:51:12