...

View Full Version : Javascript to run an XSLT on a webpage?



anamardoll
09-27-2011, 03:30 PM
Complete and utter newb here, so I apologize in advance.

I'm trying to create a widget for a website that will show the Recent Comments, but will limit what is shown to 1 comment per unique thread. The idea being that the popular threads don't drown out the unpopular threads in the widget.

Alas, I do not know Javascript. I am, however, proficient in XSLT. So I mapped out a little transform to get (essentially) what I want, thus:

Input: http://anamardoll.disqus.com/latest.rss

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template name="RSS_Feed" match="rss">
<xsl:value-of select="'&#xa;'"/>
<!-- ITERATE THROUGH ALL POST NODES -->
<xsl:for-each select="//item">
<!-- IF NOT PREVIOUSLY USED -->
<xsl:if test="not(preceding-sibling::item/child::title/node() = current()/child::title/node())">
<xsl:value-of xmlns:dc="http://purl.org/dc/elements/1.1/" select="child::dc:creator/node()"/>
<xsl:value-of select="(' posted on &#xa;')"/>
<xsl:value-of select="substring-after(child::title/node(), 'Ramblings: ')"/>
<xsl:value-of select="('&#xa;')"/>
<xsl:value-of select="child::link/node()"/>
<xsl:value-of select="('&#xa;&#xa;')"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


Output:

Ana Mardoll posted on
Twilight: It's All About The Protagonist, Baby
http://www.anamardoll.com/2011/09/twilight-its-all-about-protagonist-baby.html#comment-320798527

Thepepboy posted on
eReader: Running CM7 on a Nook Color from SD Card (REPOST)
http://www.anamardoll.com/2011/07/ereader-running-cm7-on-nook-color-from.html#comment-320690496

Jckeeml posted on
Narnia: The Clean and Tidy Poor
http://www.anamardoll.com/2011/09/narnia-clean-and-tidy-poor.html#comment-320649311

chris the cynic posted on
Metapost: Newsletter Subscriptions
http://www.anamardoll.com/2011/09/metapost-newsletter-subscriptions.html#comment-320586205


(And here is why I say the output is "essentially" what I want -- I'd PREFER the links to be linked around the preceding texts, but that's an advanced step at this point in the game.)

Is there an easy way in Javascript to just invoke an XSLT on a webpage and display the results? I've read online that there is, but can find no examples that work for me. I do appreciate any help provided and thank you in advance! :)

(Also, for background: This will be going into the Blogger HTML/Javascript Widget tool, so... yeah.)

DaveyErwin
09-27-2011, 09:33 PM
http://www.w3schools.com/xsl/xsl_client.asp

anamardoll
10-01-2011, 02:40 AM
Thank you. We ended up having to go this route.

http://www.anamardoll.com/2011/09/metapost-current-comments.html

But you can mark this as ended. Thanks! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum