xsl stylesheet only part is working

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



xsl stylesheet only part is working



enter image description hereI am having some trouble with my final for a class. I have my XML and it is well-validated. I have made an XSL and I can only see one table in the customer information table. I have tried everything to make these other tables show up on the webpage and nothing. Please help me. I will post a picture in the comment section so everyone can see what is happening. Also when I check my XSL it is also well-validated, that is why its so confusing, I don't know where I am going wrong.



XML


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="vendor.xsl"?>
<!DOCTYPE orderform1 SYSTEM "vendor.dtd">
<orderform1>
<customers>
<customer>
<name>
<title>MR.</title>
<first>Bob</first>
<middle>Thomas</middle>
<last>Smith</last>
</name>
<mail_a>
<line1>453 N. Hartman St.</line1>
<line2></line2>
<city>Omaha</city>
<state>NE</state>
<zip>68111</zip>
</mail_a>
<c_num>001</c_num>
</customer>
<customer>
<name>
<title>MRS.</title>
<first>Mary</first>
<middle>Bell</middle>
<last>Moore</last>
</name>
<mail_a>
<line1>2104 Jones Ave.</line1>
<line2></line2>
<city>Carson City</city>
<state>NV</state>
<zip>89701</zip>
</mail_a>
<c_num>020</c_num>
</customer>
<customer>
<name>
<title>MISS.</title>
<first>Brittany</first>
<middle>Lynn</middle>
<last>Murry</last>
</name>
<mail_a>
<line1>3526 Jackson ST</line1>
<line2></line2>
<city>Millersburg</city>
<state>MO</state>
<zip>65251</zip>
</mail_a>
<c_num>003</c_num>
</customer>
<customer>
<name>
<title>DR.</title>
<first>Edward</first>
<middle>Taylor</middle>
<last>Jones</last>
</name>
<mail_a>
<line1>3411 Dewey Ave</line1>
<line2></line2>
<city>Fulton</city>
<state>MO</state>
<zip>65364</zip>
</mail_a>
<c_num>400</c_num>
</customer>
<customer>
<name>
<title>MS.</title>
<first>Anne</first>
<middle>Marie</middle>
<last>Love</last>
</name>
<mail_a>
<line1>3132 Willit St..</line1>
<line2></line2>
<city>Reno</city>
<state>NV</state>
<zip>89601</zip>
</mail_a>
<c_num>051</c_num>
</customer>
</customers>
<product_information>
<product_description>2 pack of Gold Forks</product_description>
<catgory>Ktichenware</catgory>
<upc>3426381901</upc>
<p_vend>ABC Inc.</p_vend>
<c_information>1 qty</c_information>
<cost>$2.99</cost>
<retail_cost>$6.99</retail_cost>
<product_description>4 pack of Teal Plates</product_description>
<catgory>Ktichenware</catgory>
<upc>942676142</upc>
<p_vend>ABC Inc.</p_vend>
<c_information>1 qty</c_information>
<cost>$10.24</cost>
<retail_cost>$24.99</retail_cost>
<product_description>6 pack of Clear Glass Drinking Glasses</product_description>
<catgory>Ktichenware</catgory>
<upc>3064491314</upc>
<p_vend>ABC Inc.</p_vend>
<c_information>1 qty</c_information>
<cost>$13.56</cost>
<retail_cost>$34.99</retail_cost>
<product_description>EVG A Geforce GTX 970 4GB SC Gaming ACX 2.0 26% cooler and 36% quieter cooling Graphics Card 04G-P4-2974-KR</product_description>
<catgory>Computer Hardware</catgory>
<upc>1706191112</upc>
<p_vend>Molly's Computer Repair</p_vend>
<c_information>1 qty</c_information>
<cost>$120.00</cost>
<retail_cost>$246.37</retail_cost>
<product_description>Corsair CMZ32GX3M4Z1600C10 Vengance 32GB (4x8GB) DDR3 1600 MHz (PC3 12800) Desktop Memory</product_description>
<catgory>Computer Hardware</catgory>
<upc>1231274213</upc>
<p_vend>Molly's Computer Repair</p_vend>
<c_information>1 qty</c_information>
<cost>$175.64</cost>
<retail_cost>$264.24</retail_cost>
<product_description>Axial LS1238,muffin 120V AC PC Cooling Fan</product_description>
<catgory>Computer Hardware</catgory>
<upc>0647069969</upc>
<p_vend>Molly's Computer Repair</p_vend>
<c_information>1 qty</c_information>
<cost>$2.99</cost>
<retail_cost>$14.99</retail_cost>
<product_description>Pink Lace Push-up Bra size 46 FF</product_description>
<catgory>Clothing</catgory>
<upc>3696841106</upc>
<p_vend>Love B's Underclothes Company</p_vend>
<c_information>1 qty</c_information>
<cost>$5.42</cost>
<retail_cost>$24.99</retail_cost>
<product_description>Themed Boy Shorts (Underware) 3 pair</product_description>
<catgory>Clothing</catgory>
<upc>4252698403</upc>
<p_vend>Love B's Underclothes Company</p_vend>
<c_information>1 qty</c_information>
<cost>$3.08</cost>
<retail_cost>$13.41</retail_cost>
<product_description>Mens White Ankle Sock (1 pack,8 pair)</product_description>
<catgory>Clothing</catgory>
<upc>1926769334</upc>
<p_vend>Love B's Underclothes Company</p_vend>
<c_information>1 qty</c_information>
<cost>$1.99</cost>
<retail_cost>$6.75</retail_cost>
</product_information>
<vendor>
<bus_name>ABC Inc.</bus_name>
<contact_information>Mattew Smith</contact_information>
<b_address>
<line1>511 N. 3rd</line1>
<line2></line2>
<city>Reno</city>
<state>NV</state>
<zip>89889</zip>
</b_address>
<vendor_id>982746</vendor_id>
<bus_name>Molly's Computer Repair</bus_name>
<contact_information>Bucky Daniels</contact_information>
<b_address>
<line1>9564 N.96th St.</line1>
<line2></line2>
<city>Elko</city>
<state>NV</state>
<zip>89801</zip>
</b_address>
<vendor_id>467910</vendor_id>
<bus_name>Love B's Underclothes Company</bus_name>
<contact_information>Kristie Robbs</contact_information>
<b_address>
<line1>549 S. 55 Ave.</line1>
<line2></line2>
<city>Reeding</city>
<state>CA</state>
<zip>96723</zip>
</b_address>
<vendor_id>116424</vendor_id>
</vendor>
<orders>
<order>
<date>04-20-2017</date>
<c_num>001</c_num>
<pur_deatails>6 pack of Clear Glass Drinking Glasses,Axial LS1238,muffin 120V AC PC Cooling Fan, Mens White Ankle Sock (1 pack,8 pair)</pur_deatails>
<total_before_tax>$56.37</total_before_tax>
<tax>$3.94</tax>
<total_after_tax>$60.31</total_after_tax>
<item_count>3</item_count>
</order>
<order>
<date>03-05-2016</date>
<c_num>020</c_num>
<pur_deatails>2 pack of Gold Forks, 4 pack of Teal Plates, Pink Lace Push-up Bra size 46 FF</pur_deatails>
<total_before_tax>$56.97</total_before_tax>
<tax>$3.98</tax>
<total_after_tax>$60.95</total_after_tax>
<item_count>3</item_count>
</order>
<order>
<date>07-13-2018</date>
<c_num>003</c_num>
<pur_deatails>2 pack of Gold Forks, 4 pack of Teal Plates, Themed Boy Shorts (Underware) 3 pair</pur_deatails>
<total_before_tax>$45.39</total_before_tax>
<tax>$3.17</tax>
<total_after_tax>$48.56</total_after_tax>
<item_count>3</item_count>
</order>
<order>
<date>02-29-2017</date>
<c_num>400</c_num>
<pur_deatails>EVG A Geforce GTX 970 4GB SC Gaming ACX 2.0 26% cooler and 36% quieter cooling Graphics Card 04G-P4-2974-KR, Corsair CMZ32GX3M4Z1600C10 Vengance 32GB (4x8GB) DDR3 1600 MHz (PC3 12800) Desktop Memory, Axial LS1238,muffin 120V AC PC Cooling Fan</pur_deatails>
<total_before_tax>$525.60</total_before_tax>
<tax>$36.79</tax>
<total_after_tax>$562.39</total_after_tax>
<item_count>3</item_count>
</order>
<order>
<date>10-10-2016</date>
<c_num>051</c_num>
<pur_deatails>6 pack of Clear Glass Drinking Glasses, Pink Lace Push-up Bra size 46 FF, Themed Boy Shorts (Underware) 3 pair</pur_deatails>
<total_before_tax>$73.39</total_before_tax>
<tax>$5.13</tax>
<total_after_tax>$78.52</total_after_tax>
<item_count>3</item_count>
</order>
</orders>
</orderform1>



XSL


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/" >
<html>
<head><title>Vendor Information</title>
</head>
<body>
<table border="1">
<thead>
<tr>
<th>Order Information</th>
</tr>
</thead>
<thead>
<tr>
<xsl:for-each select="orderform1/customers/customer">
<tr>
<td><h4>Customer Information</h4></td>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="mail_a"/></td>
<td><xsl:value-of select="c_num"/></td>
</tr>
</xsl:for-each>
</tr>
</thead>
<thead>
<tr>
<xsl:for-each select="customers/customer/product_information">
<tr>
<td><h4>Product Information</h4></td>
<td><xsl:value-of select="product_description"/></td>
<td><xsl:value-of select="catgory"/></td>
<td><xsl:value-of select="upc"/></td>
<td><xsl:value-of select="p_vend"/></td>
<td><xsl:value-of select="c_information"/></td>
<td><xsl:value-of select="cost"/></td>
<td><xsl:value-of select="retail_cost"/></td>
</tr>
</xsl:for-each>
</tr>
</thead>
<thead>
<tr>
<xsl:for-each select="orderform1/customers/customer/product_information/vendor">
<tr>
<td><h4>Vendor Information</h4></td>
<td><xsl:value-of select="bus_name"/></td>
<td><xsl:value-of select="contact_information"/></td>
<td><xsl:value-of select="b_address"/></td>
<td><xsl:value-of select="vendor_id"/></td>
</tr>
</xsl:for-each>
</tr>
</thead>
<thead>
<tr>
<xsl:for-each select="orderform1/customers/customer/product_information/vendor/orders/order">
<tr>
<td><h4>Order Information</h4></td>
<td><xsl:value-of select="date"/></td>
<td><xsl:value-of select="c_num"/></td>
<td><xsl:value-of select="pur_deatails"/></td>
<td><xsl:value-of select="total_before_tax"/></td>
<td><xsl:value-of select="tax"/></td>
<td><xsl:value-of select="total_after_tax"/></td>
<td><xsl:value-of select="item_count"/></td>
</tr>
</xsl:for-each>
</tr>
</thead>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>





Please show us how the expected output differs from the actual output. A rendered HTML screenshot is not of much use.
– Jim Garrison
Aug 13 at 4:36





Let me see if I can explain this because I am lost and need the help. My teacher did not give us what your final should look like. She just gives us a small outline on what i am to do. I can upload that if you want. In my XSL sheet only my first two threads and showing up, nothing at all is showing up below the first two theads if that makes any sense.
– Brandi Blankenfeld
Aug 13 at 4:45





I think adding the outline on what you're supposed to do will help, but what would help even more is adding the output that you've decided on based on the outline. Are you trying to get four different tables (one each for Customers, product_information, vendors, and orders)? One table with all of the information in it? Right now you have a single table with a bunch of thead (table header) rows (there should only be one thead in a table). If you can describe what your output should look like (or better yet, code a small html example by hand), we can get you back on track.
– Daniel Haley
Aug 13 at 17:46


Customers


product_information


vendors


orders





Also, if you created the XML and the DTD I would strongly suggest updating product_information and vendor so that the elements for individual products and vendors are grouped in another element instead of all being siblings of each other. This will make creating the XSLT much simpler. The answer by @aniket-v below mentions for-each-group and group-starting-with which are XSLT 2.0 only. If you're using a web browser as the XSLT processor, you won't be able to use XSLT 2.0; only 1.0.
– Daniel Haley
Aug 13 at 18:04


product_information


vendor


for-each-group


group-starting-with




1 Answer
1



The XPath specified for displaying the product, vendor and order information are incorrect and that is the reason, you are not getting any result in the output for those tables.


product


vendor


order



Nodes <customers>, <product_information>, <vendor> and <orders> are siblings of each other and child elements of orderform1 and hence should be accessed using XPath orderform1/customers, orderform1/product_information and so on. So your XPath for the for-each loops should look like


<customers>


<product_information>


<vendor>


<orders>


orderform1


orderform1/customers


orderform1/product_information


for-each


<xsl:for-each select="orderform1/product_information">
....
</xsl:for-each>

<xsl:for-each select="orderform1/vendor">
....
</xsl:for-each>

<xsl:for-each select="orderform1/orders/order">
....
</xsl:for-each>



Secondly, the input XML has repeating <customer> nodes for Customer Information and repeating order nodes for Order Information. These can be easily looped using for-each to get the required output.


<customer>


Customer Information


order


Order Information


for-each



However for getting Product Information and Vendor Information there are no repeating nodes like product or vendor and data for multiple product and vendor is available under a single node product_information and vendor respectively. In this case, the for-each will not work to prepare a table as it will output all the data in the single <td> for multiple elements.


Product Information


Vendor Information


product


vendor


product


vendor


product_information


vendor


for-each


<td>



If you are using XSLT 2.0, then you would need to use for-each-group and group-starting-with features to prepare the output data.


for-each-group


group-starting-with



I am not sure whether the input XML is missing something but the XSL needs to be fixed according to the above suggestions in order to get the things working.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS