Yahoo' RSS <media:content> doesnt display image thumbnail - mediarss

I need to make thumbnails available in RSS, i.e. show pictures in RSS. I started
to use Yahoo' Media RSS module. Good documentation, good examples. Ok.
Here is my snippet of RSS' xml and__ it doesn't show pictures:
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<link>http://localhost:8080/dir/jrOreAeH/Pictures.html</link>
<item>
<title>Winter.jpg</title>
<link>http://localhost:8080/photo/iZ0Omnkt/Winter.html</link>
<media:content fileSize="105542" height="100"
url="http://localhost:8080/img/37/f5b44ca3/Winter.jpg?sizeM=2" width="100"/>
<pubDate>25/10/2010</pubDate>
</item>
<item>
<title>Edge.jpg</title>
<link>http://localhost:8080/photo/yfLmrjtu/Edge.html</link>
<media:content fileSize="28521" height="100"
url="http://localhost:8080/img/38/650b5132/Edge.jpg?sizeM=2" width="100"/>
<pubDate>25/10/2010</pubDate>
</item>
</channel>
</rss>
I believe xml is correct and images should be displayed, but in fact - is not. So, what's wrong?!

I have use this one working properly:
<media:thumbnail url="http://localhost:8080/img/38/650b5132/Edge.jpg?sizeM=2" />
<media:content url="http://localhost:8080/img/38/650b5132/Edge.jpg?sizeM=2" />

Try nesting the element inside the ..
Then if you are viewing the rss in a browser, the media elements sometimes do not show by default, view the source to see if your media elements are there.
You might have to use a php or asp script to turn the Rss into an XMLDocumnet object then
in php you can echo your html and feed variables.. for asp I had to call in a an XSL stylesheet to display the elements how you want..
ASP script to turn rss into dom doc..
XSL Stylesheet sample..
<xsl:variable name="title" select="title" />
<xsl:variable name="description" select="description" />
<xsl:variable name="thumb" select="media:content/media:thumbnail/#url" />
<p class="bold"><a style="text-decoration: none"><xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute><xsl:value-of select="$title" disable-output-escaping="yes"/></a></p>
<p><xsl:value-of select="$description" disable-output-escaping="yes"/></p>
<img src="{$thumb}" alt="{$title}"/>
</xsl:if>

Related

Get XML atribute using XSLT for a href on HTML

I have come across this problem while doing a home project and I honestly do not know how to solve it.
The goal is, using XSLT, get a certain attribute from my XML and add it to href.
<Video videoID="v0001" imageLink="IMG/VIDEO_IMG/v0001_img.jpg"/>
Then, by applying the XSLT, that looks kinda like this:
<xsl:template match="/">
<xsl:for-each select="Video"/>
<a href="X">
<img src="Y"/>
</a>
</xsl:template>
where X is the imageLink from the XML and Y is gonna be the local link to the XHTML page of that single video.
<!--The goal is getting something like this after using XSLT-->
<a href="VIDEOS/video_v0001.xhtml">
<img class="User" src="../IMG/VIDEO_IMG/v0001_img.png" alt="VideoImage"/>
</a>
Assume that your XML input is:
<?xml version="1.0" encoding="UTF-8"?>
<Videos>
<Video videoID="v0001" imageLink="IMG/VIDEO_IMG/v0001_img.jpg"/>
<Video videoID="v0002" imageLink="IMG/VIDEO_IMG/v0002_img.jpg"/>
</Videos>
Then the XSLT script performing your task can be:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xhtml" doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system= "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="Videos/Video">
<a href="VIDEOS/video_{#videoID}.xhtml">
<img class="User" src="../{substring-before(#imageLink, '.')}.png"
alt="VideoImage"/>
</a>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:transform>
As you can see, there should be 2 Attribute Value Templates ({...}),
one drawing the content from source videoID attribute and the other -
from imageLink.
In the second case the content to be copied is limited to the part
before the dot, because in this case file name extension is different.
Note that I used method="xhtml" and both doctype attributes for XHTML
page. Maybe in your case they should be different.
For a working example see http://xsltransform.net/jxWYjVH/1
To get a full HTML page, add <head> tag and other HTML stuff, according
to your needs, e.g. a stylesheet for User class.

adding CSS styling to the <xsl:element name="standard_element_name">

As per SO standards, I have researched this question in Google and Yahoo, and on W3Schools and other forums for hours before posting here.
All answers I have found so far are geared towards specialized XML languages and other application that are going to read the XML file.
I am not doing this, nor am I writing any other type of code (such as C++, Java, C#, etc; nor am I wanting to use JavaScript).
The small local site I am creating is using only files in HTML, XML, and XSL, and a hand full of image files stored as .jpg and png. There is nothing else.
My little site is running on a local PC based Windows 10 computer with IIS enabled. The site works and other computers can view it in the common web browsers (such as FireFox and Chrome) through the LAN.
The only issue is my coding.
My project is to create a very basic, static site with simple HTML to the output, using nothing but XML and XSLT.
I have an XSL file which defines all of the standard HTML tags in templates [such as (p) (div) (table) (tr) (th) (td), etc] I also have many custom tags, which is why I want to use XML.)
I have reached a point where I want to use the (xsl:element name=" "). For example, I want to define a typical HTML (p style="color:yellow;"), using the (xsl:element name="p").
Here is a small sample of xsl I already have:
<xsl:element name="p">
<xsl:value-of select="p" />
</xsl:element>
This works, and a very plain (p) tag is created in the output and all the text is displayed. But, it has no styling. In the browser output it looks like this
<p>
A paragraph of text in here.
</p>
Having explained the above, my question is (hoping to be very clear), how to do I use the (xsl: element name="p") as shown above to add style attributes to it so my HTML output looks something like this:
<p style="background-color:yellow; font-size: 16pt;">
A paragraph of text in here, which is now black on a yellow background and a 16 point font.
</p>
I have answered my own question, and have included my complete, actual XSLT and some of my XML file for others that may be struggling with this. The short answer is the (xsl:attribute name="style") that is directly below the (xsl:element name="div").
I have included the complete code, which creates a (div) in the output on the left side that remains in a fixed position (meaning it does not scroll). This is a space for a list of links to other chapters used as a menu. The short piece of code beginning with the (xsl:element name="div") and ending with the closing tag (/xsl:element) creates that area, and the (for-each) block reads all the (list-text) and (url) tags [children of the (side_menu_div) tag, then creates a list of links in the (div) area on the side.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="ROOT">
<html>
<head>
<xsl:element name="title">
<xsl:value-of select="title" />
</xsl:element>
</head>
<body style="background-color:#fffc99;">
<xsl:element name="div">
<xsl:attribute name="style">width: 10%; height: 100%; position: fixed; padding-right: 1em; background: white</xsl:attribute>
<xsl:for-each select="/ROOT/side_menu_div/link-text">
<xsl:variable name="index" select="position()" />
<a href="{/ROOT/side_menu_div/url[$index]}">
<xsl:value-of select="." />
</a>
<br/>
</xsl:for-each>
</xsl:element>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The actual XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/style-sheets/master.xsl"?>
<ROOT>
<title>Player's Core Rulebook</title>
<side_menu_div>
<link-text>Home Menu</link-text>
<url>/methasia_index.html</url>
<br></br>
<link-text>Preamble</link-text>
<url>/rulebooks/_players_core_rulebook/00-Preamble/Preamble.xml</url>
<link-text>Chapter 1</link-text>
<url>/rulebooks/_players_core_rulebook/01-Chapter-01/chapter_1.xml</url>
<link-text>Chapter 2</link-text>
<url>/rulebooks/_players_core_rulebook/02-Chapter-02/chapter_2.xml</url>
<link-text>Chapter 3</link-text>
<url>/rulebooks/_players_core_rulebook/03-Chapter-03/chapter_3.xml</url>
<link-text>Chapter 4</link-text>
<url>/rulebooks/_players_core_rulebook/04-Chapter-04/chapter_4.xml</url>
<link-text>Chapter 5</link-text>
<url>/rulebooks/_players_core_rulebook/05-Chapter-05/chapter_5.xml</url>
<link-text>Chapter 6</link-text>
<url>/rulebooks/_players_core_rulebook/06-Chapter-06/chapter_6.xml</url>
<link-text>Chapter 7</link-text>
<url>/rulebooks/_players_core_rulebook/07-Chapter-07/chapter_7.xml</url>
<link-text>Chapter 8</link-text>
<url>/rulebooks/_players_core_rulebook/08-Chapter-08/chapter_8.xml</url>
<link-text>Chapter 9</link-text>
<url>/rulebooks/_players_core_rulebook/09-Chapter-09/chapter_9.xml</url>
<link-text>Chapter 10</link-text>
<url>/rulebooks/_players_core_rulebook/10-Chapter-10/chapter_10.xml</url>
<link-text>Appendix</link-text>
<url>/rulebooks/_players_core_rulebook/11-Appendix/Players_Core_Rulebook_Appendix.xml</url>
</side_menu_div>

HTML Help, need easy way to change text on my site

i am making a website that will feature many articles that will always be changing, i am trying to find a way to quickly change the text in these articles as i am the only person who knows the code in the company.
I was thinking of having a text document or something that has the articles text and when it gets changed so does the text on the site.I just dont know how to implement this.
sorry if its hard to understand what i mean, im not too familiar with sleep these days.
You don't need any dynamic server code like the other answers are suggesting. Either a "static site generator" (there are uncountably many, but that should give you something to Google if my main answer doesn't satisfy you) or a client-side scripting.
XSLT was designed for this exact problem. It can be run client-side or server-side with xsltproc (for compatibility with dumb clients). XSLT 1.0 is well-supported by all common browsers, though if you need EXSLT extensions in IE you had to add shims. Note that Webkit-based browsers can't do XSLT on file:// URLs, either set up a local HTTP server or use Firefox.
I have a minimal example site set up here that includes multiple files in
one page: https://o11c.github.io/foo-test/foo-root.xml
foo-style.xml:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/index">
<html>
<body>
<h2>Merge test</h2>
<table border="1">
<tr>
<th>Attr</th>
<th>Value</th>
</tr>
<xsl:apply-templates select="document(include/#name)"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="root">
<xsl:for-each select="foo">
<tr>
<td><xsl:value-of select="#x"/></td>
<td><xsl:value-of select="text()"/></td>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template name="identity">
<xsl:copy>
<xsl:for-each select="node()|#*">
<xsl:call-template name="identity"/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
foo-root.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="foo-style.xslt"?>
<index>
<include name="foo-1.xml"/>
<include name="foo-2.xml"/>
</index>
foo-1.xml:
<?xml version="1.0"?>
<root>
<foo x="a">aa</foo>
<foo x="b">bb</foo>
<foo x="c">cc</foo>
</root>
foo-2.xml:
<?xml version="1.0"?>
<root>
<foo x="d">dd</foo>
<foo x="e">ee</foo>
<foo x="f">ff</foo>
</root>
Further resources:
XSLT 1.0 spec
XPath 1.0 spec - in particular the function reference
EXSLT extensions - node-set in particular is very useful.
xsltproc webpage
You could use wordpress, if you are building the site from scratch and not adding to an existing one. This will allow you to edit articles in a user friendly interface that will allow you to style the text and will be easier for other people in the company to edit as well. It's very fast to set up.
Or you could just keep the written text in the HTML file itself, but this may make it harder to maintain and style, and those not technical savvy may not be able to edit it or will end up breaking it.
Well you might do this using php and Mysql
You can easily display save the articles in mysql and you could create a simple user interface for the people respnsible for editing the code to edit it too easy

Problems with embedding youtube with xslt transforms

I have multiple video links from youtube stored in an xml file, I have added code that will allow these to be embedded, xml element is video. Each element is stored in an outer element with an id, and only sections with each id are only visible one at a time.
The pblem is that only 1 section has all of its videos embedded while others will either have none or will have the other sections videos. Code is shown below
<xsl:for-each select="item/items[#id='id1']">
<table>
<tr>
<th>Video</th>
<td></td>
<td>
<iframe width="512"
height="308"
src="{video}"
frameborder="0"></iframe>
</td>
</tr>
</table>
</xsl:for-each>
Is there another way to get this to work?
EDIT - Below is a sample xml file in the format of what I am transforming.
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="items.xsl"?>
<item>
<items id="id1">
<video>http://www.youtube.com/embed/0iCFi14Glbk</video>
</items>
<items id="id1">
<video>http://www.youtube.com/embed/rMCh4etBbkU</video>
</items>
These embedded videos should be displayed in a table as shown in the xsl above.
http://www.htmlgoodies.com/tutorials/web_graphics/article.php/3480061/How-To-Add-a-YouTube-Video-to-Your-Web-Site.htm
The link above shows the way in which i want this to work with the embeded video displayed
There was no problem with the code something was wrong with youtube

Using xsl:if doesn't include closing tag

Trying to use the following code to insert a google ad inside of a blog roll
<xsl:if test="position() = 3">
<object data="/frontpage_blogroll_center_top_728x90"
width="735"
height="95" ></object>
</xsl:if>
For some reason the closing tag </object> doesn't get rendered in the HTML and causes error. Is there anyway to resolve this?
There is no difference (except lexical) in XML between:
<object></object>
and
<object/>
These represent exactly the same XML element, and different XSLT processors are free whichever of the two representations above they choose.
If the long form of the element is really needed in HTML, this can be achieved by either:
Using <xsl:output method="xhtml"/> . The xhtml method is only available in XSLT 2.0.
Using <xsl:output method="html"/> . The result of the XSLT transformation will be an HTML document (not XML).
Using a trick, like:
<object data="/frontpage_blogroll_center_top_728x90" width="735" height="95" >
<xsl:value-of select="$vsomeVar"/>
</object>
where $vsomeVar has no value and will not cause anything to be output, but will trick the XSLT processor into thinking something was output and thus outputting the long form of the element.
Use html output method.
This stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:if test="true()">
<object data="/frontpage_blogroll_center_top_728x90"
width="735"
height="95" ></object>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Output:
<object height="95"
width="735"
data="/frontpage_blogroll_center_top_728x90"></object>
Tested with MSXSL, Xalan, Oracle, Saxon, Altova, XQSharp.