We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19315
    • 84 Posts
    This is an auto-generated support/comment thread for [SNIPPET] xslt.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Translates a remote XML feed using a local XSL file
      • 19315
      • 84 Posts
      Hey All,

      Hope you find this a bit useful. This is my first snippet, any help, tips improvements, corrections etc. very welcome!

      Michal.
        • 7923
        • 4,213 Posts
        Thanks alot for contributing! Nice to see more and more people coding addons, Good job! smiley


          "He can have a lollipop any time he wants to. That's what it means to be a programmer."
          • 25
          • 5 Posts
          How can I get this to work? Can you provide a .xslt-File that works in ModX for testing and adopting? Would be great.
            • 30317
            • 7 Posts
            I am surprised more folks are not using this to pull news feeds into their sites.. It seems like a clean and simple solution. Thanks for this valuable contribution, michalc!

            However, I can’t seem to get it to work. I am getting the following error when I try to call the snippet:
            Parse error: syntax error, unexpected '<' in /usr/home/{path-to-modX}/manager/includes/document.parser.class.inc.php(748) : eval()'d code on line 2


            Any ideas on how to troubleshoot this?

            My snippet call is:
            [!xslt? &xmlURL=`http://rss.manchesteronline.co.uk/news.xml` &xslFile=`[(filemanager_path)]/assets/snippets/xsl/news_transform.xsl` &xslParams='someExampleParameter:3,otherParemeter:yes' !]
              • 7923
              • 4,213 Posts
              What version of modx are you using? take the <?php and ?> off from the snippet code.


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 30317
                • 7 Posts
                Thanks for your help -I’m using the 0.9.5 release. When I created the snippet, the <?php ..... ?> wrapper tags are in the snippet area, so I left them.
                Based on your suggestion, I’ve tried removing them and that didn’t help. When I tried removing those tags, the are re-inserted when the snippet is saved.

                After quite a bit of testing, I discovered that there was a bad URL for the XSLT - even though I had tested it.. doh! (We have two ModX instances on the server, I put the xsl in the wrong place...it tested as a good url, until I used [(filemanager_path)]....

                Anyway...after sorting that out, and using simple URLs for the rss feeds, I got it working for some sample RSS feeds ( grin Yeah!!)

                However, I was trying to publish and RSS feed from Google Docs, so that my team members could collaborate in GoogleDocs, and then use the RSS feeds to show published documents. It seems that there is either a problem with the parsing of the Google RSS feed url, or the actual XML that it serves. The error I’m getting now is:
                PHP error debug
                  Error: 	domxml_open_mem() [function.domxml-open-mem]: SystemLiteral " or ' expected 	 
                  Error type/ Nr.: 	Warning - 2	 
                  File: 	/usr/home/lri/www/htdocs/lrtwo/MODx2/manager/includes/document.parser.class.inc.php(748) : eval()'d code	 
                  Line: 	62	 
                 
                


                This looks to me like it is having a problem parsing the XML, but I looked at the XML and it seems very clean to me.

                Here’s a XSLT call that works, followed by one that fails:
                [!xslt? &xmlURL=`http://www.nytimes.com/services/xml/rss/nyt/Technology.xml` &xslFile=`[(filemanager_path)]/assets/snippets/xsl/news_transform.xsl` !]
                



                The one that causes the error above:
                [!xslt? &xmlURL=`http://docs.google.com/RSSFeed?userID=ajmh8zk59mfq&authToken=P1H5RjnaOCd3D0sRjKoo9M00&tags=Publish-To-LR.com&recentDocs=false&x=` &xslFile=`[(filemanager_path)]/assets/snippets/xsl/news_transform.xsl`!]
                


                If I get this all working I’ll try to write it up and share it - it’s pretty nifty to use google docs to collaborate on a document, then pipe the final document into ModX. Step one is to get the RSS feed working, but I would prefer to grab the entire article, which I can do down the line...(googledocs supports several blog publishing APIs.)

                Thanks again for any help or suggestions!

                Tom
                  • 30317
                  • 7 Posts
                  Just an update on the problem I’m having with PHP parsing the RSS feed from Google. I suspect that it’s a problem with quotes in the xml header.

                  Here are the headers for the XML that work:
                  NY Times:
                  <?xml version="1.0" encoding="UTF-8"?>
                  <rss version="2.0">
                  <channel>
                  ...
                  


                  Manchester Online:
                  <?xml version="1.0" encoding="UTF-8"?>
                  <rss version="0.91">
                    <channel>
                  
                  ...
                  


                  And the one that is causing the errors below from Google (note the single quotes in the RSS version number) - perhaps screwing up PHP parsing of the string?
                  <?xml version="1.0" encoding="utf-8" ?> 
                  <rss version='2.0'>
                  	 <channel>
                  ...
                  



                    • 1932
                    • 137 Posts
                    Tom, consider taking a look at FeedX. It’s not XSL-based but you might have better luck with parsing.
                      • 30317
                      • 7 Posts
                      :) I finally got it working!

                      Thanks for pointing me to FeedX - the support thread there tipped me off to the problem. It seems that the snippet parsing can’t handle complex URLs as parameters. So you need to replace the "?" ,"=" and "&" with something else, and then when you are handling the URL, you need to restore these values.

                      FeedX chose to use their own string substitution values, (|xq| for Questionmark, |qe| for Equals, and |qa| for Ampersand), which are easy to remember, but not standard.

                      Instead, I escape my URL before putting it in the snippet. One quick way to do this is to copy your complex URL to the clipboard, then in your favorite browser’s address type:
                      javascript:escape("YOUR-URL-HERE");
                      


                      (For this to work, you need to make sure that your pasted URL is surrounded by quotes.)

                      When you hit return, the value of the escaped URL is displayed (all the ?’s changed to %3F, all the spaces changed to %20, etc.) Now use this escaped URL in your snippet.

                      The snippet needs to be modified to unencode the URL.

                      In the case of the XSLT snippet, I modified the snippet to decode the URL right before the CURL call. So in the XSLT Snippet, I added the following line , just before "//Create Curl Session"
                       $xmlURL = urldecode($xmlURL); 
                      


                      And now, everything seems to work!

                      It would be nice if all the snippets standardized on encoding URLS, so that there would be less to remember when moving among snippets. I suggest that standard URL encoding and decoding would be a best practice...

                      Anyway, hope my exploration of this, and suggested patch for XSLT help other Feed Readers and XML digesting folks.

                      Cheers.

                      Tom