Subject: [xsl] creating tags around a string From: TGolshan@xxxxxxxxxxxx Date: Mon, 17 Apr 2006 14:17:47 -0700 |
Hello, I am trying to create some tags around a string of names and was wondering what is the best way to do this. I have come up with the below xslt, but it will only work limited instances. Any other ideas would be grand. For example, if I have any middle names or more than a first/last name, the xslt breaks. Thanks! -troy ===================================================== <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="http://whatever"> <xsl:output method="text"/> <xsl:function name="foo:mesplit"> <xsl:param name="inString"/> <xsl:param name="delimiter"/> <xsl:variable name="tokenizedSample" select=" tokenize($inString,$delimiter)"/> <xsl:for-each select="$tokenizedSample"> <xsl:variable name="thisstick"> <xsl:value-of select="."/> </xsl:variable> <xsl:choose> <xsl:when test="contains(.,',')"> <xsl:value-of select=" foo:mesplit($thisstick,',')"/> </xsl:when> <xsl:when test="contains(., ' ')"> <xsl:value-of select="foo:mesplit( normalize-space($thisstick),' ')"/> </xsl:when> <xsl:otherwise> <xsl:if test="."> <xsl:if test=" index-of($tokenizedSample, .) = 1"> <xsl:text> </ xsl:text> <xsl:text> <fname></xsl:text> < xsl:value-of select="."/> <xsl:text> </fname></xsl:text> </xsl:if> <xsl:if test=" index-of($tokenizedSample, .) = 2"> <xsl:text> <lname></xsl:text> < xsl:value-of select="."/> <xsl:text> </lname></xsl:text> </xsl:if> </xsl:if> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:function> <xsl:template match="/"> <xsl:value-of select="foo:mesplit('Al Stick, Tom She, Dick Burg and Harry Ward', 'and')"/> </xsl:template> </xsl:stylesheet> ====================== desired output: <fname>Al</fname><lname>Stick</lname> <fname>Tom</fname><lname>She</lname> <fname>Dick</fname><lname>Burg</lname> <fname>Harry</fname><lname>Ward</lname>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Re: xsl:choose and multip, Florent Georges | Thread | Re: [xsl] creating tags around a st, Wendell Piez |
RE: [xsl] Problem with passing argu, Michael Kay | Date | Re: [xsl] creating tags around a st, Wendell Piez |
Month |