Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Alcock 113 posts 176 karma points
    Mar 12, 2013 @ 14:54
    Peter Alcock
    0

    Generate a custom XML feed

    Hi all,

    Been trying to crack this for a while but no joy! I basicaly want to create an XML (URL) which contains details on properties on my website.

    In essence what i need is this following simple XSLT done in a way that when you go on the URL it's a XML format that can be red by RSS readers if that makes sense!

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@isDoc and @level = 1]" />

     

    <xsl:for-each select="$siteRoot/descendant-or-self::*[@isDoc and name() = 'AProperty']">

    <item>

    <title><xsl:value-of select="@nodeNAme"/></title>

    </item>

    </xsl:for-each>

    Hopefully it's simple an im being a bit silly!

    Thanks

    Pete

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 12, 2013 @ 15:42
    Lee Kelleher
    0

    Hi Peter,

    Looking at your example XSLT, it is most likely the casing of "@nodeNAme" (XSLT is case-sensitive), try "@nodeName", see if that works.

    Cheers, Lee.

  • Peter Alcock 113 posts 176 karma points
    Mar 12, 2013 @ 15:49
    Peter Alcock
    0

    Hi Lee, I wish unfortunatly just a spelling mistake made putting the code on here, heres my full XSLT which when going on the page shows everything i want but isnt in the usual XML and cant be read by a reader.

     

    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        exclude-result-prefixes="msxml umbraco.library"

        <xsl:output method="xml" omit-xml-declaration="yes"/> 
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@isDoc and @level = 1]" />
    <xsl:param name="currentPage"/>

          <xsl:template match="/">
          
              <xsl:call-template name="BOB"
              </xsl:call-template>
              
           
          </xsl:template>
          
    <xsl:template name="BOB">
      
     <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</xsl:text
     <xsl:text>&lt;rss&gt;</xsl:text><br />
     <xsl:text>&lt;channel&gt;</xsl:text><br />
     <xsl:text>&lt;title&gt;</xsl:text>Premier Blog<xsl:text>&lt;/title&gt;</xsl:text<br />
     <xsl:text>&lt;link&gt;</xsl:text>http://www.premiervillasinthesun.com/blog<xsl:text>&lt;/link&gt;</xsl:text><br />
     <xsl:text>&lt;description&gt;</xsl:text>Just another WordPress site<xsl:text>&lt;/description&gt;</xsl:text><br />
      <xsl:text>&lt;lastBuildDate&gt;</xsl:text>Tue, 05 Mar 2013 12:13:21 +0000<xsl:text>&lt;/lastBuildDate&gt;</xsl:text<br />
      <xsl:text>&lt;language&gt;</xsl:text>en-US<xsl:text>&lt;/language&gt;</xsl:text<br />
      <br />
    <xsl:for-each select="$siteRoot/descendant-or-self::*[@isDoc and name() = 'AProperty']">

     
       <xsl:text>&lt;item&gt;</xsl:text>
      <xsl:text>&lt;title&gt;</xsl:text><xsl:value-of select="@nodeName"/> <xsl:text>&lt;/title&gt;</xsl:text>
      <xsl:text>&lt;/item&gt;</xsl:text>
      <br />
    </xsl:for-each>
      
      <xsl:text>&lt;/channel&gt;</xsl:text><br />
      <xsl:text>&lt;/rss&gt;</xsl:text>
     
    </xsl:template>

    </xsl:stylesheet>

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 12, 2013 @ 15:54
    Lee Kelleher
    0

    Not sure if it's a copy-n-paste issue (on this forum), but looks like you are escaping all the angle-brackets ... so the rendered "XML" output, is not really XML, but HTML-escaped text.  If that's the case, try removing all the <xsl:text> elements and swapping all the escaped entities, (e.g. &lt and &gt) to proper angle-brackets.

    Cheers, Lee.

  • Peter Alcock 113 posts 176 karma points
    Mar 12, 2013 @ 16:02
    Peter Alcock
    0

    Hi Lee,

    Just trued it without but it seems to render even less on the page ah! 

    now using

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        exclude-result-prefixes="msxml umbraco.library"

        <xsl:output method="xml" omit-xml-declaration="yes"/> 
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@isDoc and @level = 1]" />
    <xsl:param name="currentPage"/>

          <xsl:template match="/">
          
              <xsl:call-template name="BOB"
              </xsl:call-template>
              
           
          </xsl:template>
          
    <xsl:template name="BOB">
     <rss><br />
    <channel>
     <title>Premier Blog</title<br />
     <link>http://www.premiervillasinthesun.com/blog</link><br />
     <description>Just another WordPress site</description><br />
      <lastBuildDate>Tue, 05 Mar 2013 12:13:21 +0000</lastBuildDate<br />
      <language>en-US</language<br />
      <br />
    <xsl:for-each select="$siteRoot/descendant-or-self::*[@isDoc and name() = 'AProperty']">

     
       <item>
      <title><xsl:value-of select="@nodeName"/> </title>
      </item>
      <br />
    </xsl:for-each>
      
      </channel><br />
      </rss>
     
    </xsl:template>

    </xsl:stylesheet>

     

    Which when the url is loaded just gives me

    http://www.premiervillasinthesun.com/blog
    Just another WordPress site
    Tue, 05 Mar 2013 12:13:21 +0000
    en-US

    Any ideas?

  • Peter Alcock 113 posts 176 karma points
    Mar 12, 2013 @ 16:02
    Peter Alcock
    0

    Ah i stand corrected has worked thanks!!

Please Sign in or register to post replies

Write your reply to:

Draft