Home > other >  Not able to fetch data from a nested xml document and populate xsl style sheet to result in html web
Not able to fetch data from a nested xml document and populate xsl style sheet to result in html web

Time:11-29

This is the total description, Im stuck at point 5. I tried with for-each, generating id and applying the template didn't seem to work for me not sure where I'm missing out. I just need to accomplish the 5th point need to populate item no, description and qty I'm confused on how to do that since its kind of nested xml.Can anyone please help with this I'm new to web technology trying to learn. Attaching my code below.

Go to the camping.xsl file in your text editor and begin designing your XSLT style sheet. John wants the report to include the following features:

  1. The name of the store as a main heading.
  2. A customer ID table providing each customer’s name, address, and ID, with customers listed alphabetically by customer name.
  3. Order tables following each customer ID table with the order information for that customer; the order tables are listed in descending order by the order ID.
  4. Each order table should include the date of the order and the order ID.
  5. Each order table should list the items purchased with the items purchased in the largest quantities listed first. If two products have the same quantity of items ordered, the products should be arranged alphabetically by the item ID.

this is the campingtxt.xml file

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="html" href="campingtxt.html"?>
<customers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <?xml-stylesheet type="html" version="2.0" href="campingtxt.xsl"?>  
    <customer cid="c5781">
        <name>Hardy, Joan</name>
        <street>105 Terrace Rd.</street>
        <city>Duncan</city>
        <state>NE</state>
        <zip>68634</zip>
        <orders>
            <order oid="51170">
                <date>8/2/2017</date>
                <item iid="p5148">
                    <description>Self-Inflating Pad</description>
                    <qty>2</qty>
                </item>
                <item iid="sb2818">
                    <description>Down Sleeping Bag</description>
                    <qty>2</qty>
                </item>
                <item iid="t7815">
                    <description>2 Person Tent</description>
                    <qty>1</qty>
                </item>
            </order>
            <order oid="52811">
                <date>8/11/2017</date>
                <item iid="led7331">
                    <description>LED Rechargeable Lantern</description>
                    <qty>1</qty>
                </item>
                <item iid="wp0312">
                    <description>Water Purifier</description>
                    <qty>1</qty>
                </item>
            </order>
        </orders>
    </customer>
    <customer cid="c5391">
        <name>Evans, Terry</name>
        <street>641 Greenway Blvd.</street>
        <city>Mount Hope</city>
        <state>OH</state>
        <zip>44660</zip>
        <orders>
            <order oid="52517">
                <date>8/1/2017</date>
                <item iid="wb7133">
                    <description>Insulated Water Bottle</description>
                    <qty>2</qty>
                </item>
                <item iid="gps1015">
                    <description>Zendo GPS meter</description>
                    <qty>1</qty>
                </item>
                <item iid="bl2815">
                    <description>Boot Laces (Medium)</description>
                    <qty>1</qty>
                </item>
                <item iid="tr8140">
                    <description>Trail Mix (Pouch)</description>
                    <qty>5</qty>
                </item>
                <item iid="fa8442">
                    <description>First Aid Kit (Pack Size)</description>
                    <qty>1</qty>
                </item>
                <item iid="bb7117">
                    <description>Blister Patches</description>
                    <qty>3</qty>
                </item>
            </order>
            <order oid="53003">
                <date>8/5/2017</date>
                <item iid="hp7814">
                    <description>Fiberglass Light Hiking Poles (Spring Adj.)</description>
                    <qty>1</qty>
                </item>
            </order>
            <order oid="54814">
                <date>8/6/2017</date>
                <item iid="sb6601">
                    <description>Solar Battery Recharging Unit</description>
                    <qty>1</qty>
                </item>
                <item iid="br9002">
                    <description>Bug Repellent (Deep Woodes)</description>
                    <qty>2</qty>
                </item>
                <item iid="sb8502">
                    <description>Sunblock SPF 30 (Hiking Size)</description>
                    <qty>6</qty>
                </item>
            </order>
        </orders>
    </customer>
    <customer cid="c5614">
        <name>Sandoval, Tammy</name>
        <street>641 Greenway Blvd.</street>
        <city>Galesburg</city>
        <state>ND</state>
        <zip>58035</zip>
        <orders>
            <order oid="52144">
                <date>8/3/2017</date>
                <item iid="sg8128">
                    <description>Polarized Snow Goggles</description>
                    <qty>1</qty>
                </item>
                <item iid="sh5591">
                    <description>Snow Helmet Women's</description>
                    <qty>1</qty>
                </item>
                <item iid="sb5317">
                    <description>Attack Snowboard Women's</description>
                    <qty>1</qty>
                </item>
                <item iid="pw6558">
                    <description>Insulated Pants Women's</description>
                    <qty>2</qty>
                </item>
                <item iid="pj5199">
                    <description>Insulated Jacket Women's</description>
                    <qty>1</qty>
                </item>
                <item iid="bl6638">
                    <description>Snowboard Leash</description>
                    <qty>1</qty>
                </item>
            </order>
            <order oid="53410">
                <date>8/6/2017</date>
                <item iid="ws6832">
                    <description>Snowshoes Women's</description>
                    <qty>1</qty>
                </item>
                <item iid="sp5588">
                    <description>Snowshoes Pair</description>
                    <qty>1</qty>
                </item>
            </order>
        </orders>
    </customer>
</customers>

Css file /* Default styles */

* {
   margin: 0px;
   list-style: none;
}

header, section, article {
   display: block;
}



/* Body styles */
body {
   font-family: Verdana, Geneva, sans-serif;
   background-color: white;
}

div#wrap {
   background-color: white;
   margin: 0px auto;
   width: 780px;
   border-left: 1px solid rgb(151, 151, 151);
   border-right: 1px solid rgb(151, 151, 151);

   box-shadow: rgb(191, 191, 191) 10px 0px 30px,
               rgb(191, 191, 191) -10px 0px 30px;
}

header {
   background-color: rgb(120, 157, 40);
   padding: 5px;
}

header h1 {
   font-size: 2.4em;
   color: rgb(150, 187, 60);
   text-shadow: black 1px 1px 1px,
                white 0px -2px 0px;
   margin-left: 20px;
}

section {
   margin-top: 10px;
   margin-left: 20px;

}

section h1 {
   font-size: 1.8em;
   color: rgb(51, 51, 51);
   text-shadow: rgb(150, 187, 60) 1px 1px 4px;
   margin: 0px 0px 30px 0px;
}

table.cdata {
   border-collapse: collapse;
   border: 1px solid rgb(151, 151, 151);
   background-color: rgb(231, 231, 231);
   font-size: 0.8em;
   margin-top: 10px;
   margin-bottom: 30px;
}

table.cdata th {
   text-align: left;
   background-color: rgb(191, 191, 191);
   border: 1px solid rgb(101, 101, 101);
   padding: 3px;
   width: 100px;
   font-weight: normal;
   vertical-align: top;
}

table.cdata td {
   text-align: left;
   width: 250px;
   border: 1px solid rgb(101, 101, 101);
   padding: 3px;
   vertical-align: top;
}

article {
   border-bottom: 1px solid rgb(111, 151, 71);
   padding-bottom: 15px;   
}

span {
   color: rgb(131, 131, 131);
}

table.items span.oid {
   float: right;
}

table.items span.date {
   float: left;
}

table.items tr {
   clear: both;
}

table.items {
   border-collapse: collapse;
   border: 1px solid rgb(191,211, 171);
   font-size: 0.8em;
   margin-top: 8px;
}

table.items td, table.items th {
   border: 1px solid rgb(151, 151, 151);
   padding: 3px 7px;
}

table.items thead tr:last-of-type th {
   font-weight: normal;
   background-color: rgb(191, 191, 191);
}

table.items tbody tr:nth-child(even) {
   background-color: rgb(231, 255, 211);
}

table.items tr td:nth-child(1) {
   width: 100px;
}

table.items tr td:nth-child(2) {
   width: 350px;
}

table.items tr td:nth-child(3) {
   width: 50px;
   text-align: right;
}

This is my campingtxt.xsl stylesheet which has to be converted to a html page

   <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="html" doctype-system="about:legacy-compat" encoding="UTF-8" indent="yes" />
   <xsl:template match="/">
      <html>
         <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>Customer Orders at Cairn Camping</title>
            <link href="cstyles.css" rel="stylesheet" type="text/css" />
         </head>
         <body>
            <div id="wrap">
               <header>
                  <h1>Cairn Camping Store</h1>
               </header>
               <section>
                  <h1>Customer Orders</h1>
                  <article>
                     <xsl:for-each select="customers/customer">
                     
                        <xsl:sort select="name" />
                        <table class="cdata">
                           <tr>
                              <th>Name</th>
                              <td>
                                 <xsl:value-of select="name" />
                              </td>
                           </tr>
                           <tr>
                              <th>Address</th>
                              <td>
                                 <xsl:value-of select="street"/>
                                 <br> 
                                 <xsl:value-of select="city" />
                                 , 
                                 <xsl:value-of select="state" />
                                 </br>
                                 <br> 
                                 <xsl:value-of select="zip" />
                                 </br>
                              </td>
                           </tr>
                           <tr>
                              <th>Customer ID</th>
                              <td>
                                 <xsl:value-of select="@cid" />
                              </td>
                           </tr>
                        </table>
                        <xsl:for-each select ="orders/order">
                        <xsl:sort select="@oid" order="descending" /> 
                        <table class="items">
                           <thead>
                              <tr>
                                 <th colspan="3">
                                    <span class="date">
                                       <xsl:value-of select="date" />
                                 </span>
                                 <span class="oid">
                                   <xsl:value-of select="@oid" />
                                  
                                 </span></th>
                              </tr>
                              <tr>
                                 <th>Item No.</th>
                                 <td><xsl:value-of select="iid" /> </td>
                                 <th>Description</th>
                                 <td><xsl:value-of select="description" /> </td>
                                 <th>Qty</th>
                                 <td><xsl:value-of select="qty" /> </td>
                              </tr>
                           </thead>
                           <tbody>
                              <tr>
                              </tr>
                           </tbody>
                        </table>
                        </xsl:for-each> 
                     </xsl:for-each>
                  </article>
               </section>
            </div>
         </body>
      </html>
   </xsl:template>
</xsl:stylesheet>

CodePudding user response:

Make that last tbody (that currently outputs a single empty row with <tbody<tr></tr></tbody>) output the items instead:

                      <tbody>
                          <xsl:for-each select="item">
                            <xsl:sort select="qty" data-type="number" order="descending"/>
                            <xsl:sort select="description"/>
                            <tr>
                              <td>
                                <xsl:value-of select="@iid"/>
                              </td>
                              <td>
                                <xsl:value-of select="description"/>
                              </td>
                              <td>
                                <xsl:value-of select="qty"/>
                              </td>
                            </tr>
                          </xsl:for-each>
                       </tbody>

In addition, I don't think that in the previous thead, you want six columns, you want three, with the names e.g.

                         <tr>
                             <th>Item No.</th>
                             <th>Description</th>
                             <th>Qty</th>
                          </tr>
  • Related