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

RE: replace multiple distinct strings

Subject: RE: replace multiple distinct strings
From: Jarno.Elovirta@xxxxxxxxx
Date: Tue, 30 Sep 2003 08:19:01 +0300
multiple distinct
Hi,

> I'm attempting to write a javascript escape function like 
> template in xsl.  
> I wish to escape text to it's URL escaped form (i.e. %xx 
> where x is a hex 
> digit).
> 
> I've tried two different style sheets that I think should 
> accomplish the 
> same thing.  However, I end up with the following error:  
> javax.xml.transform.TransformerException: java.lang.RuntimeException: 
> Invalid conversion from 'reference' to 'java.lang.String'.

Probably a Xalan bug. Try out something in the lines of

  <xsl:key name="hex" match="replace" use="from"/>
  <xsl:template name="js:escape">
    <xsl:param name="text"/>
    <xsl:for-each select="document('replace.xml')">
      <xsl:call-template name="js:escape.recursion">
        <xsl:with-param name="text" select="$text"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="js:escape.recursion">
    <xsl:param name="text"/>
    <xsl:choose>
      <xsl:when test="not($text)"/>
      <xsl:when test="key('hex', substring($text, 1, 1))">
        <xsl:value-of select="key('hex', substring($text, 1, 1))/to"/>
        <xsl:call-template name="js:escape.recursion">
          <xsl:with-param name="text" select="substring($text, 2)"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="substring($text, 1, 1)"/>
        <xsl:call-template name="js:escape.recursion">
          <xsl:with-param name="text" select="substring($text, 2)"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

Cheers,

Jarno - Nick Sentience: March 2003 Mix

 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.