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

replacing selective p tags with tags with attributes

Subject: replacing selective p tags with tags with attributes
From: "strip513 ." <arkle.ash@xxxxxxxxx>
Date: Thu, 18 Apr 2013 22:38:40 -0400
 replacing selective p tags with tags with attributes
        Hey guys,

        I have an xml file with many p tags --

        INPUT --

        <p>
              <inline-img class="full">
                <web-main-photo>
                  <photo src="http://yahoo.com/test.jpg"/>
                </web-main-photo>
                <data>
                  <br/>
                  <caption>
                    <p> (Nick Wass/Associated Press)</p>
                  </caption>
                </data>
              </inline-img>
            </p>
            <p>this is content </p>
            <p>After missing the past three games with an injured left
leg, Martin Erat will return to the <a href="/blog/">Capitals</a>'
lineup Saturday night at Verizon Center against the Tampa Bay
Lightning.</p>
            <p>Erat, 31, suffered the injury on April 6 at Florida
when Panthers defenseman Erik Gudbranson delivered a late hit from
behind that sent the veteran winger awkwardly into the boards. He
avoided significant harm, though, and after five consecutive days of
skating Erat said he's prepared to get back to game action.</p>
        <p>
              <inline-img class="full">
                <web-main-photo>
                  <photo src="http://yahoo.com/test.jpg"/>
                </web-main-photo>
                <data>
                  <br/>
                  <caption>
                    <p> (Nick Wass/Associated Press)</p>
                  </caption>
                </data>
              </inline-img>
            </p>
            <p>"Feeling good. Feels better every day, I'm pretty much
ready to go," Erat said, adding that while he would have much rather
been playing games with his new team the time to take part in practice
and watch the system work from above should help him make a smooth
transition.</p>


        INPUT ENDS HERE

        I want all the p tags which are above inline img class to be
replaced by <p channel="y.com"> and it will look like

        <p channel="y.com">
          <inline-img class="full">
                <web-main-photo>
                  <photo src="http://yahoo.com/test.jpg"/>
                </web-main-photo>
                <data>
                  <br/>
                  <caption>
                    <p> (Nick Wass/Associated Press)</p>
                  </caption>
                </data>
              </inline-img>
            </p>

        I dont want to replace any other normal p tags.So, in this
particular example find and replace will happen at two places.

        I used this code,but it is not working.Please advise.Thanks.

        XSLT CODE using xslt 1.0




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

                    <p>
                        <xsl:call-template name="replace-text">
                                <xsl:with-param name="text"
select="/item/content" />
                                <xsl:with-param name="replace"
select="'&lt;p&gt;&lt;inline-img class='" />
                                <xsl:with-param name="by"
select="'&lt;p channel="y.com"&gt;&lt;inline-img class='" />
                        </xsl:call-template>
                    </p>

            </component>
        </xsl:template>

        <xsl:template name="replace-text">
           <xsl:param name="text"/>
           <xsl:param name="replace" />
           <xsl:param name="by" />

           <xsl:choose>
           <xsl:when test="contains($text, $replace)">
              <xsl:value-of select="substring-before($text, $replace)"/>
              <xsl:value-of select="$by" disable-output-escaping="yes"/>
              <xsl:call-template name="replace-text">
                 <xsl:with-param name="text"
select="substring-after($text, $replace)"/>
                 <xsl:with-param name="replace" select="$replace" />
                 <xsl:with-param name="by" select="$by" />
              </xsl:call-template>
           </xsl:when>
           <xsl:otherwise>
              <xsl:value-of select="$text"/>
           </xsl:otherwise>
           </xsl:choose>
        </xsl:template>
        </xsl:stylesheet>

    Thanks so much for your help.I really appreciate it.

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.