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

Re: replace a word

Subject: Re: replace a word
From: Kamal Bhatt <kbhatt@xxxxxxxxx>
Date: Tue, 13 Dec 2005 16:44:49 +1100
another word for hurry
This is correct. sub is not an element, it will therefore only find and replace once.

What you need is a recursive call that will keep recursing till there are no more instances of {sub}.

There are a number of examples of similar situations on the mailing list.

Cheers.

Kamal.

T Uma Shankari wrote:


Greetings to all,


I have to find a word and replace that word with another word.

for example if my xml file is like this means

<question page="6" Queswav="" ChooseType="" id="0" Qno="533" chapter="chapter1" >
<stmt1 mgif1="" mgif="" Qno="533" misc="" >statement1</stmt1>
<opt ptno="1" mgif1="" mgif="" " misc=""


{sub}2{/sub}Option1{sub}5{/sub}</opt>

<opt ptno="1" mgif1="" mgif="" " misc="" >Option2</opt> <opt ptno="1" mgif1="" mgif="" " misc="" >Option3</opt> <opt ptno="1" mgif1="" mgif="" " misc="" >Option4</opt> </question>


i need to find the {sub} and replace it with {/sub} so i have written this code.


xsl:template match="question" name="main">
 <xsl:for-each select="self::question">
           <xsl:variable name="stringques1">
              <h1><b><xsl:value-of select="opt" /></b></h1>
            </xsl:variable>

<xsl:variable name="stringques2">
<xsl:choose>
<xsl:when test="(contains($stringques1,'{sub}'))">
<xsl:value-of select="substring-before($stringques1,'{sub}')"/>
<sub>
<xsl:value-of select="substring-before(substring-after($stringques1,'{sub}'),'{/sub}')"/>


   </sub>
  <xsl:value-of select="substring-after($stringques1,'{/sup}')" />
      </xsl:when>
       <xsl:otherwise>
        <xsl:value-of select="$stringques1"/>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:variable>
 </xsl:for-each>
  </xsl:template>
 </xsl:stylesheet>


It is replacing the first occurance not the oncoming occurance. Can anyone please tell where i am wrong?


regards
uma

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.