mercredi 23 octobre 2019

Tyring to take an xml/xslt table and place it onto a html webpage

I've recently made up an XML file for a project, accompanied with an XSLT Stylesheet to produce a simple table format once the XML is loaded into my web browser. Alongside, I have an HTML website that I am wanting to be able to take that generated table and place it onto the HTML webpage, so I can then style it accordingly in CSS alongside the rest of the website.

I have a set layout for my HTML website and I'm just simply wanting to move the table generated by the XML/XSLT and have it display on the HTML page.

My XML example page: XML

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="PT.xslt"?>
<!DOCTYPE owners [
<!ELEMENT owners (business+)>
<!ELEMENT business (servicetype, businessname, businesslogo*, servicepic+, url, address, phone+, operatinghours, services, description, rating*, averageprice, currentsales*)>
<!ELEMENT servicetype (#PCDATA)>
<!ELEMENT businessname (#PCDATA)>
<!ELEMENT businesslogo (#PCDATA)>
<!ELEMENT servicepic (#PCDATA)>
<!ELEMENT url (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT operatinghours (#PCDATA)>
<!ELEMENT services (minimumprice, hourlyfee)>
<!ELEMENT minimumprice (#PCDATA)>
<!ELEMENT hourlyfee (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT rating (#PCDATA)>
<!ELEMENT averageprice (#PCDATA)>
<!ELEMENT currentsales (#PCDATA)>
]>
<owners>
<business>
  <servicetype>Physical Training </servicetype>
  <businessname>Big Guns Fitness </businessname>
  <businesslogo>img/logo.jpg</businesslogo>
  <servicepic>service1.jpg</servicepic>
  <url>www.biggunz.net.au</url>
  <address>41 Lekemba Road, Rodstead 2259 NSW Australia </address>
  <phone>0483659150</phone>
  <operatinghours>0900-1700 Monday-Friday</operatinghours>
  <services>
    <minimumprice>$49.99</minimumprice>
    <hourlyfee>$49.99</hourlyfee>
  </services>
  <description>At Big Guns Fitness, we strive to deliver the greatest in expertise and professionalism, delivered to you in world class training and design.</description>
  <rating>4.9/5.0</rating>
  <averageprice>$89.49</averageprice>
  <currentsales>First Workout Free (ends 30th Sept 2019)</currentsales>
</business>

<business>
  <servicetype>Physical Training </servicetype>
  <businessname>Shape Up Bodyworks</businessname>
  <businesslogo>img/logo2.jpg</businesslogo>
  <servicepic>service2.jpg</servicepic>
  <url>www.SUBodyworks.com</url>
  <address>987 Wolka St, Harmet 8792 QLD Australia</address>
  <phone>0487373203</phone>
  <operatinghours>0900-1700 Monday-Thursday, 1000-1700 Friday</operatinghours>
  <services>
    <minimumprice>$19.99</minimumprice>
    <hourlyfee>$39.99</hourlyfee>
  </services>
  <description>Work hard, fast and the right way. Shape Up Bodyworks is the home of athletes, right in the heart of Peak Physical Training.</description>
  <rating>4.2/5.0</rating>
  <averageprice>$29.99</averageprice>
  <currentsales>Buy two PT sessions, get one half price</currentsales>
</business>

<business>
  <servicetype>Physical Training </servicetype>
  <businessname>Orion Supplements</businessname>
  <businesslogo>img/logo3.jpg</businesslogo>
  <servicepic>service3.png</servicepic>
  <url>www.OrionSupplements.fitness.au</url>
  <address>21 Kendall St, Albourke 2232 NSW Australia</address>
  <phone>0429487304</phone>
  <operatinghours>0800-1600 Monday-Wednesday, 0900-1700 Thursday-Friday</operatinghours>
  <services>
    <minimumprice>$9.99</minimumprice>
    <hourlyfee>$24.95</hourlyfee>
  </services>
  <description>Orion Supplements is the pinnacle of Physical Training and development supplements. A mix of pre-workout, and an actual workout. Fitness, just hit a whole nother level</description>
  <rating>5.0/5.0</rating>
  <averageprice>$22.49</averageprice>
  <currentsales>2x 2ltr Pre-workout shakers for $50</currentsales>
</business>
</owners>

My XSLT: XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
      <html>
          <head>
              <title>Businesses</title>
          </head>
          <body>

               <table border="1"  style="border-collapse:collapse;">
                 <tr bgcolor="#9acd32">
                     <th>Business Name</th>
                     <th>Service Type</th>
                     <th>Website</th>
                     <th>Business Logo</th>
                     <th>Service Picture</th>
                     <th>Address</th>
                     <th>Phone</th>
                     <th>Operating Hours</th>
                     <th>Minimum Price</th>
                     <th>Hourly Fee</th>
                     <th>Average Price</th>
                     <th>Description</th>
                     <th>Rating</th>
                     <th>Current Sales</th>
                 </tr>
                 <xsl:for-each select="owners/business">
                  <tr>
                    <td><xsl:value-of select="businessname"/></td>
                    <td><xsl:value-of select="servicetype"/></td>
                    <td><xsl:value-of select="url"/></td>
                    <td><img src="img/logo.jpg" width="100" height="100"/></td>
                    <td><img src="img/service1.jpg" width="250" height="120"/></td>
                    <td><xsl:value-of select="address"/></td>
                    <td><xsl:value-of select="phone"/></td>
                    <td><xsl:value-of select="operatinghours"/></td>
                    <td><xsl:value-of select="services/minimumprice"/></td>
                    <td><xsl:value-of select="services/hourlyfee"/></td>
                    <td><xsl:value-of select="averageprice"/></td>
                    <td><xsl:value-of select="description"/></td>
                    <td><xsl:value-of select="rating"/></td>
                    <td><xsl:value-of select="currentsales"/></td>
                  </tr>
                 </xsl:for-each>
               </table>
          </body>
      </html>
  </xsl:template>
</xsl:stylesheet>

I really hope someone could help me out :D




Aucun commentaire:

Enregistrer un commentaire