to jörn nettingsmeier:
thanks, this is a very good idea!
Silvia Liberto
--- Ursprüngliche Nachricht ---
Von: Joern Nettingsmeier <nettings(_at_)folkwang-hochschule(_dot_)de>
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Betreff: Re: [xsl] Split the content of a variable (xpath 1.0)
Datum: Fri, 03 Mar 2006 14:41:38 +0100
Silvia Liberto wrote:
Hi all,
I have a variable "Keywords" with several keywords inside.
They are seperated with ;.
so i want per xslt to split this content into single keywords,
like this:
<keywordset>
<keyword>Keyword1</keyword>
<keyword>Keyword2</keyword>
<keyword>Keyword3</keyword>
<keyword>Keyword4</keyword>
<keyword>Keyword5</keyword>
</keywordset>
xml:
<Keywords>Keyword1; Keyword2; Keyword3; Keyword4; Keyword5;
Keyword6</Keywords>
here's an xslt1.0 version without extension functions:
<xsl:template name="tokenize">
<xsl:param name="inputString"/>
<xsl:param name="separator" select="' '"/>
<xsl:param name="resultElement" select="'item'"/>
<xsl:variable
name="token"
select="substring-before($inputString, $separator)"
/>
<xsl:variable
name="nextToken"
select="substring-after($inputString, $separator)"
/>
<xsl:if test="$token">
<xsl:element name="{$resultElement}">
<xsl:value-of select="$token"/>
</xsl:element>
</xsl:if>
<xsl:if test="$nextToken">
<xsl:call-template name="tokenize">
<xsl:with-param
name="inputString"
select="$nextToken"/>
<xsl:with-param
name="separator"
select="$separator"/>
<xsl:with-param
name="resultElement"
select="$resultElement"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
and here's how you would use it to get what you want:
<xsl:template match="Keywords">
<keywords>
<xsl:call-template name="tokenize">
<xsl:with-param
name="inputString"
select="."/>
<xsl:with-param
name="separator"
select="';'"/>
<xsl:with-param
name="resultElement"
select="'keyword'"/>
</xsl:call-template>
</keywords>
</xsl:template>
--
jörn nettingsmeier
home://germany/45128 essen/lortzingstr. 11/
http://spunk.dnsalias.org
phone://+49/201/491621
if you are a free (as in "free speech") software developer
and you happen to be travelling near my home, drop me a line
and come round for a free (as in "free beer") beer. :-D
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--
Bis zu 70% Ihrer Onlinekosten sparen: GMX SmartSurfer!
Kostenlos downloaden: http://www.gmx.net/de/go/smartsurfer
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--