Re: [xsl] Detecting and replacing "Space" in a XML using XSL

Subject: Re: [xsl] Detecting and replacing "Space" in a XML using XSL
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 11 Sep 2007 11:50:23 -0400
Buddhi,

No (you are correct), translate() won't work for this purpose.

If using XSLT 2.0, you want the replace() function.

If using XSLT 1.0, this is considerably more difficult, but not impossible. Consult the FAQ at http://www.dpawson.co.uk/xsl/sect2/replace.html.

Cheers,
Wendell

At 11:51 PM 9/10/2007, you wrote:
Hi all,

I have a string element in a xml file, it can consist a word. After
parsing  I am taking letter by letter with some formatting stuff.

Ex.

My original String:
<Value>H A N</Value>

After Parsing : (I have trimmed output for more clearance)

&lt;Body&gt;
&lt;FontFace value="STDFONT.FNT"&gt;&lt;FontSize value="0.2"&gt;H&lt;/FontSize&gt;&lt;/FontFace&gt;
&lt;FontFace value="STDFONT.FNT"&gt;&lt;FontSize
value="0.2"&gt;&lt;/FontSize&gt;&lt;/FontFace&gt;
&lt;FontFace value="STDFONT.FNT"&gt;&lt;FontSize
value="0.2"&gt;A&lt;/FontSize&gt;&lt;/FontFace&gt;
&lt;FontFace value="STDFONT.FNT"&gt;&lt;FontSize
value="0.2"&gt;&lt;/FontSize&gt;&lt;/FontFace&gt;
&lt;FontFace value="STDFONT.FNT"&gt;&lt;FontSize
value="0.2"&gt;N&lt;/FontSize&gt;&lt;/FontFace&gt;
&lt;/Body&gt;


As you see I have spaces on my original string.

I want to translate spaces into '_x0020_' rather than empty space. I
tried using "translate()" but it will put one character because I have
single space.
translate(substring($text,$i,1), '&#x20;', '_x0020_')

The out put I want to get is...
....
&lt;FontFace value="STDFONT.FNT"&gt;&lt;FontSize value="0.2"&gt;_x0020_&lt;/FontSize&gt;&lt;/FontFace&gt;
....


Please help me....

- Regards

- Buddhi from Sri Lanka -


======================================================================
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
======================================================================

Current Thread