<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Script Tutorials &#187; XSLT | Script Tutorials | Web development</title> <atom:link href="http://www.script-tutorials.com/category/xslt/feed/" rel="self" type="application/rss+xml" /><link>http://www.script-tutorials.com</link> <description>Tutorials for Web Developers</description> <lastBuildDate>Fri, 03 Feb 2012 06:07:51 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>How to easily make animated forums using XSLT and Ajaxy</title><link>http://www.script-tutorials.com/creating-ajaxy-forums-using-xslt/</link> <comments>http://www.script-tutorials.com/creating-ajaxy-forums-using-xslt/#comments</comments> <pubDate>Fri, 15 Apr 2011 17:18:49 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[AJAX]]></category> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[XSLT]]></category> <category><![CDATA[ajaxy]]></category> <category><![CDATA[animated]]></category> <category><![CDATA[creating]]></category> <category><![CDATA[forums]]></category> <category><![CDATA[making]]></category> <category><![CDATA[xslt]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=529</guid> <description><![CDATA[How to easily make animated forums using XSLT and Ajaxy Today is a special day. Today our XSLT lessons will show some really interesting (attractive) results which you can apply in practice. We will make a forum. Initially we will display only the forum topics, and load posts dynamically (by mouse clicking on the topics) [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> How to Easily display Your Stumbleupon Favorites using XSLT</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> How to Easily display Delicious bookmarks using XSLT transformation</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="Ajaxy forum using XSLT" alt="Ajaxy forum using XSLT" src="http://www.script-tutorials.com/demos/58/thumb.png"></div><p><strong>How to easily make animated forums using XSLT and Ajaxy</strong><br
/> <br
/>Today is a special day. Today our XSLT lessons will show some really interesting (attractive) results which you can apply in practice. We will make a forum. Initially we will display only the forum topics, and load posts dynamically (by mouse clicking on the topics) using ajax technology. I think you may have seen similar forums on the Internet, so I will tell you how to do it your own.<br
/> <span
id="more-529"></span></p><p>Here are samples and downloadable package:</p><h5 style="text-align: center;"><strong><a
title="Creating animated forums using XSLT - demo 58" href="http://www.script-tutorials.com/demos/58/index.php" target="_blank">Forum Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Creating animated forums using XSLT - demo 58" href="http://www.script-tutorials.com/demos/58/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Ok, download the source files and lets start coding !</p><hr
/><h3>Step 1. Source XML</h3><p>Firstly lets define our structure of forum:</p><h4>forum.xml</h4><pre class="brush:xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;forum&gt;
    &lt;topic title=&quot;XSLT forum demonstration&quot; date=&quot;15.04.2011&quot; description=&quot;description can be here&quot;&gt;
        &lt;post date=&quot;15.04.2011&quot; author=&quot;Diego&quot;&gt;
            &lt;description&gt;&lt;![CDATA[
            This forum able to display any HTML entities
            ]]&gt;&lt;/description&gt;
        &lt;/post&gt;
        &lt;post date=&quot;15.04.2011&quot; author=&quot;Andrew&quot;&gt;
            &lt;description&gt;&lt;![CDATA[
            As example &lt;b&gt;bold text&lt;/b&gt;, &lt;i&gt;italic&lt;/i&gt;, &lt;u&gt;underline&lt;/u&gt;, &lt;a href=&quot;http://www.google.com&quot;&gt;links&lt;/a&gt; etc
            ]]&gt;&lt;/description&gt;
        &lt;/post&gt;
        &lt;post date=&quot;15.04.2011&quot; author=&quot;James&quot;&gt;
            &lt;description&gt;&lt;![CDATA[
            &lt;p&gt;Some HTML description 3, &lt;a href=&quot;http://www.google.com&quot;&gt;links&lt;/a&gt; etc
            ]]&gt;&lt;/description&gt;
        &lt;/post&gt;
        &lt;post date=&quot;15.04.2011&quot; author=&quot;John&quot;&gt;
            &lt;description&gt;&lt;![CDATA[
            Hello guys here
            ]]&gt;&lt;/description&gt;
        &lt;/post&gt;
        &lt;post date=&quot;15.04.2011&quot; author=&quot;Robert&quot;&gt;
            &lt;description&gt;&lt;![CDATA[
            Wonderful forum, isn`t it?
            ]]&gt;&lt;/description&gt;
        &lt;/post&gt;
    &lt;/topic&gt;
    &lt;topic title=&quot;sample forum topic 2&quot; date=&quot;16.04.2011&quot; description=&quot;description of topic 2&quot;&gt;
        &lt;post date=&quot;16.04.2011&quot; author=&quot;Michael&quot;&gt;
            &lt;description&gt;&lt;![CDATA[
            sample record 1
            ]]&gt;&lt;/description&gt;
        &lt;/post&gt;
        &lt;post date=&quot;16.04.2011&quot; author=&quot;William&quot;&gt;
            &lt;description&gt;&lt;![CDATA[
            sample record 2
            ]]&gt;&lt;/description&gt;
        &lt;/post&gt;
        &lt;post date=&quot;16.04.2011&quot; author=&quot;David&quot;&gt;
            &lt;description&gt;&lt;![CDATA[
            sample record 3
            ]]&gt;&lt;/description&gt;
        &lt;/post&gt;
    &lt;/topic&gt;
    &lt;topic title=&quot;sample forum topic 3&quot; date=&quot;17.04.2011&quot; description=&quot;description of topic 3&quot;&gt;
        &lt;post date=&quot;17.04.2011&quot; author=&quot;Charles&quot;&gt;
            &lt;description&gt;&lt;![CDATA[
            sample record 3.1
            ]]&gt;&lt;/description&gt;
        &lt;/post&gt;
        &lt;post date=&quot;17.04.2011&quot; author=&quot;Joseph&quot;&gt;
            &lt;description&gt;&lt;![CDATA[
            sample record 3.2
            ]]&gt;&lt;/description&gt;
        &lt;/post&gt;
    &lt;/topic&gt;
&lt;/forum&gt;
</pre><p>Forum contain several topics, each topic can contain variable amount of posts. Each post have name of Author, date of posting, and, text itself (Description) can contain HTML tags.</p><h3>Step 2. PHP</h3><p>Here are easy PHP file which we using for xsl transformation:</p><h4>index.php</h4><pre class="brush:php">
&lt;?php

if (version_compare(phpversion(), &quot;5.3.0&quot;, &quot;&gt;=&quot;)  == 1)
  error_reporting(E_ALL &amp; ~E_NOTICE &amp; ~E_DEPRECATED);
else
  error_reporting(E_ALL &amp; ~E_NOTICE); 

// create DomDocument and load our forum
$xml = new DOMDocument;
$xml-&gt;load('forum.xml');

$xsl = new DOMDocument;

switch ($_POST['action']) {
    case 'posts':
        $xsl-&gt;load('xslt/posts.xslt'); // importing xslt
        $proc = new XSLTProcessor; // creating xslt processor
        $proc-&gt;importStyleSheet($xsl); // attaching xsl rules
        $proc-&gt;setParameter('', 'topic_id', (int)$_POST['i']); // we will set param for XSL
        break;
    default:
        $xsl-&gt;load('xslt/forum.xslt'); // importing xslt
        $proc = new XSLTProcessor; // creating xslt processor
        $proc-&gt;importStyleSheet($xsl); // attaching xsl rules
        break;
}

echo $proc-&gt;transformToXML($xml); // output

?&gt;
</pre><p>Make attention to switch-case. For ajax response (when we clicking to our topics) I using first switch case (when action = posts). To determine which messages we will display (filter) I will pass ID of topic (topic_id) to our XSL script.</p><h3>Step 3. CSS</h3><p>Here are used CSS file:</p><h4>css/styles.css</h4><pre class="brush:css">
body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.main{background:#FFF;width:698px;min-height:500px;overflow:hidden;border:1px #000 solid;margin:3.5em auto 2em;padding:1em 2em 2em}

p{margin:0;padding:0}
.forum{border:1px solid #B0BBCD}
.forum .header{color:#fff;background-color:#545F6F;padding:5px}
.forum .topic{border-bottom:2px solid #B0BBCD;background-color:#F3F2EF;padding:5px}
.forum .topic .desc{margin-left:30px;font-size:12px;color:#444}
.forum .topic .posts{border-top:1px solid #B0BBCD;display:none;margin-top:10px;padding:10px}
.forum .topic .posts .post{border-bottom:1px solid #B0BBCD;margin:5px}
.forum .post .date{font-size:10px;color:#444;text-align:right}
</pre><p>Here are several styles of our forum &#8211; styles for topics, posts etc.</p><h3>Step 4. JS</h3><p>Here are used JS files:</p><h4>js/jquery.min.js</h4><p>This is just jQuery library, available in package.</p><h4>js/main.js</h4><pre class="brush:js">
function loadPosts(obj, i) {
    $('.topic#'+i+' .posts').load('index.php',
      {action: 'posts', i: i},
      function() {
        $(this).fadeIn('slow');

        obj.unbind('click');
        obj.click(function(e) {
            $('.topic#'+i+' .posts').slideToggle('slow');
        });
      }
    );
}

$(function(){
    $('.topic').click(function() {
        loadPosts( $(this), $(this).attr('id') );
    });
});
</pre><p>When page loaded &#8211; I linking onClick events to our forum topics. After, when we clicking to Topic element, I using $.load to load posts of this Topic. And, unbind old onClick functional (we don`t will need to load this content twice), and adding new onClick event, which will toggle slide of these posts.</p><h3>Step 5. XSLT</h3><p>And, the delicacy &#8211; used XSLT rules:</p><h4>xslt/forum.xslt</h4><pre class="brush:xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
    &lt;xsl:output method=&quot;html&quot; doctype-system=&quot;http://www.w3.org/TR/html4/strict.dtd&quot; doctype-public=&quot;-//W3C//DTD HTML 4.01//EN&quot; indent=&quot;yes&quot; /&gt;
    &lt;xsl:template match=&quot;/&quot;&gt;
        &lt;html xml:lang=&quot;en&quot;&gt;
            &lt;head&gt;
                &lt;script src=&quot;js/jquery.min.js&quot; type=&quot;text/javascript&quot;&gt;&gt;&lt;/script&gt;
                &lt;script src=&quot;js/main.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
                &lt;link media=&quot;all&quot; href=&quot;css/styles.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;/&gt;
                &lt;title&gt;Our XSLT-based ajaxy forum&lt;/title&gt;
            &lt;/head&gt;
            &lt;body&gt;
                &lt;div class=&quot;main&quot;&gt;
                    &lt;h2&gt;Our XSLT-based ajaxy forum&lt;/h2&gt;
                    &lt;div class=&quot;forum&quot;&gt;
                        &lt;div class=&quot;header&quot;&gt;Forum topics&lt;/div&gt;
                        &lt;xsl:for-each select=&quot;forum/topic&quot;&gt;
                            &lt;div class=&quot;topic&quot;&gt;
                                &lt;xsl:attribute name=&quot;id&quot;&gt;
                                    &lt;xsl:value-of select=&quot;position()&quot;/&gt;
                                &lt;/xsl:attribute&gt;

                                &lt;a class=&quot;top_link&quot; href=&quot;javascript:void(0)&quot;&gt;
                                    &lt;xsl:value-of select=&quot;@title&quot;/&gt; (&lt;xsl:value-of select=&quot;count(child::*)&quot;/&gt;)
                                &lt;/a&gt;
                                &lt;div class=&quot;desc&quot;&gt;
                                    &lt;xsl:value-of select=&quot;@description&quot;/&gt;
                                &lt;/div&gt;
                                &lt;div class=&quot;posts&quot;&gt;&lt;/div&gt;
                            &lt;/div&gt;
                        &lt;/xsl:for-each&gt;

                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;xsl:comment&gt;Copyright: AndrewP&lt;/xsl:comment&gt;
            &lt;/body&gt;
        &lt;/html&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre><p>As you can see, here we generating our main forum, and drawing only topics now. We will load posts ajaxy fr each Topic using jQuery, nice, isn`t is?</p><h4>xslt/posts.xslt</h4><pre class="brush:xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
    &lt;xsl:template match=&quot;/&quot;&gt;
        &lt;xsl:for-each select=&quot;forum/topic[position() = $topic_id]/*&quot;&gt;
            &lt;div class=&quot;post&quot;&gt;
                &lt;xsl:attribute name=&quot;id&quot;&gt;
                    &lt;xsl:value-of select=&quot;position()&quot;/&gt;
                &lt;/xsl:attribute&gt;
                &lt;xsl:value-of select=&quot;description&quot; disable-output-escaping=&quot;yes&quot;/&gt;
                &lt;div class=&quot;date&quot;&gt;
                    posted at &lt;xsl:value-of select=&quot;@date&quot;/&gt; by &lt;xsl:value-of select=&quot;@author&quot;/&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/xsl:for-each&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre><p>Second XSL file we will use to generate list of posts for requested Topic. Hope that you don`t forget that we will request it ajaxy? We already passed $topic_id variable into this XSL above (in PHP code). So, we just should display all child &#8216;posts&#8217; of our Topic.</p><hr
/><h5 style="text-align: center;"><strong><a
title="Creating animated forums using XSLT - demo 58" href="http://www.script-tutorials.com/demos/58/index.php" target="_blank" rel="nofollow">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Creating animated forums using XSLT - demo 58" href="http://www.script-tutorials.com/demos/58/source.zip" target="_blank" rel="nofollow">download in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>I hope that today&#8217;s article was very interesting, and I hope that interest to XSL language has not dried up <img
src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> Good luck!</p><div
class="shr-publisher-529"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> <br
/> How to Easily display Your Stumbleupon Favorites using XSLT</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> <br
/> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> <br
/> How to Easily display Delicious bookmarks using XSLT transformation</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/creating-ajaxy-forums-using-xslt/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Creating a Multilevel Menu using XSLT</title><link>http://www.script-tutorials.com/creating-multilevel-menu-using-xslt/</link> <comments>http://www.script-tutorials.com/creating-multilevel-menu-using-xslt/#comments</comments> <pubDate>Mon, 11 Apr 2011 20:52:52 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[XSLT]]></category> <category><![CDATA[creating]]></category> <category><![CDATA[css]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[menu]]></category> <category><![CDATA[multileve]]></category> <category><![CDATA[xslt]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=510</guid> <description><![CDATA[Creating multilevel menu using XSLT Today we continue the practice of using XSLT. And lets consider a very entertaining task &#8211; the creation of navigation menu through XSL transformations. Someone will think that this is a fairly simple task, but we complicate it in advance &#8211; the menu should be multilevel. That is mean an [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/css3-metal-menu-with-icons/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/152/thumb.png" alt="Creating a Multilevel CSS3 Metal Navigation with icons" /> Creating a Multilevel CSS3 Metal Navigation with icons</a></li><li> <a
href="http://www.script-tutorials.com/creating-css3-dropdown-menu-2/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/91/thumb.png" alt="Creating a CSS3 Dropdown Menu #2" /> Creating a CSS3 Dropdown Menu #2</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> How to Easily display Your Stumbleupon Favorites using XSLT</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="Creating a multilevel menu using xslt" alt="Creating a multilevel menu using xslt" src="http://www.script-tutorials.com/demos/53/thumb.png"></div><p><strong>Creating multilevel menu using XSLT</strong><br
/> <br
/>Today we continue the practice of using XSLT. And lets consider a very entertaining task &#8211; the creation of navigation menu through XSL transformations. Someone will think that this is a fairly simple task, but we complicate it in advance &#8211; the menu should be multilevel. That is mean an unlimited number of sublevels. As initial data we will have an XML file with defined structure. At the output we will expect our multi-level drop-down menu.<br
/> <span
id="more-510"></span></p><p>Here are samples and downloadable package:</p><h5 style="text-align: center;"><strong><a
title="Creating multilevel menu using XSLT - demo 53" href="http://www.script-tutorials.com/demos/53/index.php" target="_blank">Live Menu Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Creating multilevel menu using XSLT - demo 53" href="http://www.script-tutorials.com/demos/53/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Ok, download the source files and lets start coding !</p><hr
/><h3>Step 1. Source XML</h3><p>Firstly lets define our structure of initial menu:</p><h4>menu.xml</h4><pre class="brush:xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;menu&gt;
    &lt;top title=&quot;Element 1&quot; url=&quot;#&quot;&gt;
        &lt;link title=&quot;subelement 1#1&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
        &lt;link title=&quot;subelement 1#2&quot; url=&quot;#&quot;&gt;
            &lt;link title=&quot;subelement 1#2#1&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
            &lt;link title=&quot;subelement 1#2#2&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
            &lt;link title=&quot;subelement 1#2#3&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
        &lt;/link&gt;
        &lt;link title=&quot;subelement 1#3&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
    &lt;/top&gt;
    &lt;top title=&quot;Element 2&quot; url=&quot;#&quot;&gt;
        &lt;link title=&quot;subelement 2#1&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
        &lt;link title=&quot;subelement 2#2&quot; url=&quot;#&quot;&gt;
            &lt;link title=&quot;subelement 2#2#1&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
            &lt;link title=&quot;subelement 2#2#2&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
            &lt;link title=&quot;subelement 2#2#3&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
        &lt;/link&gt;
        &lt;link title=&quot;subelement 2#3&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
    &lt;/top&gt;
    &lt;top title=&quot;Element 3&quot; url=&quot;#&quot;&gt;
        &lt;link title=&quot;subelement 3#1&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
        &lt;link title=&quot;subelement 3#2&quot; url=&quot;#&quot;&gt;
            &lt;link title=&quot;sub 3#2#1&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
            &lt;link title=&quot;sub 3#2#2&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
            &lt;link title=&quot;sub 3#2#3&quot; url=&quot;#&quot;&gt;
                &lt;link title=&quot;sub 3#2#3#1&quot; url=&quot;#&quot;&gt;
                    &lt;link title=&quot;sub 1&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
                    &lt;link title=&quot;sub 2&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
                    &lt;link title=&quot;sub 3&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
                &lt;/link&gt;
                &lt;link title=&quot;sub 3#2#3#2&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
                &lt;link title=&quot;sub 3#2#3#3&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
            &lt;/link&gt;
        &lt;/link&gt;
        &lt;link title=&quot;subelement 3#3&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
    &lt;/top&gt;
    &lt;top title=&quot;Element 4&quot; url=&quot;#&quot;&gt;
        &lt;link title=&quot;subelement 4#1&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
        &lt;link title=&quot;subelement 4#2&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
        &lt;link title=&quot;subelement 4#3&quot; url=&quot;#&quot;&gt;&lt;/link&gt;
    &lt;/top&gt;
&lt;/menu&gt;
</pre><h3>Step 2. PHP</h3><p>Here are easy PHP file which we using for xsl transformation:</p><h4>index.php</h4><pre class="brush:php">
&lt;?php

// create DomDocument and load our menu
$xml = new DOMDocument;
$xml-&gt;load('menu.xml');

$xsl = new DOMDocument;
$xsl-&gt;load('xslt/template.xslt'); // importing xslt

$proc = new XSLTProcessor; // creating xslt processor
$proc-&gt;importStyleSheet($xsl); // attaching xsl rules
echo $proc-&gt;transformToXML($xml); // output

?&gt;
</pre><h3>Step 3. CSS</h3><p>Here are used CSS file. It contain CSS of our future menu too:</p><h4>css/styles.css</h4><pre class="brush:css">
body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.main{background:#FFF;width:698px;height:440px;font-size:80%;border:1px #000 solid;margin:3.5em auto 2em;padding:1em 2em 2em}
#background {background:url(paper.jpg);}

/*menu styles*/
.preload1 {background: url(tab.png);}
.preload2 {background: url(tabb_on.png);}

.menu2 {padding:0 0 0 32px; margin:0; list-style:none; height:36px; position:relative; z-index:500; font-family:arial, verdana, sans-serif;}
.menu2 li.top {display:block; float:left;}
.menu2 li a.top_link {display:block; float:left; height:36px; color:#444; text-decoration:none; }

.menu2 li a.top_link span {display:block; height:36px; float:left; line-height:27px; font-size:11px; font-weight:bold; padding:0 10px; cursor:pointer; background: url(tab_off.png) no-repeat;}
.menu2 li a.top_link b {display:block; width:15px; height:36px; float:left; background: url(tabb_off.png) no-repeat;}
.menu2 li a.top_link b.down {background: url(tabdown_off.png) no-repeat;}

.menu2 li a.top_link:hover span {color:#fff; background: url(tab.png) no-repeat; line-height:26px;}
.menu2 li a.top_link:hover b {color:#fff; background: url(tabb_on.png) no-repeat;}

.menu2 li:hover &gt; a.top_link span {color:#fff; background: url(tab.png) no-repeat; line-height:26px;}
.menu2 li:hover &gt; a.top_link b {color:#fff; background: url(tabb_on.png) no-repeat;}
.menu2 li:hover &gt; a.top_link b.down {color:#fff; background: url(tabdown_on.png) no-repeat;}

.menu2 table {border-collapse:collapse; width:0; height:0; position:absolute; top:0; left:0;}

/* Default link styling */

/* Style the list OR link hover. Depends on which browser is used */
.menu2 a:hover {visibility:visible; position:relative; z-index:200;}
.menu2 li:hover {position:relative; z-index:200;}

/* keep the 'next' level invisible by placing it off screen. */
.menu2 ul,
.menu2 :hover ul ul,
.menu2 :hover ul :hover ul ul,
.menu2 :hover ul :hover ul :hover ul ul,
.menu2 :hover ul :hover ul :hover ul :hover ul ul {position:absolute; left:-9999px; top:-9999px; width:0; height:0; margin:0; padding:0; list-style:none;}

.menu2 :hover ul.sub {left:0; top:32px; white-space:nowrap; width:120px; height:auto; z-index:300;}
.menu2 :hover ul.sub li {display:block; height:20px; float:left; width:120px; font-weight:normal; background: url(submid.png);}
.menu2 :hover ul.sub li.fly {background: url(submid_r.png);}

.menu2 :hover ul.sub li a {display:block; position:relative; font-size:11px; height:20px; width:120px; line-height:20px; text-indent:10px; color:#000; text-decoration:none;background:url(trans.gif);}
.menu2 :hover ul.sub li a:hover {color:#fff;}

.menu2 :hover ul.sub :hover &gt; a {color:#fff;}

.menu2 :hover ul :hover ul,
.menu2 :hover ul :hover ul :hover ul,
.menu2 :hover ul :hover ul :hover ul :hover ul,
.menu2 :hover ul :hover ul :hover ul :hover ul :hover ul
{left:120px; top:0; white-space:nowrap; width:120px; z-index:400; height:auto;}

.menu2 :hover ul.sub li.subtop,
.menu2 :hover ul :hover ul li.subtop,
.menu2 :hover ul :hover ul :hover ul li.subtop,
.menu2 :hover ul :hover ul :hover ul :hover ul li.subtop
{background:url(subtop.png);}

.menu2 :hover ul.sub li.flytop,
.menu2 :hover ul :hover ul li.flytop,
.menu2 :hover ul :hover ul :hover ul li.flytop,
.menu2 :hover ul :hover ul :hover ul :hover ul li.flytop
{background: url(subtop_r.png);}

.menu2 :hover ul.sub li.subbot,
.menu2 :hover ul :hover ul li.subbot,
.menu2 :hover ul :hover ul :hover ul li.subbot,
.menu2 :hover ul :hover ul :hover ul :hover ul li.subbot
{height:30px; background:url(subbottom.png);}

.menu2 :hover ul.sub li.flybot,
.menu2 :hover ul :hover ul li.flybot,
.menu2 :hover ul :hover ul :hover ul li.flybot,
.menu2 :hover ul :hover ul :hover ul :hover ul li.flybot
{height:30px; background: url(subbottom_r.png);}
</pre><p>As you can see &#8211; menu itself using some images, and I not sure that need put it in our article &#8211; they always will available in our downloadable package.</p><h3>Step 4. XSLT</h3><p>And, the delicacy &#8211; used XSLT rules:</p><h4>xslt/template.xslt</h4><pre class="brush:xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
    &lt;xsl:output method=&quot;html&quot; doctype-system=&quot;http://www.w3.org/TR/html4/strict.dtd&quot; doctype-public=&quot;-//W3C//DTD HTML 4.01//EN&quot; indent=&quot;yes&quot; /&gt;
    &lt;xsl:template match=&quot;/&quot;&gt;
        &lt;html xml:lang=&quot;en&quot;&gt;
            &lt;head&gt;
                &lt;link media=&quot;all&quot; href=&quot;css/styles.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;/&gt;
            &lt;/head&gt;
            &lt;body&gt;
                &lt;div class=&quot;main&quot; id=&quot;background&quot;&gt;

                    &lt;!-- The menu starts here --&gt;
                    &lt;ul class=&quot;menu2&quot;&gt;
                        &lt;xsl:for-each select=&quot;menu/top&quot;&gt;
                            &lt;li class=&quot;top&quot;&gt;
                                &lt;a class=&quot;top_link&quot;&gt;
                                    &lt;xsl:attribute name=&quot;href&quot;&gt;
                                        &lt;xsl:value-of select=&quot;@url&quot;/&gt;
                                    &lt;/xsl:attribute&gt;
                                    &lt;span&gt;
                                        &lt;xsl:value-of select=&quot;@title&quot;/&gt;
                                    &lt;/span&gt;
                                    &lt;b&gt;
                                      &lt;xsl:if test=&quot;count(link) &gt; 0&quot;&gt;
                                        &lt;xsl:attribute name=&quot;class&quot;&gt;down&lt;/xsl:attribute&gt;
                                      &lt;/xsl:if&gt;
                                    &lt;/b&gt;
                                &lt;/a&gt;

                                &lt;xsl:call-template name=&quot;nested_levels&quot;&gt;
                                    &lt;xsl:with-param name=&quot;level&quot; select=&quot;1&quot;/&gt;
                                &lt;/xsl:call-template&gt;

                            &lt;/li&gt;
                        &lt;/xsl:for-each&gt;
                    &lt;/ul&gt;
                &lt;/div&gt;
                &lt;xsl:comment&gt;Copyright: AndrewP&lt;/xsl:comment&gt;
                &lt;hr style=&quot;clear:both;&quot; /&gt;
                &lt;h4&gt;
                    &lt;a href=&quot;http://www.script-tutorials.com/creating-multilevel-menu-using-xslt/&quot;&gt;back to original article page&lt;/a&gt;
                &lt;/h4&gt;
            &lt;/body&gt;
        &lt;/html&gt;
    &lt;/xsl:template&gt;

    &lt;xsl:template name=&quot;nested_levels&quot;&gt;
        &lt;xsl:param name=&quot;level&quot; select=&quot;0&quot;/&gt;
        &lt;xsl:if test=&quot;count(link) &gt; 0&quot;&gt;
            &lt;ul&gt;
                &lt;xsl:if test=&quot;$level = 1&quot;&gt;
                    &lt;xsl:attribute name=&quot;class&quot;&gt;sub&lt;/xsl:attribute&gt;
                &lt;/xsl:if&gt;

                &lt;xsl:for-each select=&quot;link&quot;&gt;
                    &lt;li&gt;
                        &lt;xsl:choose&gt;
                        &lt;xsl:when test=&quot;count(link) = 0 and position()=1&quot;&gt;
                            &lt;xsl:attribute name=&quot;class&quot;&gt;subtop&lt;/xsl:attribute&gt;
                        &lt;/xsl:when&gt;
                        &lt;xsl:when test=&quot;count(link) &amp;gt; 0 and position()=1&quot;&gt;
                            &lt;xsl:attribute name=&quot;class&quot;&gt;flytop&lt;/xsl:attribute&gt;
                        &lt;/xsl:when&gt;
                        &lt;xsl:when test=&quot;count(link) &amp;gt; 0 and not(position()=last())&quot;&gt;
                            &lt;xsl:attribute name=&quot;class&quot;&gt;fly&lt;/xsl:attribute&gt;
                        &lt;/xsl:when&gt;
                        &lt;xsl:when test=&quot;count(link) = 0 and position()=last()&quot;&gt;
                            &lt;xsl:attribute name=&quot;class&quot;&gt;subbot&lt;/xsl:attribute&gt;
                        &lt;/xsl:when&gt;
                        &lt;xsl:when test=&quot;count(link) &amp;gt; 0 and position()=last()&quot;&gt;
                            &lt;xsl:attribute name=&quot;class&quot;&gt;flybot&lt;/xsl:attribute&gt;
                        &lt;/xsl:when&gt;
                        &lt;xsl:otherwise&gt;&lt;/xsl:otherwise&gt;
                        &lt;/xsl:choose&gt;

                        &lt;a&gt;
                            &lt;xsl:attribute name=&quot;href&quot;&gt;
                                &lt;xsl:value-of select=&quot;@url&quot;/&gt;
                            &lt;/xsl:attribute&gt;
                            &lt;xsl:value-of select=&quot;@title&quot;/&gt;
                            &lt;xsl:value-of select=&quot;$level&quot;/&gt;
                        &lt;/a&gt;

                        &lt;xsl:call-template name=&quot;nested_levels&quot;&gt;
                            &lt;xsl:with-param name=&quot;level&quot; select=&quot;$level + 1&quot;/&gt;
                        &lt;/xsl:call-template&gt;

                    &lt;/li&gt;
                &lt;/xsl:for-each&gt;
            &lt;/ul&gt;
        &lt;/xsl:if&gt;
    &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;
</pre><p>This script will generate full HTML of page, with including css styles, defining doctype etc. I hope that most of code is pretty understandable, note one point &#8211; to provide multilevel support I made special template &#8216;nested_levels&#8217; which I using to generate code for inner sublevels in recursion, so you can have even 5 or 10 sublevels if you want.</p><hr
/><h5 style="text-align: center;"><strong><a
title="Creating multilevel menu using XSLT - demo 53" href="http://www.script-tutorials.com/demos/53/index.php" target="_blank" rel="nofollow">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Creating multilevel menu using XSLT - demo 53" href="http://www.script-tutorials.com/demos/53/source.zip" target="_blank" rel="nofollow">download in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>I hope that today&#8217;s article was very interesting, and possible you even will change your oppinion about using xsl in your projects, anyway &#8211; this is good practic for our brains to play with xsl. Good luck!</p><div
class="shr-publisher-510"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/css3-metal-menu-with-icons/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/152/thumb.png" alt="Creating a Multilevel CSS3 Metal Navigation with icons" /> <br
/> Creating a Multilevel CSS3 Metal Navigation with icons</a></li><li> <a
href="http://www.script-tutorials.com/creating-css3-dropdown-menu-2/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/91/thumb.png" alt="Creating a CSS3 Dropdown Menu #2" /> <br
/> Creating a CSS3 Dropdown Menu #2</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> <br
/> How to Easily display Your Stumbleupon Favorites using XSLT</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/creating-multilevel-menu-using-xslt/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>How to Easily display Delicious bookmarks using XSLT transformation</title><link>http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/</link> <comments>http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/#comments</comments> <pubDate>Fri, 01 Apr 2011 16:59:56 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[XSLT]]></category> <category><![CDATA[deliciuos bookmarks]]></category> <category><![CDATA[display]]></category> <category><![CDATA[show]]></category> <category><![CDATA[user]]></category> <category><![CDATA[xslt]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=476</guid> <description><![CDATA[How to Easily display Delicious bookmarks using XSLT transformation Today we will create application which will show our Delicious bookmarks. We will use XSLT transformation to parse XML provided by Delicious. I will using my profile for our sample. And here are path for my XML feeds: http://feeds.delicious.com/v2/rss/AramisGC. So, we have all for begining. Today [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-youtube-videos-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Youtube videos using XSLT transformation" /> How to Easily display Youtube videos using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> How to Easily display Your Stumbleupon Favorites using XSLT</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="How to Easily display Delicious bookmarks using XSLT transformation" alt="How to Easily display Delicious bookmarks using XSLT transformation" src="http://www.script-tutorials.com/demos/47.png"></div><p><strong>How to Easily display Delicious bookmarks using XSLT transformation</strong><br
/> <br
/>Today we will create application which will show our Delicious bookmarks. We will use <strong>XSLT transformation</strong> to parse XML provided by Delicious. I will using <a
href="http://www.delicious.com/AramisGC" rel="nofollow">my profile</a> for our sample. And here are path for my XML feeds: http://feeds.delicious.com/v2/rss/AramisGC. So, we have all for begining. Today I`ll show you how to display this information in your projects.<br
/> <span
id="more-476"></span></p><p>Here are samples and downloadable package:</p><h5 style="text-align: center;"><strong><a
title="How to Easily display Delicious bookmarks using XSLT transformation - demo 47" href="http://www.script-tutorials.com/demos/47/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Easily display Delicious bookmarks using XSLT transformation - demo 47" href="http://www.script-tutorials.com/demos/47/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Ok, download the source files and lets start coding !</p><hr
/><h3>Step 1. PHP</h3><p>Ok, here are all used PHP files:</p><h4>index.php</h4><p>This file will generate list of Delicious bookmarks. Quite all code commented, so I hope it will easy to understand it.</p><pre class="brush:php">
&lt;?php

$sMethod = 'http://feeds.delicious.com/v2/rss/AramisGC';
$sXmlSrc = getDeliciousXml($sMethod);

// Load the XML source
$xml = new DOMDocument;
$xml-&gt;loadXML($sXmlSrc);

// Load XSLT
$xsl = new DOMDocument;
$xsl-&gt;load('xslt/delicious.xslt');

$proc = new XSLTProcessor; // configure the transformer
$proc-&gt;importStyleSheet($xsl); // attach the xsl rules

echo $proc-&gt;transformToXML($xml);

// this function get delicious information using caches (not more than 1 times per hour)
function getDeliciousXml($sUrl) {
    // our folder with cache files
    $sCacheFolder = 'cache/';

    // cache filename
    $sFilename = date('YmdH').'.xml';

    if (! file_exists($sCacheFolder.$sFilename)) {
        $ch = curl_init($sUrl);
        $fp = fopen($sCacheFolder.$sFilename, 'w');
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15') ); // makes our request look like it was made by Firefox
        curl_exec($ch);
        curl_close($ch);
        fclose($fp);
    }
    return file_get_contents($sCacheFolder.$sFilename);
}

?&gt;
</pre><h3>Step 2. CSS</h3><p>Here are used CSS file. Just few styles for our demo:</p><h4>css/styles.css</h4><pre class="brush:css">
h1{text-align:center}
.dl-unit{background-color:#F3F3F3;border:1px solid #CCC;position:relative;margin:10px;padding:10px}
.dl-unit h3, .dl-unit div{border-bottom:1px dashed #888;padding:5px;overflow:hidden}
.dl-unit div p{float:left;margin-right:20px}
.dl-unit div p:first-child{font-weight:bold}
body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.main{background:#FFF;width:900px;font-size:80%;border:1px #000 solid;margin:3.5em auto 2em;padding:1em 2em 2em}
</pre><h3>Step 3. XSLT</h3><p>And, most interesting part of my story &#8211; used XSLT rules:</p><h4>xslt/delicious.xslt</h4><pre class="brush:xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
    &lt;xsl:template match=&quot;channel&quot;&gt;
        &lt;xsl:variable name=&quot;channelDescription&quot; select=&quot;description&quot;/&gt;
        &lt;xsl:variable name=&quot;authorLink&quot; select=&quot;link&quot;/&gt;
        &lt;html&gt;
            &lt;head&gt;
                &lt;link media=&quot;all&quot; href=&quot;css/styles.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;/&gt;
            &lt;/head&gt;
            &lt;body&gt;
                &lt;div class=&quot;main&quot;&gt;
                &lt;h1&gt;
                    &lt;a&gt;
                        &lt;xsl:attribute name=&quot;href&quot;&gt;
                            &lt;xsl:value-of select=&quot;$authorLink&quot;/&gt;
                        &lt;/xsl:attribute&gt;
                        &lt;xsl:value-of select=&quot;$channelDescription&quot;/&gt;
                    &lt;/a&gt;
                &lt;/h1&gt;
                &lt;xsl:for-each select=&quot;item&quot;&gt;
                    &lt;div class=&quot;dl-unit&quot;&gt;
                        &lt;h3&gt;
                            &lt;a target=&quot;_blank&quot;&gt;
                                &lt;xsl:attribute name=&quot;title&quot;&gt;&lt;xsl:value-of select=&quot;title&quot;/&gt;&lt;/xsl:attribute&gt;
                                &lt;xsl:attribute name=&quot;href&quot;&gt;&lt;xsl:value-of select=&quot;link&quot;/&gt;&lt;/xsl:attribute&gt;
                                &lt;xsl:value-of select=&quot;title&quot;/&gt;
                            &lt;/a&gt;
                        &lt;/h3&gt;
                        &lt;div&gt;&lt;p&gt;Description:&lt;/p&gt;&lt;p&gt;&lt;xsl:value-of select=&quot;description&quot; disable-output-escaping=&quot;yes&quot; /&gt;&lt;/p&gt;&lt;/div&gt;
                        &lt;div&gt;
                            &lt;a target=&quot;_blank&quot;&gt;
                                &lt;xsl:attribute name=&quot;href&quot;&gt;
                                    &lt;xsl:value-of select=&quot;comments&quot;/&gt;
                                &lt;/xsl:attribute&gt;
                                link to comments
                            &lt;/a&gt;
                        &lt;/div&gt;
                        &lt;div&gt;&lt;p&gt;When:&lt;/p&gt;&lt;p&gt;&lt;xsl:value-of select=&quot;substring(pubDate, 0, 26)&quot;/&gt;&lt;/p&gt;&lt;/div&gt; &lt;!-- we will take first 26 symbols --&gt;
                        &lt;div&gt;&lt;p&gt;Tags:&lt;/p&gt;&lt;p&gt;
                            &lt;xsl:for-each select=&quot;category&quot;&gt;
                                &lt;a target=&quot;_blank&quot;&gt;
                                    &lt;xsl:attribute name=&quot;href&quot;&gt;
                                        &lt;xsl:value-of select=&quot;@domain&quot;/&gt;
                                        &lt;xsl:value-of select=&quot;.&quot;/&gt;
                                    &lt;/xsl:attribute&gt;
                                    &lt;xsl:value-of select=&quot;.&quot;/&gt;
                                &lt;/a&gt; |
                            &lt;/xsl:for-each&gt;
                        &lt;/p&gt;&lt;/div&gt;
                    &lt;/div&gt;
                &lt;/xsl:for-each&gt;
                &lt;/div&gt;
                &lt;xsl:comment&gt;Copyright: AndrewP&lt;/xsl:comment&gt;
            &lt;/body&gt;
        &lt;/html&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre><h3>Step 4. Few important notes</h3><p>During checking my PHP file you will notice that I perform caching of Delicious requests. I don`t load provided RSS often that once per hour. No need overload Delicious server with often requests <img
src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>I made &#8216;cache&#8217; folder with permission to write (you should create &#8216;cache&#8217; folder too).</p><p>Also I created .htaccess file in it with next content:</p><p>Options -Indexes</p><p>Thats all.</p><hr
/><h5 style="text-align: center;"><strong><a
title="How to Easily display Delicious bookmarks using XSLT transformation - demo 47" href="http://www.script-tutorials.com/demos/47/index.php" target="_blank" rel="nofollow">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Easily display Delicious bookmarks using XSLT transformation - demo 47" href="http://www.script-tutorials.com/demos/47/source.zip" target="_blank" rel="nofollow">download in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>I hope that today&#8217;s article will very useful for your projects. Good luck!</p><div
class="shr-publisher-476"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-youtube-videos-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Youtube videos using XSLT transformation" /> <br
/> How to Easily display Youtube videos using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> <br
/> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> <br
/> How to Easily display Your Stumbleupon Favorites using XSLT</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>XPath visually</title><link>http://www.script-tutorials.com/xpath-visually/</link> <comments>http://www.script-tutorials.com/xpath-visually/#comments</comments> <pubDate>Sat, 26 Mar 2011 04:53:13 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[XSLT]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=420</guid> <description><![CDATA[XPath visually XPath is one of important keys to understanding of XSLT. And at first time we usually looking for any information (better &#8211; places where we can play online) &#8211; how to get different values in branch of XML tree. In this article I`ll give you all important information and will show how to [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-parse-web-pages-using-xpath/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/59/thumb.png" alt="How to parse web pages using XPath" /> How to parse web pages using XPath</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p><strong>XPath visually</strong><br
/> <br
/>XPath is one of important keys to understanding of XSLT. And at first time we usually looking for any information (better &#8211; places where we can play online) &#8211; how to get different values in branch of XML tree. In this article I`ll give you all important information and will show how to work with XPath in samples.<br
/> <span
id="more-420"></span></p><p>As example we have next source XML:</p><pre class="brush:xml">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;bookstore specialty=&quot;novel&quot;&gt;
  &lt;book style=&quot;autobiography&quot;&gt;
    &lt;author&gt;
      &lt;first-name&gt;Joe&lt;/first-name&gt;
      &lt;last-name&gt;Bob&lt;/last-name&gt;
      &lt;award&gt;Trenton Literary Review Honorable Mention&lt;/award&gt;
    &lt;/author&gt;
    &lt;price&gt;12&lt;/price&gt;
  &lt;/book&gt;
  &lt;book style=&quot;textbook&quot;&gt;
    &lt;author&gt;
      &lt;first-name&gt;Mary&lt;/first-name&gt;
      &lt;last-name&gt;Bob&lt;/last-name&gt;
      &lt;publication&gt;Selected Short Stories of
        &lt;first-name&gt;Mary&lt;/first-name&gt;
        &lt;last-name&gt;Bob&lt;/last-name&gt;
      &lt;/publication&gt;
    &lt;/author&gt;
    &lt;price&gt;55&lt;/price&gt;
  &lt;/book&gt;
  &lt;magazine style=&quot;glossy&quot; frequency=&quot;monthly&quot;&gt;
    &lt;price&gt;2.50&lt;/price&gt;
    &lt;subscription price=&quot;24&quot; per=&quot;year&quot;/&gt;
  &lt;/magazine&gt;
  &lt;book style=&quot;novel&quot; id=&quot;myfave&quot;&gt;
    &lt;author&gt;
      &lt;first-name&gt;Toni&lt;/first-name&gt;
      &lt;last-name&gt;Bob&lt;/last-name&gt;
      &lt;degree from=&quot;Trenton U&quot;&gt;B.A.&lt;/degree&gt;
      &lt;degree from=&quot;Harvard&quot;&gt;Ph.D.&lt;/degree&gt;
      &lt;award&gt;Pulitzer&lt;/award&gt;
      &lt;publication&gt;Still in Trenton&lt;/publication&gt;
      &lt;publication&gt;Trenton Forever&lt;/publication&gt;
    &lt;/author&gt;
    &lt;price intl=&quot;Canada&quot; exchange=&quot;0.7&quot;&gt;6.50&lt;/price&gt;
    &lt;excerpt&gt;
      &lt;p&gt;It was a dark and stormy night.&lt;/p&gt;
      &lt;p&gt;But then all nights in Trenton seem dark and
      stormy to someone who has gone through what
      &lt;emph&gt;I&lt;/emph&gt; have.&lt;/p&gt;
      &lt;definition-list&gt;
        &lt;term&gt;Trenton&lt;/term&gt;
        &lt;definition&gt;misery&lt;/definition&gt;
      &lt;/definition-list&gt;
    &lt;/excerpt&gt;
  &lt;/book&gt;
&lt;/bookstore&gt;
</pre><p>This is some bookstore listing</p><p>Here are list of rules which we can use in XPath:</p><ul><li>Different levels in tree separate via / symbol. This example will return array with infos of all authors: bookstore/book/author</li><li>Access to attributes we can obtain via @ symbol. That example will return us price of magazine subscription: bookstore/magazine/subscription/@price</li><li>Inside [] we can use number value to tell which (by order) element will need to receive. This example will return us price of second book: bookstore/book[2]/price</li><li>Also, we can use subpaths in [] and use this as check, are necessary elements present in our tree or not. Example &#8211; get all books with style=novel: bookstore/book[@style="novel"]</li><li>Another example &#8211; get all books with excerpts: bookstore/book[excerpt]</li><li>Another example &#8211; get all books if author have any awards: bookstore/book[author[award]]</li><li>Or &#8211; get all authors who have any awards: bookstore/book/author[award]</li><li>Or we can add some logic &#8211; get all books if author Don`t have awards: bookstore/book[author[not(award)]]</li><li>And last sample &#8211; get all books with price from 10 and 20: bookstore/book[price &lt; 20 and price &gt; 10]</li></ul><p>Interesting, isn`t it? Now, how we can use that. In first sample &#8211; we will store some defined value into variable:</p><pre class="brush:xml">
&lt;xsl:variable name=&quot;magSubPrice&quot; select=&quot;bookstore/magazine/subscription/@price&quot;/&gt;
</pre><p>Now we will walk through array of located elements:</p><pre class="brush:xml">
&lt;xsl:for-each select=&quot;bookstore/book/author&quot;&gt;
    // do some actions with authors
&lt;/xsl:for-each&gt;
</pre><p>And, here are one interesting service: http://xpath.me/  &#8211; where you will able to play with all our samples online. It will allow you to feel all this by self. Very nice and easy service.</p><hr
/><h3>Conclusion</h3><p>I hope that today&#8217;s article will very useful for your projects. Will glad if this will help you in your work. Good luck!</p><div
class="shr-publisher-420"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-parse-web-pages-using-xpath/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/59/thumb.png" alt="How to parse web pages using XPath" /> <br
/> How to parse web pages using XPath</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/xpath-visually/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to Build tags cloud using XSLT transformation</title><link>http://www.script-tutorials.com/how-to-build-tags-cloud-using-xslt-transformation/</link> <comments>http://www.script-tutorials.com/how-to-build-tags-cloud-using-xslt-transformation/#comments</comments> <pubDate>Tue, 15 Mar 2011 17:47:01 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[XSLT]]></category> <category><![CDATA[coding]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[tags]]></category> <category><![CDATA[tags cloud]]></category> <category><![CDATA[xslt]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=411</guid> <description><![CDATA[How to Build tags cloud using XSLT transformation As all we know &#8211; tags cloud is some array of links at page where bigger units mean more important things. If your project have any interesting information (blogs, or other text content), it will useful to put cloud of tags at your homepage. Of course, one [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> How to Easily display Delicious bookmarks using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-youtube-videos-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Youtube videos using XSLT transformation" /> How to Easily display Youtube videos using XSLT transformation</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="How to Build tags cloud using XSLT transformation" alt="How to Build tags cloud using XSLT transformation" src="http://www.script-tutorials.com/demos/36.png"></div><p><strong>How to Build tags cloud using XSLT transformation</strong></p><p>As all we know &#8211; tags cloud is some array of links at page where bigger units mean more important things. If your project have any interesting information (blogs, or other text content), it will useful to put cloud of tags at your homepage. Of course, one of way will just make all this using pure PHP to draw necessary links in different size, but lets try today to use xslt than just PHP. One of good side is that we can configure all necessary params (as example min font size and max font size, possible other details like different font classes if you want to use different colors etc) out of PHP logic.<span
id="more-411"></span><br
/></p><p>Here are samples and downloadable package:</p><h5 style="text-align: center;"><strong><a
title="How to Build tags cloud using XSLT - demo 36" href="http://www.script-tutorials.com/demos/36/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Build tags cloud using XSLTHow to Build tags cloud using XSLT - demo 36" href="http://www.script-tutorials.com/demos/36/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Ok, as example we have XML-based array of our cloud elements:</p><hr
/><pre class="brush:xml">&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;cloud&gt;
    &lt;tag id="1"&gt;
        &lt;name&gt;web&lt;/name&gt;
        &lt;amount&gt;2&lt;/amount&gt;
    &lt;/tag&gt;
    &lt;tag id="2"&gt;
        &lt;name&gt;development&lt;/name&gt;
        &lt;amount&gt;10&lt;/amount&gt;
    &lt;/tag&gt;
    &lt;tag id="3"&gt;
        &lt;name&gt;php&lt;/name&gt;
        &lt;amount&gt;6&lt;/amount&gt;
    &lt;/tag&gt;
    &lt;tag id="4"&gt;
        &lt;name&gt;jQuery&lt;/name&gt;
        &lt;amount&gt;2&lt;/amount&gt;
    &lt;/tag&gt;
    &lt;tag id="5"&gt;
        &lt;name&gt;xhtml&lt;/name&gt;
        &lt;amount&gt;10&lt;/amount&gt;
    &lt;/tag&gt;
    &lt;tag id="6"&gt;
        &lt;name&gt;xslt&lt;/name&gt;
        &lt;amount&gt;1&lt;/amount&gt;
    &lt;/tag&gt;
    &lt;tag id="7"&gt;
        &lt;name&gt;css&lt;/name&gt;
        &lt;amount&gt;7&lt;/amount&gt;
    &lt;/tag&gt;
    &lt;tag id="8"&gt;
        &lt;name&gt;programming&lt;/name&gt;
        &lt;amount&gt;8&lt;/amount&gt;
    &lt;/tag&gt;
&lt;/cloud&gt;
</pre><p>As we can see &#8211; I put name of tag in NAME tag, and amount of repeating (weight) into AMOUNT tag. Here are &#8216;development&#8217; and &#8216;xhtml&#8217; is most popular words.</p><p>And now we should to create our XSL part to perform transformation all this into user friendly view. Lets start coding all necessary files to our sample:</p><h3>Step 1. PHP</h3><p>Here are our php file which we using to transform our xml feed with tags:</p><h4>index.php</h4><p>As we can see &#8211; I just load our XML file here and perform transformation. Of course this can be not just static XML file, but also and any PHP-based source of XML in your custom cases. If so &#8211; you will need just to make small changes in my code. But currently &#8211; static case will enough (our file will &#8216;cloud.xml&#8217;).</p><pre class="brush:php">&lt;?php

// Obtain cloud data from file
$sXmlSrc = file_get_contents('cloud.xml');

// Load the XML source
$xml = new DOMDocument;
$xml-&gt;loadXML($sXmlSrc);

// Load XSLT
$xsl = new DOMDocument;
$xsl-&gt;load('xslt/tagcloud.xslt');

$proc = new XSLTProcessor; // configure xslt processor
$proc-&gt;importStyleSheet($xsl); // attach the xsl rules

echo $proc-&gt;transformToXML($xml); // draw result tags cloud

?&gt;
</pre><h3>Step 2. CSS</h3><p>Not so necessary step, but here are just few styles for our sample:</p><h4>css/styles.css</h4><pre class="brush:css">h1{text-align:center}
body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.main{background:#FFF;width:500px;font-size:80%;border:1px #000 solid;margin:3.5em auto 2em;padding:1em 2em 2em;overflow:hidden}
.main a{float:left;margin-right:5px;line-height:30px}
</pre><h3>Step 3. XSLT</h3><p>And, most interesting part of my post &#8211; used XSLT rules:</p><h4>xslt/tagcloud.xslt</h4><pre class="brush:xml">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:template match="/"&gt;
        &lt;html&gt;
            &lt;head&gt;
                &lt;link media="screen" href="css/styles.css" type="text/css" rel="stylesheet"/&gt;
            &lt;/head&gt;
            &lt;body&gt;
                &lt;div class="main"&gt;
                    &lt;h1&gt;Tags cloud via XSLT&lt;/h1&gt;
                    &lt;xsl:apply-templates /&gt;
                &lt;/div&gt;
            &lt;/body&gt;
        &lt;/html&gt;
    &lt;/xsl:template&gt;

    &lt;xsl:template match="cloud"&gt;
        &lt;xsl:variable name="maxAmount" select="tag[not(amount &amp;lt; ../tag/amount)]/amount" /&gt;
        &lt;xsl:variable name="minValue" select="tag[not(amount &amp;gt; ../tag/amount)]/amount" /&gt;

        &lt;xsl:variable name="perc100" select="$maxAmount - $minValue"/&gt;
        &lt;xsl:variable name="perc1"&gt;
            &lt;xsl:choose&gt;
                &lt;xsl:when test="$perc100 = 0"&gt;100&lt;/xsl:when&gt;
                &lt;xsl:otherwise&gt;&lt;xsl:value-of select="100 div $perc100"/&gt;&lt;/xsl:otherwise&gt;
            &lt;/xsl:choose&gt;
        &lt;/xsl:variable&gt;

        &lt;xsl:variable name="maxFont"&gt;28&lt;/xsl:variable&gt;
        &lt;xsl:variable name="minFont"&gt;12&lt;/xsl:variable&gt;

        &lt;xsl:variable name="fontDiff" select="$maxFont - $minFont"/&gt;
        &lt;div&gt;
        &lt;xsl:for-each select="tag"&gt;
                &lt;xsl:variable name="fontSize" select="$minFont + ceiling($fontDiff div 100 * ((amount - $minValue) * $perc1))"/&gt;
                &lt;a href="your_website_url/tag/{name}" style="font-size: {$fontSize}px"&gt;
                    &lt;xsl:value-of select="name" /&gt;
                &lt;/a&gt;
        &lt;/xsl:for-each&gt;
        &lt;/div&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre><p>I set max font size and min font size as maxFont and minFont variables. All other calculations need just for calculation of result font size (depends on &#8216;amount&#8217; value of our tags). All results we will able to see by links above:</p><hr
/><h5 style="text-align: center;"><strong><a
title="How to Build tags cloud using XSLT - demo 36" rel="nofollow" href="http://www.script-tutorials.com/demos/36/index.php" target="_blank">Result of transformation</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Build tags cloud using XSLT - demo 36" rel="nofollow" href="http://www.script-tutorials.com/demos/36/source.zip" target="_blank">download in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>I hope that today&#8217;s article will very useful for your projects. Good luck!</p><div
class="shr-publisher-411"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> <br
/> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> <br
/> How to Easily display Delicious bookmarks using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-youtube-videos-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Youtube videos using XSLT transformation" /> <br
/> How to Easily display Youtube videos using XSLT transformation</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/how-to-build-tags-cloud-using-xslt-transformation/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>How to Easily display Youtube videos using XSLT transformation</title><link>http://www.script-tutorials.com/how-to-easily-display-youtube-videos-using-xslt-transformation/</link> <comments>http://www.script-tutorials.com/how-to-easily-display-youtube-videos-using-xslt-transformation/#comments</comments> <pubDate>Thu, 10 Mar 2011 17:28:38 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Flash]]></category> <category><![CDATA[XSLT]]></category> <category><![CDATA[coding]]></category> <category><![CDATA[display]]></category> <category><![CDATA[videos]]></category> <category><![CDATA[xslt]]></category> <category><![CDATA[youtube]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=393</guid> <description><![CDATA[How to Easily display Youtube videos using XSLT transformation Today we will create application which will show our Youtube videos. Also we will draw youtube player for our videos. We will use XSLT transformation to parse XML provided by Youtube API. I will using my profile for our sample. Youtube API providing next path for [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> How to Easily display Delicious bookmarks using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> How to Easily display Your Stumbleupon Favorites using XSLT</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p><strong>How to Easily display Youtube videos using XSLT transformation</strong></p><p>Today we will create application which will show our Youtube videos. Also we will draw youtube player for our videos. We will use <strong>XSLT</strong> transformation to parse XML provided by Youtube API. I will using <a
rel="nofollow" href="http://www.youtube.com/user/AramisGC">my profile</a> for our sample. Youtube API providing next path for XML feed: http://gdata.youtube.com/feeds/api/users/AramisGC/uploads. So, we have all to start. Today I`ll show you how to display this information in any view.<span
id="more-393"></span><br
/></p><p>Here are samples and downloadable package:</p><h5 style="text-align: center;"><strong><a
title="How to Easily display Youtube videos using XSLT transformation - demo 34" href="http://www.script-tutorials.com/demos/34/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Easily display Youtube videos using XSLT transformation - demo 34" href="http://www.script-tutorials.com/demos/34/source.zip" target="_blank">download in package</a></strong></h5><hr
/>Ok, download the source files and lets start coding !</p><hr
/><h3>Step 1. PHP</h3><p>Ok, here are all used PHP files:</p><h4>index.php</h4><p>This file will generate list of Youtube videos. Quite all code commented, so I hope it will easy to understand it.</p><pre class="brush:php">&lt;?php

$sMethod = 'http://gdata.youtube.com/feeds/api/users/AramisGC/uploads';
$sXmlSrc = getYtbXml($sMethod);

// Load the XML source
$xml = new DOMDocument;
$xml-&gt;loadXML($sXmlSrc);

// Load XSLT
$xsl = new DOMDocument;
$xsl-&gt;load('xslt/youtube.xslt');

$proc = new XSLTProcessor; // configure the transformer
$proc-&gt;importStyleSheet($xsl); // attach the xsl rules

echo $proc-&gt;transformToXML($xml);

// this function get youtube information using caches (not more than 1 times per hour)
function getYtbXml($sUrl) {
    // our folder with cache files
    $sCacheFolder = 'cache/';

    // cache filename
    $sFilename = date('YmdH').'.xml';

    if (! file_exists($sCacheFolder.$sFilename)) {
        $ch = curl_init($sUrl);
        $fp = fopen($sCacheFolder.$sFilename, 'w');
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15') ); // makes our request look like it was made by Firefox
        curl_exec($ch);
        curl_close($ch);
        fclose($fp);
    }
    return file_get_contents($sCacheFolder.$sFilename);
}

require_once('footer.html');

?&gt;
</pre><h3>Step 2. CSS</h3><p>Here are used CSS file. Just few styles for our demo:</p><h4>css/styles.css</h4><pre class="brush:css">h1{text-align:center}
body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.main{background:#FFF;width:900px;font-size:80%;border:1px #000 solid;margin:3.5em auto 2em;padding:1em 2em 2em}

.main div.video_block{width:640px;float:left;text-align:left;display:block;min-height:400px;padding:5px}
.main div.video_thumbs img{border-width:0px}
.main div.thumb{float:left;width:100px;height:110px;overflow:hidden;margin:6px}
</pre><h3>Step 3. XSLT</h3><p>And, most interesting part of my story &#8211; used XSLT rules:</p><h4>xslt/youtube.xslt</h4><pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:media="http://search.yahoo.com/mrss/" xmlns:n1="http://www.w3.org/2005/Atom" &gt;
    &lt;xsl:variable name="XML" select="/"/&gt;
    &lt;xsl:template match="/"&gt;
        &lt;html&gt;
            &lt;head&gt;
                &lt;link media="screen" href="css/styles.css" type="text/css" rel="stylesheet"/&gt;
                &lt;script type="text/javascript" src="js/swfobject.js"&gt;&lt;/script&gt;
                &lt;script type="text/javascript" src="js/youtube.js"&gt;&lt;/script&gt;
            &lt;/head&gt;
            &lt;body&gt;
                &lt;div class="main"&gt;
                    &lt;h1&gt;My videos&lt;/h1&gt;
                    &lt;xsl:for-each select="$XML"&gt;
                        &lt;xsl:for-each select="n1:feed"&gt;
                            &lt;xsl:if test="n1:entry[1]"&gt;
                                &lt;div class="video_block"&gt;
                                    &lt;div id="view_video"&gt;
                                        &lt;xsl:for-each select="n1:entry[1]/media:group/media:content"&gt;
                                            &lt;xsl:if test="@type = 'application/x-shockwave-flash'"&gt;
                                                &lt;embed width="640" height="385" name="view_video_swf" id="view_video_swf" bgcolor="#000" quality="high"&gt;
                                                    &lt;xsl:attribute name="src"&gt;
                                                        &lt;xsl:value-of select="@url"/&gt;
                                                    &lt;/xsl:attribute&gt;
                                                &lt;/embed&gt;
                                            &lt;/xsl:if&gt;
                                        &lt;/xsl:for-each&gt;
                                    &lt;/div&gt;
                                    &lt;div id="view_video_title"&gt;
                                        &lt;xsl:value-of select="n1:entry[1]/n1:title"/&gt;
                                    &lt;/div&gt;
                                &lt;/div&gt;
                            &lt;/xsl:if&gt;
                            &lt;div class="video_thumbs"&gt;
                                &lt;xsl:for-each select="n1:entry/media:group"&gt;
                                    &lt;div class="thumb"&gt;
                                        &lt;xsl:for-each select="media:content"&gt;
                                            &lt;xsl:if test="@type = 'application/x-shockwave-flash'"&gt;
                                                &lt;a href="javascript:void(0)"&gt;
                                                    &lt;xsl:attribute name="onclick"&gt;playVideo('&lt;xsl:value-of select="@url"/&gt;','&lt;xsl:value-of select="../media:title"/&gt;');&lt;/xsl:attribute&gt;
                                                    &lt;xsl:for-each select="../media:thumbnail[1]"&gt;
                                                        &lt;img width="100px" height="60px"&gt;
                                                            &lt;xsl:attribute name="src"&gt;&lt;xsl:value-of select="@url"/&gt;&lt;/xsl:attribute&gt;
                                                        &lt;/img&gt;
                                                    &lt;/xsl:for-each&gt;
                                                    &lt;xsl:value-of select="../media:title"/&gt;
                                                &lt;/a&gt;
                                            &lt;/xsl:if&gt;
                                        &lt;/xsl:for-each&gt;
                                    &lt;/div&gt;
                                &lt;/xsl:for-each&gt;
                                &lt;div style="clear:both"&gt;&lt;/div&gt;
                            &lt;/div&gt;
                        &lt;/xsl:for-each&gt;
                    &lt;/xsl:for-each&gt;
                &lt;/div&gt;
                &lt;xsl:comment&gt;Copyright © AndrewP&lt;/xsl:comment&gt;
            &lt;/body&gt;
        &lt;/html&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre><h3>Step 4. JS</h3><p>Here are two JS files:</p><h4>js/youtube.js</h4><pre class="brush:js">function playVideo(url, title) {
    obj = new SWFObject(url, "view_video_swf", "640", "385", "7");
    obj.write("view_video");
    document.getElementById('view_video_title').innerHTML = title;
}
</pre><p>This file contain only one easy function which will allow us to play another videos</p><h4>js/swfobject.js</h4><p>This is just SWFObject class. Available as a download package.</p><h3>Step 5. Few important notes</h3><p>During checking my PHP file you will notice that I perform caching of Youtube API XML requests. I don`t load provided RSS often that once per hour. No need overload Youtube server with often requests <img
src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>I made &#8216;cache&#8217; folder with permission to write (you should create &#8216;cache&#8217; folder too).</p><p>Also I created .htaccess file in it with next content:</p><p>Options -Indexes</p><p>Thats all.</p><hr
/><h5 style="text-align: center;"><strong><a
title="How to Easily display Youtube videos using XSLT transformation - demo 34" rel="nofollow" href="http://www.script-tutorials.com/demos/34/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Easily display Youtube videos using XSLT transformation - demo 34" rel="nofollow" href="http://www.script-tutorials.com/demos/34/source.zip" target="_blank">download in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>I hope that today&#8217;s article will very useful for your projects. Good luck!</p><div
class="shr-publisher-393"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> <br
/> How to Easily display Delicious bookmarks using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> <br
/> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> <br
/> How to Easily display Your Stumbleupon Favorites using XSLT</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/how-to-easily-display-youtube-videos-using-xslt-transformation/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>How to Easily display Your Stumbleupon Favorites using XSLT</title><link>http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/</link> <comments>http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/#comments</comments> <pubDate>Thu, 24 Feb 2011 17:20:59 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[XSLT]]></category> <category><![CDATA[css]]></category> <category><![CDATA[get posts]]></category> <category><![CDATA[html]]></category> <category><![CDATA[Stumbleupon]]></category> <category><![CDATA[xslt]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=346</guid> <description><![CDATA[How to Easily display Your Stumbleupon Favorites using XSLT Today I will tell you about another similar tutorial, but about Stumbleupon. We will create application which will show our (or any wished profile) Stumbleupon posts. And we will use XSLT transformation to parse XML (RSS) provided by Stumbleupon. I will using my profile for our [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> How to Easily display Delicious bookmarks using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-youtube-videos-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Youtube videos using XSLT transformation" /> How to Easily display Youtube videos using XSLT transformation</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p><strong>How to Easily display Your Stumbleupon Favorites using XSLT</strong></p><p
style="text-align: justify;">Today I will tell you about another similar tutorial, but about Stumbleupon. We will create application which will show our (or any wished profile) Stumbleupon posts. And we will use <strong>XSLT</strong> transformation to parse XML (RSS) provided by Stumbleupon. I will using <a
rel="nofollow" href="http://www.stumbleupon.com/stumbler/AramisGC/">my profile</a> for our sample. After some investigation I find that SU provide our list of favs in rss format here: http://www.stumbleupon.com/syndicate.php?stumbler=aramisgc  &#8211; where &#8216;aramisgc&#8217; is my account name. Also, we can obtain our comments too: http://www.stumbleupon.com/syndicate.php?stumbler=aramisgc&amp;comments=1. So, we have all to start. Today I`ll show you how to display this information in any view.<span
id="more-346"></span><br
/></p><p>Here are samples and downloadable package:</p><h5 style="text-align: center;"><strong><a
title="How to Easily display Stumbleupon posts using XSLT - demo 28" href="http://www.script-tutorials.com/demos/28/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Easily display Stumbleupon posts using XSLT - demo 28" href="http://www.script-tutorials.com/demos/28/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Ok, download the source files and lets start coding !</p><hr
/><h3>Step 1. PHP</h3><p>Ok, here are all used PHP files:</p><h4>index.php</h4><p>This file will generate list of Stumbleupon posts. As you can see &#8211; I already put several samples ($sMethod values) for different urls. So you can try any. Quite all code commented, so I hope it will easy to understand it.</p><pre class="brush:php">&lt;?php

//$sMethod = 'http://www.stumbleupon.com/syndicate.php?stumbler=aramisgc&amp;comments=1';
$sMethod = 'http://www.stumbleupon.com/syndicate.php?stumbler=aramisgc';
$sXmlSrc = getStumbleuponStoriesXml($sMethod);

// Load the XML source
$xml = new DOMDocument;
$xml-&gt;loadXML($sXmlSrc);

// Load XSLT
$xsl = new DOMDocument;
$xsl-&gt;load('xslt/stumbleupon.xslt');

$proc = new XSLTProcessor; // configure the transformer
$proc-&gt;importStyleSheet($xsl); // attach the xsl rules

echo $proc-&gt;transformToXML($xml);

// this function get stumbleupon information using caching (not more than 1 times per hour)
function getStumbleuponStoriesXml($sUrl) {
    // our folder with cache files
    $sCacheFolder = 'cache/';

    // cache filename
    $sFilename = date('YmdH').'.xml';

    if (! file_exists($sCacheFolder.$sFilename)) {
        $ch = curl_init($sUrl);
        $fp = fopen($sCacheFolder.$sFilename, 'w');
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15') ); // makes our request look like it was made by Firefox
        curl_exec($ch);
        curl_close($ch);
        fclose($fp);
    }
    return file_get_contents($sCacheFolder.$sFilename);
}

?&gt;
</pre><h3>Step 2. CSS</h3><p>Here are used CSS file. Just few styles for our demo:</p><h4>css/styles.css</h4><pre class="brush:css">h1{text-align:center}
.su-unit{background-color:#F3F3F3;border:1px solid #CCC;position:relative;margin:10px;padding:10px}
.su-unit h3, .su-unit div{border-bottom:1px dashed #888;padding:5px;overflow:hidden}
.su-unit div p{float:left;margin-right:20px}
.su-unit div p:first-child{font-weight:bold}
body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.main{background:#FFF;width:900px;font-size:80%;border:1px #000 solid;margin:3.5em auto 2em;padding:1em 2em 2em}
</pre><h3>Step 3. XSLT</h3><p>And, most interesting part of my story &#8211; used XSLT rules:</p><h4>xslt/stumbleupon.xslt</h4><pre class="brush:xml">&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:template match="channel"&gt;
        &lt;xsl:variable name="channelDescription" select="description"/&gt;
        &lt;xsl:variable name="authorLink" select="link"/&gt;
        &lt;html&gt;
            &lt;head&gt;
                &lt;link media="all" href="css/styles.css" type="text/css" rel="stylesheet"/&gt;
            &lt;/head&gt;
            &lt;body&gt;
                &lt;div class="main"&gt;
                &lt;h1&gt;
                    &lt;a&gt;
                        &lt;xsl:attribute name="href"&gt;
                            &lt;xsl:value-of select="$authorLink"/&gt;
                        &lt;/xsl:attribute&gt;
                        &lt;xsl:value-of select="$channelDescription"/&gt;
                    &lt;/a&gt;
                &lt;/h1&gt;
                &lt;xsl:for-each select="item"&gt;
                    &lt;div class="su-unit"&gt;
                        &lt;h3&gt;
                            &lt;a target="_blank"&gt;
                                &lt;xsl:attribute name="title"&gt;&lt;xsl:value-of select="title"/&gt;&lt;/xsl:attribute&gt;
                                &lt;xsl:attribute name="href"&gt;&lt;xsl:value-of select="link"/&gt;&lt;/xsl:attribute&gt;
                                &lt;xsl:value-of select="title"/&gt;
                            &lt;/a&gt;
                        &lt;/h3&gt;
                        &lt;div&gt;&lt;p&gt;Description:&lt;/p&gt;&lt;p&gt;&lt;xsl:value-of select="description" disable-output-escaping="yes" /&gt;&lt;/p&gt;&lt;/div&gt;
                        &lt;div&gt;
                            &lt;a target="_blank"&gt;
                                &lt;xsl:attribute name="href"&gt;
                                    &lt;xsl:value-of select="comments"/&gt;
                                &lt;/xsl:attribute&gt;
                                link to comments
                            &lt;/a&gt;
                        &lt;/div&gt;
                        &lt;div&gt;&lt;p&gt;When:&lt;/p&gt;&lt;p&gt;&lt;xsl:value-of select="substring(pubDate, 0, 26)"/&gt;&lt;/p&gt;&lt;/div&gt; &lt;!-- we will take first 26 symbols --&gt;
                    &lt;/div&gt;
                &lt;/xsl:for-each&gt;
                &lt;/div&gt;
                &lt;xsl:comment&gt;Copyright © AndrewP&lt;/xsl:comment&gt;
            &lt;/body&gt;
        &lt;/html&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre><h3>Step 4. Few important notes</h3><p>During checking my PHP file you will notice that I perform caching of Stumbleupon requests. I don`t load provided RSS often that once per hour. No need overload Stumbleupon server with often requests <img
src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>I made &#8216;cache&#8217; folder with permission to write (you should create &#8216;cache&#8217; folder too).</p><p>Also I created .htaccess file in it with next content:</p><p>Options -Indexes</p><p>Thats all.</p><hr
/><h5 style="text-align: center;"><strong><a
title="How to Easily display Stumbleupon posts using XSLT - demo 28" rel="nofollow" href="http://www.script-tutorials.com/demos/28/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Easily display Stumbleupon posts using XSLT - demo 28" rel="nofollow" href="http://www.script-tutorials.com/demos/28/source.zip" target="_blank">download in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>I hope that today&#8217;s article will very useful for your projects. Good luck!</p><div
class="shr-publisher-346"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> <br
/> How to Easily display Delicious bookmarks using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> <br
/> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-youtube-videos-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Youtube videos using XSLT transformation" /> <br
/> How to Easily display Youtube videos using XSLT transformation</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>How to Easily display Your Tweets using XSLT transformation</title><link>http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/</link> <comments>http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/#comments</comments> <pubDate>Wed, 23 Feb 2011 14:14:57 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[XSLT]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=337</guid> <description><![CDATA[How to Easily display Twitter posts using XSLT transformation Today I will tell you how to create application which will display your Tweets (or someone else) at your website. And we will use XSLT transformation to parse XML (RSS) provided by Twitter. As example I take my Twitter account. At this page you can see [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> How to Easily display Delicious bookmarks using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-youtube-videos-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Youtube videos using XSLT transformation" /> How to Easily display Youtube videos using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> How to Easily display Your Stumbleupon Favorites using XSLT</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p><strong>How to Easily display Twitter posts using XSLT transformation</strong></p><p>Today I will tell you how to create application which will display your Tweets (or someone else) at your website. And we will use <strong>XSLT</strong> transformation to parse XML (RSS) provided by Twitter. As example I take <a
rel="nofollow" href="http://twitter.com/AramisGC">my Twitter account</a>. At this page you can see that I have RSS channel: http://twitter.com/statuses/user_timeline/83882961.rss. Today I`ll show you how to display this information in any view.<span
id="more-337"></span><br
/></p><p>Here are samples and downloadable package:</p><h5 style="text-align: center;"><strong><a
title="How to Easily display Twitter posts using XSLT - demo 27" href="http://www.script-tutorials.com/demos/27/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Easily display Twitter posts using XSLT - demo 27" href="http://www.script-tutorials.com/demos/27/source.zip" target="_blank">download in package</a></strong></h5><hr
/>Ok, download the source files and lets start coding !</p><hr
/><h3>Step 1. PHP</h3><p>Ok, here are all used PHP files:</p><h4>index.php</h4><p>This file will generate list of Twitter posts. All code commented, so I hope it will easy to understand it.</p><pre class="brush:php">&lt;?php

$sMethod = 'http://twitter.com/statuses/user_timeline/83882961.rss';
$sXmlSrc = getTwitterStoriesXml($sMethod);

// Load the XML source
$xml = new DOMDocument;
$xml-&gt;loadXML($sXmlSrc);

// Load XSLT
$xsl = new DOMDocument;
$xsl-&gt;load('xslt/twitter.xslt');

$proc = new XSLTProcessor; // configure the transformer
$proc-&gt;importStyleSheet($xsl); // attach the xsl rules

echo '&lt;link media="all" href="css/styles.css" type="text/css" rel="stylesheet"&gt;';
echo $proc-&gt;transformToXML($xml);

// this function get twitter information using caching (not more 1 times per minute)
function getTwitterStoriesXml($sUrl) {
    // our folder with cache files
    $sCacheFolder = 'cache/';

    // cache filename
    $sFilename = date('YmdHi').'.xml';

    if (! file_exists($sCacheFolder.$sFilename)) {
        $ch = curl_init($sUrl);
        $fp = fopen($sCacheFolder.$sFilename, 'w');
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15') ); // makes our request look like it was made by Firefox
        curl_exec($ch);
        curl_close($ch);
        fclose($fp);
    }
    return file_get_contents($sCacheFolder.$sFilename);
}

?&gt;
</pre><h3>Step 2. CSS</h3><p>Here are used CSS file. Just few styles for our demo:</p><h4>css/styles.css</h4><pre class="brush:css">h1{text-align:center}
.tw-unit{background-color:#F3F3F3;border:1px solid #CCC;position:relative;margin:10px;padding:10px}
body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.main{background:#FFF;width:900px;font-size:80%;border:1px #000 solid;margin:3.5em auto 2em;padding:1em 2em 2em}
</pre><h3>Step 3. XSLT</h3><p>And, most interesting part of my story &#8211; used XSLT rules:</p><h4>xslt/twitter.xslt</h4><pre class="brush:xml">&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:template match="channel"&gt;
        &lt;xsl:variable name="channelDescription" select="description"/&gt;
        &lt;xsl:variable name="authorLink" select="link"/&gt;
        &lt;xsl:variable name="authorName" select="substring(title, 10)"/&gt; &lt;!-- we will cut off Twitter / --&gt;
        &lt;xsl:variable name="authorNameLength" select="string-length($authorName)+2"/&gt; &lt;!-- we will calculate length of our name + 2 symbols more (for colon and space symbols) --&gt;
        &lt;html&gt;
            &lt;body&gt;
                &lt;div class="main"&gt;
                &lt;h1&gt;&lt;xsl:value-of select="$channelDescription"/&gt;&lt;/h1&gt;
                &lt;xsl:for-each select="item"&gt;
                    &lt;div class="tw-unit"&gt;
                        &lt;h3&gt;
                            &lt;a target="_blank"&gt;
                                &lt;xsl:attribute name="title"&gt;&lt;xsl:value-of select="substring(title, $authorNameLength)"/&gt;&lt;/xsl:attribute&gt;
                                &lt;xsl:attribute name="href"&gt;&lt;xsl:value-of select="link"/&gt;&lt;/xsl:attribute&gt;
                                &lt;xsl:value-of select="substring(title, $authorNameLength)"/&gt;
                            &lt;/a&gt;
                        &lt;/h3&gt;
                        &lt;div&gt;Submitted by:
                            &lt;a&gt;
                            &lt;xsl:attribute name="href"&gt;
                                &lt;xsl:value-of select="$authorLink"/&gt;
                            &lt;/xsl:attribute&gt;
                            &lt;xsl:value-of select="$authorName"/&gt;
                            &lt;/a&gt;
                        &lt;/div&gt;
                        &lt;div&gt;Description: &lt;xsl:value-of select="substring(description, $authorNameLength)"/&gt;&lt;/div&gt;
                        &lt;div&gt;Source: &lt;xsl:value-of select="*[name()='twitter:source']"/&gt;&lt;/div&gt;
                        &lt;div&gt;When: &lt;xsl:value-of select="substring(pubDate, 0, 26)"/&gt;&lt;/div&gt; &lt;!-- we will take first 26 symbols --&gt;
                    &lt;/div&gt;
                &lt;/xsl:for-each&gt;
                &lt;/div&gt;
                &lt;xsl:comment&gt;Copyright © AndrewP&lt;/xsl:comment&gt;
            &lt;/body&gt;
        &lt;/html&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre><h3>Step 4. Few important notes</h3><p>During checking my PHP file you will notice that I perform caching of Twitter requests. I don`t load provided RSS often that once per minute. No need overload Twitter server with often requests <img
src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>I made &#8216;cache&#8217; folder with permission to write (you should create &#8216;cache&#8217; folder too).</p><p>Also I created .htaccess file in it with next content:</p><p>Options -Indexes</p><p>Thats all. After this, you will able to load not only my RSS feeds (of 83882961.rss), but also and your own too.</p><hr
/><h5 style="text-align: center;"><strong><a
title="How to Easily display Twitter posts using XSLT - demo 27" rel="nofollow" href="http://www.script-tutorials.com/demos/27/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Easily display Twitter posts using XSLT - demo 27" rel="nofollow" href="http://www.script-tutorials.com/demos/27/source.zip" target="_blank">download in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>I hope that today&#8217;s article will very useful for your projects. Good luck!</p><div
class="shr-publisher-337"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> <br
/> How to Easily display Delicious bookmarks using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-youtube-videos-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Youtube videos using XSLT transformation" /> <br
/> How to Easily display Youtube videos using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> <br
/> How to Easily display Your Stumbleupon Favorites using XSLT</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>How to Easily display Digg posts via XSLT using Digg Api</title><link>http://www.script-tutorials.com/how-to-easily-display-digg-posts-via-xslt-using-digg-api/</link> <comments>http://www.script-tutorials.com/how-to-easily-display-digg-posts-via-xslt-using-digg-api/#comments</comments> <pubDate>Thu, 08 Jul 2010 23:33:57 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[XSLT]]></category> <category><![CDATA[digg api]]></category> <category><![CDATA[digg xslt]]></category> <category><![CDATA[tutorial]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=156</guid> <description><![CDATA[How to Easily display Digg posts via XSLT using Digg Api As we know, Digg become very popular last time, so why not use it for our purposes? I decided to investigate Digg a little and learn how possible to draw Digg posts at my own website. And I make own unique method. Hope you [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> How to Easily display Delicious bookmarks using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> How to Easily display Your Stumbleupon Favorites using XSLT</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p><strong>How to Easily display Digg posts via XSLT using Digg Api</strong></p><p>As we know, Digg become very popular last time, so why not use it for our purposes? I decided to investigate Digg a little and learn how possible to draw Digg posts at my own website. And I make own unique method. Hope you will like it.<br
/> Reading http://digg.com/api/docs/1.0/groups/  I find necessary ways to get posts XML results. Just check story.getPopular method. Yes, this is usual to use different reparse methods in PHP, but lets learn something new like XSLT (Extensible Stylesheet Language Transformations).<br
/> <span
id="more-156"></span><br
/> Here is a sample:</p><h5 style="text-align: center;"><strong><a
title="How to Easily display Digg posts via XSLT - demo 10" rel="nofollow" href="http://www.script-tutorials.com/demos/10/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Easily display Digg posts via XSLT - demo 10" rel="nofollow" href="http://www.script-tutorials.com/demos/10/source.zip">download in package</a></strong></h5><hr
/>Ok, download the example files and lets start coding !</p><hr
/><h3>Step 1. PHP</h3><p>Ok, here are all used PHP files:</p><h4>index.php</h4><p>This file will generate list of Digg stories. As you can see &#8211; I already put several samples ($sMethod values) for different methods. So you can try any method. All code commented, so I hope it will easy to understand it.</p><pre class="brush:php">&lt;?php

// $sMethod = 'http://services.digg.com/1.0/endpoint?method=story.getHot';
$sMethod = 'http://services.digg.com/1.0/endpoint?method=story.getTop';
// $sMethod = 'http://services.digg.com/1.0/endpoint?method=story.getPopular';
// $sMethod = 'http://services.digg.com/1.0/endpoint?method=story.getUpcoming';

$sXmlSrc = getDiggStoriesXml($sMethod);

// Load the XML source
$xml = new DOMDocument;
$xml-&gt;loadXML($sXmlSrc);

// Load XSLT
$xsl = new DOMDocument;
$xsl-&gt;load('xslt/digg.xslt');

// Configure the transformer
$proc = new XSLTProcessor;
$proc-&gt;importStyleSheet($xsl); // attach the xsl rules

echo '&lt;link media="all" href="css/styles.css" type="text/css" rel="stylesheet"&gt;';
echo $proc-&gt;transformToXML($xml);

// this function get digg information using caching (not more 1 times per minute)
function getDiggStoriesXml($sUrl = 'http://services.digg.com/1.0/endpoint?method=story.getPopular') {
    // used cache folder
    $sCacheFolder = 'cache/';

    // formatting cache name
    $sFilename = date("YmdHi").'.xml';

    if (! file_exists($sCacheFolder.$sFilename)) {
        //grab the XML and save it to a temp XML file
        $ch = curl_init($sUrl);
        $fp = fopen($sCacheFolder.$sFilename, "w");
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // makes our request look like it was made by Firefox
        curl_exec($ch);
        curl_close($ch);
        fclose($fp);
    }
    return file_get_contents($sCacheFolder.$sFilename);
}

?&gt;
</pre><hr
/><h3>Step 2. CSS</h3><p>Here are used CSS styles.</p><h4>css/styles.css</h4><pre class="brush:css">.news-summary, .news-full, .news-full-confirm {
background:none repeat scroll 0 0 #F3F3F3;
border:1px solid #CCCCCC;
clear:left;
margin:10px;
min-height:55px;
padding:10px;
position:relative;
}
.news-body {
padding-left: 60px;
}
.news-body a.body {
text-decoration: none;
padding: 4px;
margin: -4px 0 -4px -4px;
color: #555;
position: relative;
z-index: 2;
}
.news-summary .news-body em {
color: #999;
white-space: nowrap;
}
.news-body em a {
color: #777;
text-decoration: none;
border-bottom: 1px solid #ddd;
}
.news-body em a:hover {
color: #000;
}
.news-digg {
position: absolute;
top: 0.8em;
left: 0;
text-align: center;
font-size: 85%;
margin: 0 0 0 3px;
padding: 0;
list-style: none;
background: url(../img/shade-news.gif) no-repeat;
}
.digg-count a, .digg-count span  {
display: block;
padding: 10px 0 4px 0;
text-decoration: none;
width: 50px;
min-height: 40px;
color: #93883F;
text-align: center;
}
.news-summary .digg-count strong {
font-size: 160%;
font-weight: normal;
letter-spacing: -1px;
line-height: 1;
display: block;
color: #736926;
}
.digg-count img {
position: absolute;
top: 0;
left: 0;
border: none;
}
.digg-count a:hover, .digg-count a:hover strong {
color: #998D43;
}
.news-body h3 {
margin: 2px 0 0 0;
font-size: 115%;
letter-spacing: -0.01em;
font-weight: bold;
line-height: 1.1;
}
.news-body p {
margin: 0.2em 0 0.1em 0;
line-height: 1.3;
}
.news-body em {
font-style: normal;
font-size: 85%;
color: #666;
}
span.news-img {
display: block;
width: 80px;
height: 80px;
background: #ddecee url(../img/v-default.gif);
border: 1px solid #a5c2e3;
position: absolute;
left: 60px;
top: 8px;
}
.img-summary span.news-img {
background: #ddecee url(../img/i-default.gif);
}
span.news-img em {
display: block;
width: 80px;
height: 80px;
text-indent: -2000em;
background: url(../img/v-frame-simple.png);
}
.img-summary span.news-img em {
background: url(../img/i-frame-simple.png);
}
.v .news-body {
margin-left:0;
min-height:70px;
padding-left:152px;
padding-right:0;
}
.comments {
background:transparent url(../img/i-cmts.gif) no-repeat scroll 0 4px;
word-spacing:-0.1em;
color:#578CCA;
padding:4px 6px 4px 18px;
font-size:85%;
}
</pre><hr
/><h3>Step 3. XSLT</h3><p>I hope this is most interesting part of my story, used XSLT rules:</p><h4>xslt/digg.xslt</h4><pre class="brush:xml">&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;!-- &lt;xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/&gt; --&gt;
    &lt;xsl:template match="stories"&gt;
        &lt;html&gt;
            &lt;body&gt;
                &lt;xsl:for-each select="story"&gt;
                    &lt;div&gt;
                        &lt;xsl:attribute name="class"&gt;
                            &lt;xsl:choose&gt;
                                &lt;xsl:when test="thumbnail"&gt;news-summary v img-summary&lt;/xsl:when&gt;
                                &lt;xsl:otherwise&gt;news-summary&lt;/xsl:otherwise&gt;
                            &lt;/xsl:choose&gt;
                        &lt;/xsl:attribute&gt;

                        &lt;div class="news-body"&gt;
                            &lt;h3&gt;
                                &lt;a target="_blank"&gt;
                                    &lt;xsl:attribute name="title"&gt;&lt;xsl:value-of select="@link"/&gt;&lt;/xsl:attribute&gt;
                                    &lt;xsl:attribute name="href"&gt;
                                        &lt;xsl:for-each select="shorturl"&gt;
                                            &lt;xsl:value-of select="@short_url"/&gt;
                                        &lt;/xsl:for-each&gt;
                                    &lt;/xsl:attribute&gt;
                                    &lt;xsl:value-of select="title"/&gt;

                                &lt;xsl:for-each select="thumbnail"&gt;
                                    &lt;span style="background-attachment:scroll;background-color:transparent;background-position:0 0;background-repeat:repeat;" class="news-img"&gt;
                                    &lt;xsl:attribute name="style"&gt;background: transparent url(&lt;xsl:choose&gt;
                                            &lt;xsl:when test="string-length(@src) &gt; 0"&gt;
                                                &lt;xsl:value-of select="@src" /&gt;
                                              &lt;/xsl:when&gt;
                                        &lt;/xsl:choose&gt;) repeat scroll 0% 0%;&lt;/xsl:attribute&gt;
                                    &lt;em&gt;view!&lt;/em&gt;&lt;/span&gt;
                                &lt;/xsl:for-each&gt;
                                &lt;/a&gt;
                            &lt;/h3&gt;
                            &lt;div&gt;
                                &lt;p&gt;
                                &lt;a class="body" style="color:#555;"&gt;
                                &lt;xsl:attribute name="href"&gt;&lt;xsl:value-of select="@href"/&gt;&lt;/xsl:attribute&gt;
                                &lt;xsl:value-of select="description"/&gt;
                                &lt;/a&gt;
                                &lt;em&gt;(Submitted by &lt;a&gt;
                                &lt;xsl:for-each select="user"&gt;
                                    &lt;xsl:attribute name="href"&gt;

http://digg.com/users/&lt;xsl:choose&gt;

                                            &lt;xsl:when test="string-length(@name) &gt; 0"&gt;
                                                &lt;xsl:value-of select="@name" /&gt;
                                              &lt;/xsl:when&gt;
                                        &lt;/xsl:choose&gt;
                                    &lt;/xsl:attribute&gt;
                                    &lt;xsl:value-of select="@name" /&gt;
                                &lt;/xsl:for-each&gt;
                                &lt;/a&gt;)&lt;/em&gt;
                                &lt;/p&gt;
                            &lt;/div&gt;

                    		&lt;div class="news-details"&gt;
                    			&lt;span class="tool comments"&gt;
                                    &lt;xsl:attribute name="title"&gt;&lt;xsl:value-of select="title"/&gt;&lt;/xsl:attribute&gt;
                                    &lt;xsl:value-of select="@comments"/&gt; Comments&lt;/span&gt;
                            &lt;/div&gt;

                        &lt;/div&gt;

                    	&lt;ul class="news-digg"&gt;
                    		&lt;li class="digg-count"&gt;
                        		&lt;a&gt;
                                &lt;xsl:attribute name="href"&gt;&lt;xsl:value-of select="@href"/&gt;&lt;/xsl:attribute&gt;
                                &lt;xsl:attribute name="title"&gt;&lt;xsl:value-of select="title"/&gt;&lt;/xsl:attribute&gt;
                        		&lt;strong&gt;&lt;xsl:value-of select="@diggs"/&gt;&lt;/strong&gt; diggs&lt;/a&gt;
                            &lt;/li&gt;
                    	&lt;/ul&gt;

                    &lt;/div&gt;
                &lt;/xsl:for-each&gt;
                &lt;xsl:comment&gt;Copyright © AndrewP&lt;/xsl:comment&gt;
            &lt;/body&gt;
        &lt;/html&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre><hr
/><h3>Step 4. Images</h3><p>Also we need several images for our project:</p><pre class="sources">    <img src="http://www.script-tutorials.com/demos/10/img/i-cmts.gif" alt="i-cmts.gif" />
    <img src="http://www.script-tutorials.com/demos/10/img/i-default.gif" alt="i-default.gif" />
    <img src="http://www.script-tutorials.com/demos/10/img/i-frame-simple.png" alt="i-frame-simple.png" />
    <img src="http://www.script-tutorials.com/demos/10/img/shade-news.gif" alt="shade-news.gif" />
</pre><hr
/><h3>Step 5. Few important things</h3><p>After reading http://digg.com/api/docs/concepts I found &#8216;Be Polite, Please!&#8217;, so I decode not request Digg api any time when user call it, and I made way using cache system. I started caching results. I created &#8216;cache&#8217; folder with permission to write (you should create &#8216;cache&#8217; folder too).<br
/> After I put .htaccess file in it with next text:<br
/> Options -Indexes</p><p>And now check index.php:<br
/> $sFilename = date(&#8220;YmdHi&#8221;).&#8217;.xml&#8217;;<br
/> So I using current year-month-day-hour-minute digits to generate cache filename. Hope you understand my idea <img
src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><hr
/><h5 style="text-align: center;"><strong><a
title="How to Easily display Digg posts via XSLT - demo 10" rel="nofollow" href="http://www.script-tutorials.com/demos/10/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="How to Easily display Digg posts via XSLT -  demo 10" rel="nofollow" href="http://www.script-tutorials.com/demos/10/source.zip">download  in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>Today I told you how to display digg posts at your own website via XSLT transformations. Hope all my code easy to understand and comfortable to use. You can use this material to create own scripts into your startups. Good luck!</p><div
class="shr-publisher-156"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-delicious-bookmarks-using-xslt/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/47.png" alt="How to Easily display Delicious bookmarks using XSLT transformation" /> <br
/> How to Easily display Delicious bookmarks using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-twitter-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Tweets using XSLT transformation" /> <br
/> How to Easily display Your Tweets using XSLT transformation</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-display-stumbleupon-posts-using-xslt-transformation/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily display Your Stumbleupon Favorites using XSLT" /> <br
/> How to Easily display Your Stumbleupon Favorites using XSLT</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/how-to-easily-display-digg-posts-via-xslt-using-digg-api/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic (User agent is rejected)
Database Caching using disk: basic

Served from: www.script-tutorials.com @ 2012-02-04 21:46:51 -->
