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

Re: Replacing strings in XSL

Subject: Re: Replacing strings in XSL
From: JBryant@xxxxxxxxx
Date: Fri, 18 Mar 2005 16:25:35 -0600
xslt instring
That clears up the issue. I thought you might have a structure like 
<element>      </element>, which would be a different problem.

The following solutions work against this midget XML structure:

<x>
  <y>one two three</y>
</x>

One way to do what you want to do in XSLT 1.0 is this:
  <xsl:template match="y">
    <y>
      <xsl:call-template name="replaceSpace">
        <xsl:with-param name="inString" select="."/>
      </xsl:call-template>
    </y>
  </xsl:template>
 
  <xsl:template name="replaceSpace">
    <xsl:param name="inString"/>
    <xsl:choose>
      <xsl:when test="contains($inString, ' ')">
        <xsl:value-of select="substring-before($inString, ' ')"/>&#160;
        <xsl:call-template name="replaceSpace">
          <xsl:with-param name="inString" 
select="substring-after($inString, ' ')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$inString"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

One way to do it in XSL 2.0 is this:
  <xsl:template match="y">
    <y><xsl:value-of select="replace(., ' ', '&#160;')"/></y>
  </xsl:template>

(Thanks to Dr. Kay for pointing out the replace function earlier today.)

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




preetig_2 <preetig_2@xxxxxxxxx> 
03/18/2005 04:05 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
cc

Subject
Re:  Replacing strings in XSL






Hi Jay,

My XML has a tag somewhat like this,

<MANUFACTURER>LG Electronics Inc</MANUFACTURER> 

The XSL has to replace the white spaces with &nbsp;
For e.g: LG&nbsp;Electronics&nbsp;Inc

Hope that helps, please let me know if you have nay
questions.

Thanks,
Preeti 


> I'm sure it is, but exactly how you'd want to go
> about it is likely to 
> depend on the details of what you are trying to do.
> How about sending us 
> snippets (small but complete enough to show the
> problem) of your XML 
> source, your stylesheet so far, and your desired
> output. It's pretty hard 
> to answer questions in a vacuum (at least for me).
> 
> Jay Bryant
> Bryant Communicaton Services
> (presently consulting at Synergistic Solution
> Technologies)
> 
> 
> 
> 
> preetig_2 <preetig_2@xxxxxxxxx> 
> 03/18/2005 03:07 PM
> Please respond to
> xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> 
> 
> To
> xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> cc
> 
> Subject
>  Replacing strings in XSL
> 
> 
> 
> 
> 
> 
> Hi ,
> 
> I am trying to replace white space with &nbsp; .
> Please let me know if its doable in XSL.
> 
> Thanks,
> Preeti
> 



 
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 

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.