首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅xsl样式表部分正在工作。

仅xsl样式表部分正在工作。
EN

Stack Overflow用户
提问于 2018-08-13 04:08:01
回答 1查看 36关注 0票数 0

在这里输入图像描述我在期末考试上遇到了一些麻烦。我有我的XML,它被很好地验证了。我已经做了一个XSL,我只能在客户信息表中看到一个表。我已经尽了一切努力让其他桌子出现在网页上,什么也没有。请帮帮我。我会在评论部分张贴一张照片,这样每个人都可以看到正在发生的事情。另外,当我检查我的XSL时,它也得到了很好的验证,这就是为什么它如此令人困惑,我不知道我哪里出错了。

XML

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

发布于 2018-08-13 04:59:02

指定用于显示productvendororder信息的productvendororder信息是不正确的,这就是为什么在这些表的输出中没有得到任何结果。

节点<customers><product_information><vendor><orders>是彼此的兄弟关系,是orderform1的子元素,因此应该使用XPath orderform1/customersorderform1/product_information等进行访问。因此,用于XPath循环的for-each应该如下所示

代码语言:javascript
复制
<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>

其次,输入<customer>具有Customer Information重复的order节点和Order Information的重复order节点。可以使用for-each轻松地循环这些输出以获得所需的输出。

然而,对于获取Product InformationVendor Information,不存在productvendor这样的重复节点,多个productvendor的数据分别在单个节点product_informationvendor下可用。在这种情况下,for-each将无法为多个元素准备表,因为它将输出单个<td>中的所有数据。

如果使用XSLT2.0,则需要使用for-each-groupgroup-starting-with特性来准备输出数据。

我不确定输入XML是否遗漏了什么东西,但需要根据上述建议修复XSL,以使其正常工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51815077

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档