[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

creating tags around a string

Subject: creating tags around a string
From: TGolshan@xxxxxxxxxxxx
Date: Mon, 17 Apr 2006 14:17:47 -0700
around a string
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>
&lt;fname&gt;</xsl:text>
                                                                <
xsl:value-of select="."/>
                                                        <xsl:text>
&lt;/fname&gt;</xsl:text>
                                                </xsl:if>
                                                <xsl:if test="
index-of($tokenizedSample, .) = 2">
                                                        <xsl:text>
&lt;lname&gt;</xsl:text>
                                                                <
xsl:value-of select="."/>
                                                        <xsl:text>
&lt;/lname&gt;</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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.