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

Re: replace html tag

Subject: Re: replace html tag
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Wed, 13 Apr 2005 10:17:15 -0700 (PDT)
replace html tags
Below is a fictitious example to do what you want
(hope you may adapt to your XML)..

The XML file is -

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<document>
  <para>{i}this{/i} is {i}an{/i} example 1</para>
  <para>this is an {i}example 2{/i}</para>
  <para>this is an example 3</para>
  <para>th{i}is{/i} is an {i}ex{/i}ample
{i}4{/i}</para>
</document>

And XSLT stylesheet is -

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
 <xsl:output method="html" />
 
  <xsl:template match="/document">
    <html>
      <head>
        <title></title>
        <body>
          <xsl:for-each select="para">
            <p>
              <xsl:call-template
name="italics-template">
                <xsl:with-param name="text" select="."
/>
                <xsl:with-param name="startdelim"
select="'{i}'" />
                <xsl:with-param name="enddelim"
select="'{/i}'" />                
              </xsl:call-template>
            </p>  
          </xsl:for-each>
        </body>
      </head>
    </html>
  </xsl:template>
 
  <!-- template to create italics tags -->
  <xsl:template name="italics-template">
    <xsl:param name="text" />
    <xsl:param name="startdelim" />
    <xsl:param name="enddelim" />
    
    <xsl:choose>
      <xsl:when test="contains($text, $startdelim) and
contains($text, $enddelim)">
        <xsl:value-of select="substring-before($text,
$startdelim)" />
        <i><xsl:value-of
select="substring-before(substring-after($text,$startdelim),
$enddelim)" /></i>        
        <xsl:call-template name="italics-template">
	   <xsl:with-param name="text"
select="substring-after($text,$enddelim)" />
	   <xsl:with-param name="startdelim"
select="$startdelim" />
	   <xsl:with-param name="enddelim" select="$enddelim"
/>	
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
</xsl:stylesheet>

The result of transformation is -

<html>
   <head>
      <meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">

      <title></title>
      <body>
         <p><i>this</i> is <i>an</i> example 1
         </p>
         <p>this is an <i>example 2</i></p>
         <p>this is an example 3</p>
         <p>th<i>is</i> is an <i>ex</i>ample
<i>4</i></p>
      </body>
   </head>
</html>

All {i}...{/i} pairs are replaced by <i>...</i> .

I am also able to see the desired output in the
browser (IE 6)..

I won't say this is best approach. But I think it
achieves what you want..

I hope this helps you..

Regards,
Mukul

--- Ahalya <ahalya@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> 
> 
> Greetings!
> 
>      I am having some characters like {i},{/i} in
> the xml file. whenever i
> find the word like {i} in xml i shd replace the "{"
> with "<" and while
> viewing the contents in the html browser i shd get
> the text to be italised
> once it finds the tag like that..Can any one tell me
> how to do that ?
> 
> for example {i}Hi{/i} --> shd appear like Hi in
> italised format in
> browser.
> 
> 
> 
> Regards
> S.Ahalya
> "Be nice to people on your way up because you meet
> them on your way down." 
> - Jimmy Durante
> 
> 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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.