[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|