This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Inserting into a String
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Inserting into a String
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Fri, 16 Mar 2001 09:24:39 +0000
- CC: Bartlett Gary <GBartlett at globalfoodexchange dot com>
- Organization: Jeni Tennison Consulting Ltd
- References: <551E3FB53858D411B48600B0D020E6A2741B9D@ATLMAIL><200103151707.RAA17829@penguin.nag.co.uk>
- Reply-To: xsl-list at lists dot mulberrytech dot com
"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