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

Re: XSL is NOT a string processing language!

Subject: Re: XSL is NOT a string processing language!
From: "Remco Bouckaert" <rrb@xxxxxxxx>
Date: Thu, 23 May 2002 13:06:25 +1200
xsl string processing
How about this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template match="/">
 <xsl:call-template name="replace-string"><xsl:with-param
name="str">bias</xsl:with-param></xsl:call-template>
</xsl:template>

<xsl:template name="replace-char">
 <xsl:param name="char"></xsl:param>
 <xsl:choose>
  <xsl:when test="$char='a'">bY</xsl:when>
  <xsl:when test="$char='b'">aY</xsl:when>
  <xsl:otherwise><xsl:value-of select="$char"/></xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template name="replace-string">
 <xsl:param name="str"></xsl:param>
 <xsl:if test="string-length($str)&gt;0">
  <xsl:variable name="first" select="substring($str,1,1)"></xsl:variable>
  <xsl:variable name="rest" select="substring($str,2,32786)"></xsl:variable>
  <xsl:call-template name="replace-char"><xsl:with-param name="char"
select="$first"></xsl:with-param></xsl:call-template>
  <xsl:call-template name="replace-string"><xsl:with-param name="str"
select="$rest"></xsl:with-param></xsl:call-template>
 </xsl:if>
</xsl:template>

</xsl:stylesheet>

Update the template "replace-char" to get the replacement for each of the
characters you want

Cheers,

Remco

----- Original Message -----
From: "Philippe Figon" <philippe.figon@xxxxxxxxxxxx>
To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, May 23, 2002 1:46 PM
Subject:  XSL is NOT a string processing language!


> Hello,
>
> First I'd like to say that I _know_ XSL is not a string processing
language,
> but I am facing a problem I wish I could solve inside XSL itself.
>
> Here it is : writing style sheets to convert XML in LaTeX I have to make
> some characters substitutions due to the "escape chars".
> I'm heavily using David Carlisle string-replace template, it works fine
but
> because of its "recursiveness" I can't obtain sequential replacement :
>
> If I want to replace 'a' by 'bX' and 'b' by 'aY' (which really happens
with
> \ and { for example), within the string 'bias' I will _never_ obtain
> 'aYibXs' which is what I want, but aYiaYXs or bXYibXs dependind on the
order
> of the calls to the string-replace template.
>
> Due to the lack of "real" variables I can't find a way of doing this, I've
> tried out many different ways but it's always endind with a "oh no, you
> can't change the value of a variable and pass it to another template". One
> solution could have been the use of global variables, but if you change
> them, the change will be available only in the template where you made it
> (kind of local global variable ;-)), no way to escape this circle.
>
> Does anyone think it's possible to do such sequential substitution ?
>
> Philippe
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.