Subject: Re: [xsl] Inserting into a String From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Fri, 16 Mar 2001 09:24:39 +0000 |
"Jeni" wrote: > Oh what the heck, apply this to any XML doc (eg itself) [snip] If you've got a long string and want to avoid deep recursion, it would be better to use one of: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="*"> <xsl:call-template name="x"> <xsl:with-param name="string" select="'fooBarJones'" /> </xsl:call-template> <xsl:text> </xsl:text> <xsl:call-template name="a"> <xsl:with-param name="string" select="'fooBarJones'" /> </xsl:call-template> </xsl:template> <xsl:variable name="uc" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /> <xsl:variable name="lc" select="'abcdefghijklmnopqrstuvwxyz'" /> <xsl:variable name="es" select="'::::::::::::::::::::::::::'" /> <xsl:template name="x"> <xsl:param name="string" /> <xsl:variable name="y" select="translate($string, $uc, $es)" /> <xsl:choose> <xsl:when test="contains($y, ':')"> <xsl:variable name="z" select="substring-before($y, ':')" /> <xsl:variable name="nz" select="string-length($z)" /> <xsl:value-of select="concat(translate($z, $lc, $uc), '_', substring($string, $nz + 1, 1))" /> <xsl:call-template name="x"> <xsl:with-param name="string" select="substring($string, $nz + 2)" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="translate($string, $lc, $uc)" /> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="a"> <xsl:param name="string" /> <xsl:variable name="b" select="string-length($string)" /> <xsl:choose> <xsl:when test="$b < 2"> <xsl:choose> <xsl:when test="contains($uc, $string)"> <xsl:text />_<xsl:value-of select="$string" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="translate($string, $lc, $uc)" /> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:call-template name="a"> <xsl:with-param name="string" select="substring($string, 1, $b div 2)" /> </xsl:call-template> <xsl:call-template name="a"> <xsl:with-param name="string" select="substring($string, $b div 2 + 1)" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> David XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Inserting into a String, David Carlisle | Thread | Re: [xsl] Inserting into a String, David Carlisle |
Re: [xsl] new line, David Carlisle | Date | RE: [xsl] Comment about XSLT Compli, Michael Kay |
Month |