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

Re: delete the white spaces

Subject: Re: delete the white spaces
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Fri, 4 Jun 2004 15:46:34 +0100
xsl replace space
> 1.- delete the whie spaces and show:
> holasoyyo
This is simple
 <xsl:value-of select="translate(root,' ','')"/>

> 2.- how can i substitute the whiel spaces with %20?
> hola%20soy%20yo
To do this you have to write a recursive template that searches and replaces
the string..

 Try This

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

 <!-- First One .. Get rid of spaces -->
  <xsl:value-of select="translate(root,' ','')"/>
 <!-- Second one Replace space with %20 -->
   <br/>
  <xsl:call-template name="replace">
   <xsl:with-param name="text-string" select="root"/>
   <xsl:with-param name="find-word" select="' '"/>
   <xsl:with-param name="replace-with" select="'%20'"/>
  </xsl:call-template>
 </xsl:template>

 <xsl:template name="replace">
  <xsl:param name="text-string"/>
  <xsl:param name="find-word"/>
  <xsl:param name="replace-with"/>
  <xsl:choose>
   <xsl:when test="contains($text-string,$find-word)">
    <xsl:call-template name="replace">
     <xsl:with-param name="text-string"
select="concat(substring-before($text-string,$find-word),$replace-with,subst
ring-after($text-string,$find-word))"/>
     <xsl:with-param name="find-word" select="$find-word"/>
     <xsl:with-param name="replace-with" select="$replace-with"/>
    </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="$text-string"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
</xsl:stylesheet>
The above template ( replace ) is a generic one, and you can use it for  any
string replace functionality..

for an xml that looks like
<?xml version="1.0"?>
<root>hola soy yo</root>

The output would be

holasoyyo
hola%20soy%20yo
in a HTML view
Hope This Helps
Vasu

----- Original Message ----- 
From: "Dionisio Ruiz de Zarate" <dionisio@xxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, June 04, 2004 12:04 PM
Subject:  delete the white spaces


> Hello y have one xml with this:
> <root>hola soy yo</root>
> i make:
> <xsl:value-of select="root" disable-output-escaping="yes"/>
> but it shows me the white spaces.
> how can i:
>
> 1.- delete the whie spaces and show:
> holasoyyo
>
> 2.- how can i substitute the whiel spaces with %20?
> hola%20soy%20yo
>
>
> thanks
>
> --+------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --+--
>
>

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.