Friday, 14 December 2007

XSLT output-tokens function ...

This can be used to split a string into tokens and add <br />s where appropriate:

<!-- reusable tokening function -->
<xsl:template name="output-tokens">
<xsl:param name="list" />
<xsl:variable name="newlist" select="concat(normalize-space($list), ' ')" />
<xsl:variable name="first" select="substring-before($newlist, ' ')" />
<xsl:variable name="remaining" select="substring-after($newlist, ' ')" />
<br />
<xsl:value-of select="$first" />
<br />
<xsl:if test="$remaining">
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$remaining" />
</xsl:call-template>
</xsl:if>
</xsl:template>

very handy ...

No comments:

Post a Comment