1

Have a RSS feed xml file

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
    <channel>
        <item>
            <title>news title 1</title>
            <link>http://URL</link>
            <description>
                <div><b>Article_Title:</b> AAAAA</div>
                <div><b>Article_Summary:</b> AAAAAA</div>
                <div><b>Article_Date:</b> 05/08/2013</div>
            </description>
            <author>QWERT</author>
            <pubDate>Mon, 27 May 2013 16:13:50 GMT</pubDate>
            <guid isPermaLink="true">http://URL</guid>
        </item>
        <item>
            <title>news title 2</title>
            <link>http://URL</link>
            <description>
                <div><b>Article_Title:</b>BBB</div>
                <div><b>Article_Summary:</b>BBB</div>
                <div><b>Article_Date:</b> 05/10/2013</div>
            </description>
            <author>ASDF</author>
            <pubDate>Tue, 28 May 2013 09:50:51 GMT</pubDate>
            <guid isPermaLink="true">http://URL</guid>
        </item>
    </channel>
</rss>

This RSS Feed XML file is residing at server. I am fetching this XML and want to do some changes to <description> tags using XSL.

All this should happen at the client side. So i want to do changes to the original RSS feed file at the client side.

Is it possible to change the original file using XSL.

Thanks in advance.

Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
KrankyCode
  • 441
  • 1
  • 8
  • 24
  • Possible duplicate of - http://stackoverflow.com/questions/6578154/can-you-use-jquery-to-transfrom-xml-to-xml-via-xslt ? – adhocgeek Jun 14 '13 at 08:40

1 Answers1

0

Use importStylesheet to grab the .xsl file plus the transformToFragment methods of the XSLTProcessor JavaScript API:

function transform()
  {
  var nameOfPage = var value=RegExp("nameOfPage[^&]+").exec(window.location.search)[0].replace(/[^=]+./,"");

  with (new XSLTProcessor)
     {
     setParameter(null, "nameOfPage", nameOfPage);
     importStylesheet("foo.xsl");
     transform.result = transformToFragment(this, document);
     transform.root = transform.result.xml;
     document.getElementById(appendTo).appendChild(transform.root);
     }
  }

where foo.xsl is something like this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" version="" indent="yes" standalone="no" media-type="text/html" omit-xml-declaration="no" doctype-system="about:legacy-compat" />

<xsl:template match='//channel'>
 <page>
  <content>
   <module>
    <header layout="simple">
     <layout-items>
      <block class="title">YDN Widget</block>
     </layout-items>
    </header>
   </module>
   <xsl:apply-templates select="item" />
  </content>
 </page>
</xsl:template>

</xsl:stylesheet>

to apply the XSLT and append the transformed result to your document.

References

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265