Subject: Re: [xsl] replacing selective p tags with tags with attributes From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 18 Apr 2013 23:02:45 -0400 |
Hey guys,
I have an xml file with many p tags --
INPUT -- ... 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 ... 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.
T:\ftemp>type arkle.xml <?xml version="1.0" encoding="UTF-8"?> <test> <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> </test>
T:\ftemp>call xslt arkle.xml arkle.xsl <?xml version="1.0" encoding="utf-8"?><test> <p channel="y"> <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 channel="y"> <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> </test> T:\ftemp>type arkle.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="p[inline-img]"> <p channel="y"> <xsl:apply-templates/> </p> </xsl:template>
<xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
</xsl:stylesheet> T:\ftemp>rem Done!
-- Contact us for world-wide XML consulting and instructor-led training | Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm | Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ | G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx | Google+ profile: https://plus.google.com/116832879756988317389/about | Legal business disclaimers: http://www.CraneSoftwrights.com/legal |
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] replacing selective p tags wi, strip513 . | Thread | Re: [xsl] replacing selective p tag, Dimitre Novatchev |
[xsl] replacing selective p tags wi, strip513 . | Date | Re: [xsl] replacing selective p tag, Dimitre Novatchev |
Month |