Re: [xsl] replacing a string value

Subject: Re: [xsl] replacing a string value
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 29 Nov 2001 18:45:20 -0500
I'm going to assume Rick means a hyperlink to a graphic, such as an <IMG SRC="..."/> element....

In the simple case, it could be as easy as

<xsl:template match="foo">
<xsl:copy>
<!-- copying the foo since Rick didn't tell us otherwise -->
<xsl:if test=".='?'">
<!-- testing if the value of the current node is equal to the string '?' -->
<img src="questionmark.jpg"/>
</xsl:if>
</xsl:copy>
</xsl:template>


But this is assuming many things. Things are trickier if you need to worry about strings floating in other strings (not just testing for and replacing entire strings) -- then you will have to recurse over your text node, as Jeni does when replacing a string with another (Rick, see www.jenitennison.com). Also whitespace might be a problem: you may have to work around that. Then too, there are tricks one can use (not shown here) to make the solution more scalable. But mainly, Rick hasn't said if, when and what *else* happens to <foo> elements or the text inside them, which he might have to account for.

I hope that helps,
Wendell


At 05:30 PM 11/29/01, you wrote:
[rick schochler]

> This may be a simple one, but here it goes...
>
> 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.
>

What do you mean, "with a graphic"?  Do you want a hyperlink to a graphic?
Do you want the graphic to be inserted using base64 encoding?  So you want
to insert an svg graphic? ...

Tom P


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


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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



Current Thread