x First time here? Check out the FAQ
  • Avatar85posts136karma

    Generate a custom XML feed

    Peter Alcock started this topic March 12, 2013 @ 02:54

    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 posted this reply March 12, 2013 @ 03:42

    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.


  • Avatar85posts136karma
    Comment with ID: 142975
    Peter Alcock posted this reply March 12, 2013 @ 03:49

    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 posted this reply March 12, 2013 @ 03:54

    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.


  • Avatar85posts136karma
    Comment with ID: 142980
    Peter Alcock posted this reply March 12, 2013 @ 04:02

    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?


  • Avatar85posts136karma
    Comment with ID: 142981
    Peter Alcock posted this reply March 12, 2013 @ 04:02

    Ah i stand corrected has worked thanks!!


Please login or Sign up To post replies