Subject: Re: [xsl] Split string From: andrew.curry@xxxxxxxxxxxx Date: Fri, 5 Dec 2003 15:59:30 -0000 |
try try <xsl:template name="str:split"> <xsl:param name="string" select="''" /> <xsl:param name="pattern" select="' '" /> <xsl:choose> <xsl:when test="not($string)" /> <xsl:when test="not($pattern)"> <xsl:call-template name="str:_split-characters"> <xsl:with-param name="string" select="$string" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="str:_split-pattern"> <xsl:with-param name="string" select="$string" /> <xsl:with-param name="pattern" select="$pattern" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="str:_split-characters"> <xsl:param name="string" /> <xsl:if test="$string"> <token><xsl:value-of select="substring($string, 1, 1)" /></token> <xsl:call-template name="str:_split-characters"> <xsl:with-param name="string" select="substring($string, 2)" /> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template name="str:_split-pattern"> <xsl:param name="string" /> <xsl:param name="pattern" /> <xsl:choose> <xsl:when test="contains($string, $pattern)"> <xsl:if test="not(starts-with($string, $pattern))"> <token><xsl:value-of select="substring-before($string, $pattern)" />< /token> </xsl:if> <xsl:call-template name="str:_split-pattern"> <xsl:with-param name="string" select="substring-after($string, $patte rn)" /> <xsl:with-param name="pattern" select="$pattern" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <token><xsl:value-of select="$string" /></token> </xsl:otherwise> </xsl:choose> </xsl:template> ----- Original Message ----- From: "Ricardo Saraiva" <rss@xxxxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Friday, December 05, 2003 3:53 PM Subject: [xsl] Split string > Hello, > > How do I split a string into several strings by a given token? > > The example that follows shows what is supposed to be done: > > The input: > > <ToName>person1;person2</ToName> > <ToAddress>mail1;mail2</ToAddress> > > Desired output: > > <To> > <Contact> > <Name>person1</Name> > <Address>mail1</Address> > </Contact> > <Contact> > <Name>person2</Name> > <Address>mail2</Address> > </Contact> > </To> > > Thanks in advance, > > Ricardo Saraiva. > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Split string, Ricardo Saraiva | Thread | Re: [xsl] Split string, JCS |
[xsl] Split string, Ricardo Saraiva | Date | [xsl] Get Values from other .xslt f, Iris Benjamin |
Month |