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

RE: replacing a string value

Subject: RE: replacing a string value
From: "rick schochler" <ricks@xxxxxxxxxx>
Date: Thu, 29 Nov 2001 16:37:04 -0600
rick schochler
thanks

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Peter Davis
Sent: Thursday, November 29, 2001 4:07 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  replacing a string value


Am I right in assuming that the '?' can occur at any place in the input?:

<foo> hello ? world ? foo </foo>
would translate to:
<foo> hello <img/> world <img/> foo </foo>

This stylesheet will do what you want:

<?xml version="1.0"?>

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

  <xsl:template match="text()" name="img-replace">
    <xsl:param name="text" select="string()"/>
    <xsl:choose>
      <xsl:when test="not(contains($text, '?'))">
        <xsl:value-of select="$text"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="substring-before($text, '?')"/>
        <img/>
        <xsl:call-template name="img-replace">
          <xsl:with-param name="text" select="substring-after($text, '?')"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="@* | node()[not(self::text())]">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

The second template is a modified version of the identity template, taken
from the XSLT spec.  You can replace it with your normal processing if you
wish.  I tested the template with the latest Xalan from their CVS, but it
should work with just about any processor since it is 100% standard.


On Thursday 29 November 2001 01:48 pm, rick schochler wrote:
> I have a requirement to replace certain string characters (if encountered)
> with a graphic. For example, if the string value of my element foo is a
> question mark (i.e, <foo>?</foo>), I need to replace the ? with a graphic.
>
> Any ideas?

--
Furthermore, I believe bacon prevents hair loss.
Peter Davis

 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.