SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru Wullie's Avatar
    Join Date
    Oct 2002
    Location
    Greenock, Scotland
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stuck with XML/XSL

    Im working with XML/XSL for the first time today. Basically im displaying an RSS feed on my website. I have 2 little problems though. Below is the RSS item code that I recieve.

    Code:
    <item>
     <title>New driving force being launched for Highlands and Islands businesses</title> 
    
     <description>A major drive is being launched to equip firms with the skills they need to win new business for the Highlands and Islands. Highlands and Islands Enterprise (HIE) is using the internet to help firms and organisations across the region drive their performance up a gear</description> 
    
     <link>http://www.hie.co.uk/default.aspx.locid-0finewkh7.htm</link> 
    
     <pubDate>Thu, 07 Apr 2005 14:59:00 GMT</pubDate> 
    
     <enclosure url="http://www.hie.co.uk/GetImage.aspx.id-41105" length="0" type="image/jpeg" /> 
    
     <guid isPermaLink="false">0finewkh7</guid> 
    
     <source url="http://www.hie.co.uk/rss.aspx?id=553">HIE News</source> 
    
    </item>
    My first question is how to I format the pubDate value to be dd/mm/yy in my XSL template?

    My second question is how to i access the details in the enclosure tag? I can get the other detais no problem using
    Code:
    <xsl:value-of select="*[local-name()='title']"/>
    but this wont work for enclosure?

    Hope someone can help me out :'(

    Wullie
    ASP.NET Freelance Web Developer
    Bored? Check out my photography folio at Flickr

  2. #2
    SitePoint Addict Brak's Avatar
    Join Date
    Jul 2004
    Location
    Central Coast, CA
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you're overcomplicating things As for the date.. I'm not sure if that's possible without XSL2 or a regex library installed.

    As for your second question... you're sorely mistaken about how XPath works. You're basically saying, "I want to cycle through all the elements, and check if their local-name is equal to title" instead of just saying "I want the title element" which is by this method:

    Code:
    <xsl:value-of select="title" />
    By that same method:
    Code:
    <xsl:value-of select="enclosure" />
    Studio Rockstar's Blog - A journey to quitting the dayjob.

  3. #3
    SitePoint Guru Wullie's Avatar
    Join Date
    Oct 2002
    Location
    Greenock, Scotland
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Brak

    Thanks for the tip regarding the XPath. I still cant seem to work out how I get access to the url value or the type value of the enclosure though?

    Using <xsl:value-of select="enclosure" /> as you suggested does not return anything.

    :'(
    ASP.NET Freelance Web Developer
    Bored? Check out my photography folio at Flickr

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xslutput method="html"/>
    <xsl:template match="item">
    <xsl:value-of select="enclosure/@url"/>
    </xsl:template>
    </xsl:stylesheet>

  5. #5
    SitePoint Addict Brak's Avatar
    Join Date
    Jul 2004
    Location
    Central Coast, CA
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah... forgot to mention that There is nothing inside the enclosuer element, there are merely attributes. Attributes are called in XPath by the @ operator. So encloseure/@url will work just fine. You're syaing "I want the url attribute value for the enclosure element"
    Studio Rockstar's Blog - A journey to quitting the dayjob.

  6. #6
    SitePoint Member
    Join Date
    May 2005
    Location
    sweden
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A late reply but just wanted to say that you cann format the date by using the substring function in xsl (w3schools xslt reference) if you havent solved the problem.

    Cheers for my first post here at sitepoint.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •