Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spilt String using XSL

Status
Not open for further replies.

2110

Programmer
Sep 17, 2001
5
US
My source looks omething like this:
<NAM>
<NAM-Child1>
Gonzales,Gus,Kalian,Kippu
</NAM-Child1>
</NAM>

I have to split the string and display them separately as
Gonzales
Gus
Kalian
Kippu

How do I split the string in XSL ?

Any help would be appreciated.
Thanks

 
Tom,

I did go thro' that page you mentioned.
I tried applying but it was not working for me.

At any point of time I have to display the lastname and firsname. The NAM can be empty or seprated by a spaces also and I have to take that also into consideration.

I'll try to work on the example you sent me. But if you have an alternate solution to this, please let me know.

Thanks
 
ok, i changed that code slightly so you might be able to drop it in now. the &quot;normalize-space&quot; function will chop off spaces so the input can be like &quot;one,two,three&quot; or &quot;one, two, three&quot;. i haven't checked this code myself tho :)

the bit between the <whatevertagsyouwant> is where each value is actually printed.

<xsl:template name=&quot;splitnames&quot;>
<xsl:param name=&quot;namelist&quot;/>
<xsl:variable name=&quot;name&quot;
select=&quot;normalize-space(substring-before($namelist,','))&quot;/>
<xsl:choose>
<xsl:when test=&quot;string-length($name) > 0&quot;>
<whatevertagsyouwant><xsl:value-of select=&quot;$name&quot;/></whatevertagsyouwant>
<xsl:call-template name=&quot;splitnames&quot;>
<xsl:with-param
name=&quot;namelist&quot;><xsl:value-of
select=&quot;substring-after($namelist,',')&quot;/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<td><xsl:value-of select=&quot;$namelist&quot;/></td>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

call function with

<xsl:call-template name=&quot;splitnames&quot;>
<xsl:with-param name=&quot;namelist&quot; select=&quot;/NAM/NAM-Child1&quot;/>
</xsl:call-template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top