Subject: Re: [xsl] Split the content of a variable (xpath 1.0) From: "Silvia Liberto" <SLiberto@xxxxxx> Date: Mon, 6 Mar 2006 14:24:47 +0100 (MET) |
to jvrn nettingsmeier: thanks, this is a very good idea! Silvia Liberto > --- Urspr|ngliche Nachricht --- > Von: Joern Nettingsmeier <nettings@xxxxxxxxxxxxxxxxxxxxxx> > An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > 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> > > > -- > jvrn 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 > -- Bis zu 70% Ihrer Onlinekosten sparen: GMX SmartSurfer! Kostenlos downloaden: http://www.gmx.net/de/go/smartsurfer
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Split the content of a va, Joern Nettingsmeier | Thread | RE: [xsl] Split the content of a va, Silvia Liberto |
AW: [xsl] Stylesheet for converting, Huditsch, Roman \(LN | Date | Re: [xsl] sequence with same id val, David Carlisle |
Month |