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

Re: String manipulation XSLT 1.0

Subject: Re: String manipulation XSLT 1.0
From: pankaj.c@xxxxxxxxxxxxxxxxxx
Date: Thu, 23 Sep 2010 09:18:16 +0530
Re:  String manipulation XSLT 1.0
Thanks Martin:

>> <xsl:value-of select="concat(substring-before(., '.'), '. ', 
substring-after(., '.'))"/>

Works fine with single initial or two initials.

<given-name>A.</given-name> or <given-name>A.H.</given-name> but fails for 
the 3 or four initials.

>> Or check http://exslt.org/ for a replace template for XSLT 1.0.

                    <xsl:call-template name="replace-substring">
                        <xsl:with-param name="original" select="."/>
                        <xsl:with-param name="substring" select="'.'"/>
                        <xsl:with-param name="replacement" select="'. '"/>
                    </xsl:call-template>
is somewhat near to the requirement but the only thing is that it adds 
"space" to last initial too. (A.H. to A. H. ), which I do not want.

The best I have done is 

<xsl:template match="given-name">
<xsl:copy>
    <xsl:choose>
    <xsl:when test="string-length(.)=2 and contains(.,'.')">
        <xsl:value-of select="."/>
    </xsl:when>
    <xsl:when test="string-length(.)=4 and contains(.,'.')">
        <xsl:value-of select="concat(substring-before(., '.'), '. ', 
substring-after(., '.'))"/>    </xsl:when>
    <xsl:otherwise> 
 
                    <xsl:call-template name="replace-substring">
                        <xsl:with-param name="original" select="."/>
                        <xsl:with-param name="substring" select="'.'"/>
                        <xsl:with-param name="replacement" select="'. '"/>
                    </xsl:call-template>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:copy>
</xsl:template>

<xsl:template name="replace-substring">
<xsl:param name="original"/>
<xsl:param name="substring"/>
<xsl:param name="replacement" select="'. '"/>
<xsl:choose>
    <xsl:when test="contains($original, $substring)">
        <xsl:value-of select="substring-before($original, $substring)"/>
        <xsl:copy-of select="$replacement"/>
        <xsl:call-template name="replace-substring">
            <xsl:with-param name="original" 
select="substring-after($original, $substring)"/>
            <xsl:with-param name="substring" select="$substring"/>
            <xsl:with-param name="replacement" select="$replacement"/>
        </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="$original"/>
    </xsl:otherwise>
</xsl:choose>
</xsl:template>

I would prefer to use replace() function if there is way of avoiding last 
intial "space". AARRRGH, time to switch to 2.0 for this project.

Looking for thoughts

TIA,
Pankaj

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.