Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 14th, 2007, 03:21 PM
Authorized User
 
Join Date: Aug 2003
Location: Coeur d\'Alene, ID, USA.
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tachyon
Default 2 Questions on XSLT for RSS Feed

I just have 2 questions on XSLT (I'm a beginner).
1) How do you set the font to Arial
2) How do you make the <strong> tags work inside the RSS's <description> tag?
Example:
<rss version="2.0">
<channel>
<item>
<description>&lt;strong&gt;Hello&lt;/strong&gt;</description>
</item>
</channel>
</rss>

In Firefox I get <strong>Hello</strong> instead of "Hello" in bold.

Here's my file (XSL file below):
~~~~~~~~~~
<?xml version="1.0"?>
<?xml-stylesheet href="style.xsl" type="text/xsl"?>
<rss version="2.0">
    <channel>
        <title>Gears Online - Updates</title>
        <link>http://www.somewhere.com/updates/</link>
        <description>The latest stuff from Gears Online</description>
        <category>anime</category>
        <category>mecha</category>
        <image>
            <url>http://www.somewhere.com/test/gears-link.gif</url>
            <link>http://www.somewhere.com/updates/</link>
            <title>Gears Online - Updates</title>
            <description>Gears Online - Updates</description>
        </image>
        <language>en-us</language>
        <pubDate>Wed, 13 Jun 2007 15:00:00 -0700</pubDate>
        <ttl>1440</ttl>
        <item>
            <category>manga</category>
            <category>mecha</category>
            <description>&lt;strong&gt;Hello&lt;/strong&gt;&lt;p/&gt;Added new stuff to the page today.</description>
            <guid isPermaLink="false">33484f18-1a86-11dc-8314-0800200c9a66</guid>
            <link>http://www.somewhere.com/fss/newstuff.html</link>
            <pubDate>Wed, 13 Jun 2007 15:00:00 -0700</pubDate>
            <title>New Stuff on the Page</title>
        </item>
    </channel>
</rss>

~~~~~~~~~~~~~~~~
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <xsl:apply-templates select="/rss/channel"/>
    </xsl:template>
    <xsl:template match="/rss/channel">
        <div>
            <h1><xsl:value-of select="title"/></h1>
            <em><xsl:value-of select="description"/></em>
            [list]<xsl:apply-templates select="item"/></ul>
        </div>
    </xsl:template>
    <xsl:template match="/rss/channel/item">
        <li>
            <a href="{link}" title="{description}"><xsl:value-of select="title"/></a>
            <em> (<xsl:value-of select="pubDate"/>) </em>
            <div><xsl:value-of select="description"/></div>
        </li>
    </xsl:template>
</xsl:stylesheet>
__________________
An overworked Web Developer who\'s expected to know everything yet given time to study nothing.
Reply With Quote
  #2 (permalink)  
Old June 14th, 2007, 04:14 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

To set the the font for the entire document you can use CSS embedded your XSLT

Code:
 <style type="text/css">
    body {
font-family: arial;
    }
</style>
To set output to bold or strong you can use the span element:
Code:
 <xsl:template match="/rss/channel">
        <div>
            <h1><xsl:value-of select="title"/></h1>
            <span style="font-weight:bold;>
            <xsl:value-of select="description"/>
            </span>
            [list]<xsl:apply-templates select="item"/></ul>
        </div>
    </xsl:template>


Reply With Quote
  #3 (permalink)  
Old June 14th, 2007, 04:56 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>1) How do you set the font to Arial

That's not a question about XSLT, it's a question about your target vocabulary. If you're generating HTML, then find out how to set the font to Arial in HTML, and then write the XSLT to generate that HTML. If you're generating some other target vocabulary, such as XSL-FO or SVG, the same applies. You can't start writing XSLT code until you know what output you want to produce.

2) How do you make the <strong> tags work inside the RSS's <description> tag?

<description>&lt;strong&gt;Hello&lt;/strong&gt;</description>

There aren't any tags between the description start and end tags. The angle brackets have been escaped: you should only do this when you want them to be treated as text rather than as markup. I don't know why people escape markup to make it look like text, it's bad practice but it's sometimes done. It makes it very hard to process in XSLT. One workaround that works in some environments - but not Firefox - is to use disable-output-escaping which causes the serializer to turn the text back into markup.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old June 14th, 2007, 05:43 PM
Authorized User
 
Join Date: Aug 2003
Location: Coeur d\'Alene, ID, USA.
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tachyon
Default

>>If you're generating HTML, then find out how to set the font to Arial in HTML, and then write the XSLT to generate that HTML.

<xsl:output method="html"/>
I want to generate HTML. How to "write the XSLT to generate that HTML" is my question.
Reply With Quote
  #5 (permalink)  
Old June 14th, 2007, 06:00 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Well, the rule is: if you know what HTML you want to generate, tell us, and we can help you generate it. If you don't know what HTML you want to generate, then ask for help on an HTML forum.

(It's not really a question of which forum you use. It's a question of getting the separation of concerns right in your own mind. Designing the HTML page is one activity, designing the transformation to produce it is a completely separate task. And as Dijkstra once said, you should never start writing a program until you know what output you want it to produce.)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
validate rss feed arafat.eajaz RSS and Atom 2 September 6th, 2012 08:56 AM
Rss Feed in php surendran RSS and Atom 2 October 22nd, 2005 12:59 AM
RSS Feed to PHP in Array? sami PHP How-To 1 April 17th, 2005 04:53 PM
RSS Feed Shibu Classic ASP XML 0 January 21st, 2005 08:47 AM



All times are GMT -4. The time now is 08:23 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.