Jump to content

Get Products, XLST for API code


Recommended Posts

Thought I'd share code in XSLT for how I pull the products on my site using Umbraco.

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<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"
       exclude-result-prefixes="msxml umbraco.library">


<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:variable name="numberOfItems" select="10" />
<xsl:variable name="excerptLength" select="200" />

<xsl:variable name="feed" select="string('http://manage.cmsplushosting.com/cmsproductsxml.php?type=hostingaccount')"/>
<!-- cache for 30 minutes (1.800 seconds) -->
<xsl:variable name="cacheRate" select="number(0)"/>

<xsl:template match="/">

<!-- start writing XSLT -->
<xsl:choose>
       <xsl:when test="$feed != ''">
               <xsl:variable name="feedContent" select="umbraco.library:GetXmlDocumentByUrl($feed)"/>
               <xsl:choose>
                       <xsl:when test="$feedContent != 'error'">
                               <xsl:call-template name="renderFeed">
                                       <xsl:with-param name="feedContent" select="$feedContent"/>
                               </xsl:call-template>
                       </xsl:when>
                       <xsl:otherwise>
                               <p>
                                       <strong>Feed Viewer Macro Error: Error fetching feed</strong><br />
                                       The feed '<xsl:value-of select="$feed"/>' could not be loaded. Verify that the feed url exists and that you have an
                                       active internet connection
                               </p>
                       </xsl:otherwise>
               </xsl:choose>
       </xsl:when>
       <xsl:otherwise>
               <p>
                       <strong>Feed Viewer Macro Error: No feed chosen</strong><br />
                       Please make sure to add a value in the "Feed Url" parameter
               </p>
       </xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="renderFeed">
<xsl:param name="feedContent"/>

<script type="text/javascript">
   function ChangeColor(tableRow, highLight)
     {
       if (highLight)
         {
           tableRow.style.backgroundColor = '#dcfac9';
         }
       else
     {
     tableRow.style.backgroundColor = 'white';
   }
 }

 function DoNav(theUrl)
 {
 document.location.href = theUrl;
 }
 </script>

 <xsl:for-each select="$feedContent//products/product [type = 'hostingaccount']">
     <xsl:sort select="monthly" order="descending"/>       


                <table width="65%">
                  <tr>
                    <td colspan="2"><h2><a href="http://manage.cmsplushosting.com/cart.php?a=add&pid={pid}" title="Click to add to cart">
                                       <xsl:value-of select="name" disable-output-escaping="yes"/>
                      </a></h2></td>
                  </tr>
                  <tr>
                    <td></td>
                    <td><xsl:value-of select="umbraco.library:StripHtml(description)" disable-output-escaping="yes"/></td>
                  </tr>
                  <tr>
                    <td colspan="2"> </td>
                  </tr>
                  <tr>
                    <td></td>
                    <td>  <!-- get price details -->
                                           <table style="border:1px solid black;" width="90%">
                                             <tr onmouseover="ChangeColor(this, true);" onclick="DoNav('http://manage.cmsplushosting.com/cart.php?a=add&pid={pid}&billingcycle=monthly');"
             onmouseout="ChangeColor(this, false);">
                                               <td align="right">Monthly:</td>
                                               <td>
                                                 <xsl:value-of select="/pricing/USD/prefix" disable-output-escaping="no"/>$<font style="color:red;"><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(pricing/USD/monthly), number($excerptLength), '...')" disable-output-escaping="yes"/></font>
                                               </td>
                                               <td>
                                                 <a href="http://manage.cmsplushosting.com/cart.php?a=add&pid={pid}&billingcycle=monthly" title="Click to add to cart">
                                                   Instant Signup
                                                 </a>
                                               </td>
                                             </tr>
                                             <tr onmouseover="ChangeColor(this, true);"
             onmouseout="ChangeColor(this, false);" onclick="DoNav('http://manage.cmsplushosting.com/cart.php?a=add&pid={pid}&billingcycle=semiannually');">
                                               <td align="right">6 Months:</td>
                                               <td>
                                                 <xsl:value-of select="/pricing/USD/prefix" disable-output-escaping="no"/>$<font style="color:red;"><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(pricing/USD/semiannually), number($excerptLength), '...')" disable-output-escaping="yes"/></font>                                                
                                               </td>
                                               <td>
                                                  <a href="http://manage.cmsplushosting.com/cart.php?a=add&pid={pid}&billingcycle=semiannually" title="Click to add to cart">
                                                   Instant Signup
                                                 </a>
                                               </td>
                                             </tr>
                                             <tr onmouseover="ChangeColor(this, true);"
             onmouseout="ChangeColor(this, false);" onclick="DoNav('http://manage.cmsplushosting.com/cart.php?a=add&pid={pid}&billingcycle=annually');">
                                               <td align="right">Yearly:</td>
                                               <td>
                                                 <xsl:value-of select="/pricing/USD/prefix" disable-output-escaping="no"/>$<font style="color:red;"><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(pricing/USD/annually), number($excerptLength), '...')" disable-output-escaping="yes"/></font>                                                
                                               </td>
                                               <td>
                                                  <a href="http://manage.cmsplushosting.com/cart.php?a=add&pid={pid}&billingcycle=annually" title="Click to add to cart">
                                                   Instant Signup
                                                 </a>
                                               </td>
                                             </tr>

                                           </table>
                    </td>
                  </tr>
   </table>
   <hr style="border-style: dashed;"/>                    

 </xsl:for-each>



</xsl:template>

</xsl:stylesheet>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated