Altova Mailing List Archives


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

From: Varun Suri <varunsuri@--------------->
To:
Date: 7/13/2004 8:12:00 PM
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

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.