We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27305
    • 173 Posts
    I was wondering if someone could help me with a page I have that I would like to integrate into modx.

    Its a xml file that gets transformed or styled with xsl, I have a massive list of products that at the moment I have put into modx by changing the page to xml, but what I really want to do it get it working with a template I have.

    The page without my template is http://www.eshop600.co.uk/asfasdf

    But I would like to insert it into a normal html template, I can’t for the life of me figure out how to do it. If I could it would save me a massive ammount of time and effort manually inputing all the products.

    Any help or pointers would be great.

    cheers
    simon
      I made my first site with modx
      ------------------------
      Shopping blog
      Sky+ HD
      • 21257 MODX Staff
      • 730 Posts
      I’m generally no advocate of iframes, but in this case, you could set up another MODx page containing a template variable , and use the "view port" widget to display that template variable inside a regular MODx html template.
      I’m not 100% sure if the value of the template variable would need to be the URL to your xml/xslt MODx document, or if you’d want to use the @DOCUMENT binding to refer to that document.

      http://modxcms.com/document-binding.html

      http://www.modxcms.com/view-port-widget.html

      I have not done this before myself - let me know how it goes.
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 27305
        • 173 Posts
        I was thinking that I could use an ifame right in the content area of my template, and just copy the iframe code linking to the xml page, but like you said im also not that keen. Not sure how google handles iframes.

        Thanks for the input, Anyone else have any ideas?

          I made my first site with modx
          ------------------------
          Shopping blog
          Sky+ HD
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Write a snippet that parses the XML and formats the data nicely for output on your pages. I’ve done that for very large XML files. Can’t say it was my favorite project, though. I’m not particularly fond of XML, I’ve run into too many badly formed structures (i.e. every data element was defined inside each item’s header!)
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 27305
            • 173 Posts
            I wouldnt know where to start with writing a snippet, it took me all day to take the xml feed, and use xsl to change it so everything has links and styles etc.

            I’ll need to do some research into the whole snippet writing thing, I struggle with php and the original xml files are a bit badly formed, there are lots of them and they don’t all appear to have the same structure.

            Basically the xml will update (with new products) quite often so I just want to drop it in the cms and let the xsl re-style it without me doing anything. I wonder if there is a plug-in that can read a xml or cvs and do the same as what the xsl was doing?

              I made my first site with modx
              ------------------------
              Shopping blog
              Sky+ HD
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              What would happen if you made a document that only had a snippet with a single line to include the xml file?
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 27305
                • 173 Posts
                I`m not sure that will work, but I will try, I think the xml needs the correct header to render properly. My templates are all html, so it would render the page as html and then insert the xml, I think you would just see the contents of the xml rather than it showing properly, will try now.
                  I made my first site with modx
                  ------------------------
                  Shopping blog
                  Sky+ HD
                  • 21257 MODX Staff
                  • 730 Posts
                  Maybe if you changed your doctype to a strict xhtml and tried to get your template to validate, then you could just include the xml right inside the html.
                  I’m not totally sure, but maybe you’d be lucky enough that the css would style the html elements and the xslt will style your custom xml structure.
                  xhtml is, afterall, just xml, and you can put xml inside xml. I’m not sure what, if anything, you’d need to do to your xslt because by sticking it in your html somewhere, the heirarchy is changing. But you must already have a handle on xslt. It’s been years for me, so I’m not going to pretend ;-)
                    Mike Schell
                    Lead Developer, MODX Cloud
                    Email: [email protected]
                    GitHub: https://github.com/netProphET/
                    Twitter: @mkschell
                    • 27305
                    • 173 Posts
                    Well I tried a snipped with a call to the xml and insterted into my normal template and the page didnt do anything just a white screen, this is however prob my lack of knowlege when it comes to writing spippets.

                    I`ll try and do the xhtml scrict, actually I know virtually nothing about xslt, it took me all day to get it working with the xml.
                      I made my first site with modx
                      ------------------------
                      Shopping blog
                      Sky+ HD
                      • 21257 MODX Staff
                      • 730 Posts
                      I just tried some stuff out for fun with your files, and was able to get the transformed xml wrapped in some html (ie your template).

                      It’s a simple proof of concept, and I’d be moved to re-think it once I got going with it, but here goes:

                      Make 2 documents in MODx.
                      * One will be your .xsl transform document - set it to no template and type text/xml, and paste in the contents of your .xsl file. You can give the document any alias, but note that you can put the .xsl extension in the alias if you like. And to be diligent, make sure it’s set up not to show in the menu, and maybe don’t let it be cached yet until you get it working nicely.
                      * The second document will be your xml file. Also set it to no template, type text/xml and paste the contents of your xml file. Same sentiments as above for the alias. Since it doesn’t really matter what the alias is, let’s call it "products.html".

                      Editing the products.html document, change the reference to the xsl file to a MODx document reference, like so (make sure you use the right document id of course):
                      <?xml version="1.0" encoding="ISO-8859-1"?>
                      <?xml-stylesheet type="text/xsl" href="[~49~]"?>
                      


                      Now if you load up products.html in your browser, it should look no different than http://www.eshop600.co.uk/asfasdf does already.

                      Here’s where the fun begins. Just open up your MODx xsl document and start adding html to it. Here’s an example of it just putting a header at the top of the page (I tightened up XML Spy’s xsl stuff output just for readability):
                      <?xml version="1.0" encoding="ISO-8859-1"?>
                      <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
                      <head>
                        <title>[(site_name)] | [*pagetitle*] published [*publishedon*] </title>
                        <base href="[(site_url)]"></base>
                      </head>
                      <body>
                      <h1>here's a header</h1>
                      	<xsl:for-each select="product/prod">
                      		<xsl:element name="a">
                      			<xsl:attribute name="href"> <xsl:value-of select="awLink"/></xsl:attribute>
                      			<img border="0" style="float:left"><xsl:attribute name="src"><xsl:value-of select="mThumb"/></xsl:attribute></img>
                      		</xsl:element>
                      		<p><b><xsl:value-of select="name"/></b></p>
                      		<p><xsl:value-of select="desc"/></p>
                      		<p><b>£<xsl:value-of select="price/search"/></b>
                      			<xsl:text xsl:space="preserve">   </xsl:text>
                      			<xsl:element name="a">
                      				<xsl:attribute name="href"> <xsl:value-of select="awLink"/></xsl:attribute>
                      				<xsl:value-of select="name"/> >>
                      			</xsl:element>
                      		</p><br /><br />
                      	</xsl:for-each>
                      </body>
                      </html>
                      


                      You should be able to move all of the elements of your standard template into this - this MODx xsl document is essentially now your template.
                      You can still re-jig this solution using actual template, chunks etc however you see fit, but this is at least a proof of concept.
                        Mike Schell
                        Lead Developer, MODX Cloud
                        Email: [email protected]
                        GitHub: https://github.com/netProphET/
                        Twitter: @mkschell