tags:

views:

27

answers:

2

I'm trying to write some xsl to style an RSS feed. The problem I'm running into is that I need to trim the first 10 characters off the title of each item and I can't get it to work.

<?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>

I'm sure I'm missing something basic, so any direction or assistance would be appreciates

+1  A: 

I think you should write your substring function as this:

substring($string,1, 10)

Look at here

http://www.zvon.org/xxl/XSLTreference/Output/function_substring.html

Govan
A: 

What are you doing in your trimtitle template? Why are you calling trimtitle recursive..?

The easiest way to show a trimmed string is with:

<xsl:value-of select="substring(title,0,10)"/>
ChrisBenyamin
Thanks - that was just what I needed to uncomplicate the mess I was trying. I appreciate it.
Dan O