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

Re: how to replace a part of a string with a newline??

Subject: Re: how to replace a part of a string with a newline??
From: Varun Suri <varunsuri@xxxxxxxxxxxxxxx>
Date: Tue, 13 Jul 2004 14:54:07 +0530
varun suri
Mukul Gandhi wrote:

Hi Varun,
 This stylesheet does it. It uses a recursive
template.

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


<xsl:output method="text" />

<xsl:template match="/s">
  <xsl:call-template name="replace-string">
     <xsl:with-param name="str" select="." />
     <xsl:with-param name="delim" select="'__OPT__'"
/>
  <xsl:with-param name="newdelim" select="':'" />
</xsl:call-template>
</xsl:template>

<xsl:template name="replace-string">
<xsl:param name="str" />
<xsl:param name="delim" />
<xsl:param name="newdelim" />
<xsl:if
test="string-length(substring-before($str,$delim)) =
0">
<xsl:value-of select="$str" />
</xsl:if>
<xsl:if
test="string-length(substring-before($str,$delim)) >
0">
<xsl:value-of
select="substring-before($str,$delim)" /><xsl:value-of
select="$newdelim" />
</xsl:if>
<xsl:if
test="string-length(substring-after($str,$delim)) >
0">
<xsl:call-template name="replace-string">
<xsl:with-param name="str"
select="substring-after($str,$delim)" />
<xsl:with-param name="delim" select="$delim"
/>
<xsl:with-param name="newdelim"
select="$newdelim" />
</xsl:call-template>
</xsl:if> </xsl:template>


</xsl:stylesheet>

for e.g. when it is applied to XML
<?xml version="1.0"?>
<s>Importer__OPT__Trading Company__OPT__Service
Provider</s>

it produces output
Importer:Trading Company:Service Provider

Regards,
Mukul

--- Varun Suri <varunsuri@xxxxxxxxxxxxxxx> wrote:


Hi

Ive got this string :

Importer__OPT__Trading Company__OPT__Service
Provider

How do i make it equivalent to
- Importer
- Trading Company
- Service Provider


Ive tried using translate function, but it replaces
all instances of the letters O,P,T as well.I did something like:


translate(text(),'__OPT__',':')

It gives the following output is Importer:rading
Company:Service rovider which i dont want.


Any easy way to do it??

Thanks in advance
Regards
Varun





__________________________________ Do you Yahoo!? Yahoo! Mail - 50x more storage than other providers! http://promotions.yahoo.com/new_mail




Thanks Mukul
Worked perfectly.


Regards


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.