2016-04-16 104 views
0

我試圖做一個xsl如果語句看到我可以得到所有的價格高於一定數量顯示出來,但我不能讓它工作生病發布代碼,看看有沒有人可以看到我的錯誤,我有一個DTD和樣式表,但我不認爲有需要PST這些Xsl如果測試顯示價格gt

歡呼

XSL:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="html" /> 
    <xsl:template match="/SpecialOffers"> 
     <html> 
      <head> 
       <link href="style.css" rel="stylesheet" type="text/css" /> 
      </head> 
      <body> 
       <center> 
        <h1>Special Offer's SuperMarket </h1> 
       </center> 
       <div id="Title1"> 
        <p>Offers Above .99c</p> 
       </div> 
<div id="content"> 
        <table style="width:100%"> 
         <tr> 
          <td>Description</td> 
          <td>Price</td> 
          <td>Offer</td> 
          <td>Number Of items</td> 
         </tr> 
         <xsl:for-each select="Hygiene/haircare"> 
         <xsl:if test="Price &gt;= 10"> 
          <tr> 
           <td> 

            <xsl:value-of select="description"/> 
           </td> 
           <td> 
            <xsl:value-of select="Price"/> 
           </td> 
           <td> 
            <xsl:value-of select="Offer"/> 
           </td> 
           <td> 
            <xsl:value-of select="Number_of_items"/> 
           </td> 
          </tr> 



         </xsl:if> 
         </xsl:for-each> 

      </table> 
      </div>    
      </body> 
     </html> 
    </xsl:template> 
</xsl:stylesheet> 

XML:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE SpecialOffers SYSTEM "Offers.dtd"> 
<!-- <?xml-stylesheet type="text/xsl" href="SpecialOffersStyleSheet.xsl"?> --> 
<?xml-stylesheet type="text/xsl" href="LoopOffers.xsl"?> 
<?xml-stylesheet type="text/css" href="style.css" ?> 
<SpecialOffers> 
    <Hygiene> 
     <haircare hid="HS"> 
      <Price>3.99</Price> 
      <Offer> 2 for 1 </Offer> 
      <Number_of_items>2</Number_of_items> 
      <description>Head and Shoulders</description> 
     </haircare> 
     <haircare hid="HE"> 
      <Price>1.99</Price> 
      <Offer>30% Off </Offer> 
      <Number_of_items>2</Number_of_items> 
      <description>Herbal Essence</description> 
     </haircare> 
     <haircare hid="L"> 
      <Price>.99c</Price> 
      <Offer> Half Price </Offer> 
      <Number_of_items>1</Number_of_items> 
      <description>Loreal</description> 
     </haircare> 
     <face_body_care> 
      <Price>1.50 </Price> 
      <Offer>Half Price</Offer> 
      <Number_of_items>1</Number_of_items> 
      <description>Radox Shower Gel</description> 
     </face_body_care> 
    </Hygiene> 
    <Cleaning_Products> 
     <household> 
      <Price>2.99</Price> 
      <Offer>2 for 1</Offer> 
      <Number_of_items>2</Number_of_items> 
      <description>Mr Sheen</description> 
     </household> 
     <detergents> 
      <Price>3.50</Price> 
      <Offer>25% Off</Offer> 
      <Number_of_items>1</Number_of_items> 
      <description>Dettol</description> 
     </detergents> 
    </Cleaning_Products> 
    <Grocery> 
     <fruit fid="M"> 
      <name>Mango</name> 
      <Price>.99c</Price> 
      <Offer>6 for .99c</Offer> 
      <weight>2kg</weight> 
      <organic></organic> 
     </fruit> 
     <fruit fid="B"> 
      <name>Banana</name> 
      <Price>1.39c</Price> 
      <Offer>1kg</Offer> 
      <weight>1kg</weight> 
      <organic>Yes</organic> 
     </fruit> 
     <vegeatables> 
      <name>Carrot</name> 
      <Price>1.49</Price> 
      <Offer>1kg for 1.49</Offer> 
      <weight>1kg</weight> 
      <organic>No</organic> 
     </vegeatables> 
     <vegeatables> 
      <name>Cabbage</name> 
      <Price>.89c</Price> 
      <Offer>1</Offer> 
      <weight>1kg</weight> 
      <organic>Yes</organic> 
     </vegeatables> 
    </Grocery> 
    <Perishables> 
     <canned_goods> 
      <name>Tuna</name> 
      <Price>.99c</Price> 
      <Offer>Half Price</Offer> 
      <weight>500g</weight> 
     </canned_goods> 
     <canned_goods> 
      <name>Beans</name> 
      <Price>1.99c</Price> 
      <Offer>6 For 1.99</Offer> 
      <weight>500g each</weight> 
     </canned_goods> 
    </Perishables> 
    <Alcholic_Beverages> 
     <spirits> 
      <name>Vodka</name> 
      <Price>14.50</Price> 
      <Offer>Half Price</Offer> 
      <ml>70cl</ml> 
      <volume_acl>37.5%</volume_acl> 
     </spirits> 
     <spirits> 
      <name>Gin</name> 
      <Price>27.50</Price> 
      <Offer>20% Off</Offer> 
      <ml>1 Litre</ml> 
      <volume_acl>37.5%</volume_acl> 
     </spirits> 
     <spirits> 
      <name>Gin</name> 
      <Price>27.50</Price> 
      <Offer>20% Off</Offer> 
      <ml>1 Litre</ml> 
      <volume_acl>37.5%</volume_acl> 
     </spirits> 
     <wine> 
      <name>Proseco</name> 
      <Price>13.75</Price> 
      <Offer>10% Off</Offer> 
      <ml>1 Litre</ml> 
      <volume_acl>13.5%</volume_acl> 
     </wine> 
     <largers> 
      <name>Heinkein</name> 
      <Price>£6</Price> 
      <Offer>4 for 6</Offer> 
      <ml>500ml</ml> 
      <volume_acl>4%</volume_acl> 
     </largers> 
    </Alcholic_Beverages> 
    <Non-Alcholic_Beverages> 
     <cordials> 
      <can> 
       <name>7 Up</name> 
       <Price>5.00</Price> 
       <Offer>12 Pack</Offer> 
       <ml>330</ml> 
      </can> 
      <bottle> 
       <name>Coke</name> 
       <Price>1.39</Price> 
       <Offer>2 for 1</Offer> 
       <ml>1 Litre</ml> 
      </bottle> 
     </cordials> 
     <juice> 
      <name>Sunny D</name> 
      <Price>.75c</Price> 
      <Offer>Half Price</Offer> 
      <ml>1 Litre</ml> 
     </juice> 
    </Non-Alcholic_Beverages> 
</SpecialOffers> 
+0

請選擇** ** XSLT 1.0 **或** XSLT 2.0 - 不**都**。 –

回答

0

您的樣式表不能生成任何表格行的原因是您的源XML中沒有價格大於或等於10的護髮產品。

你的標題說「商情以上.99c」 - 如果你想顯示產品,其價格在0.99以上,你需要讓你的條件:

<xsl:if test="Price &gt;= 1"> 

需要注意的是這些產品在你的XML其價格爲0.99c將不會通過此測試 - 但不是因爲它們的價格低於閾值,而是因爲它們的價格不是數字。包括這些價格比較,您將不得不刪除貨幣 - 例如:

<xsl:if test="translate(Price, 'c', '') &gt;= .5"> 

上述適用於XSLT 1.0和也將使用XSLT 2.0處理器,只要工作了爲您的樣式表繼續被標記爲version="1.0",因爲它現在是。

+0

對不起,只有回到這個歡呼聲回答我的幫助後,我意識到一個簡單的錯誤是多少,我只是不能發現它爲我的生活感謝幫助:) – aero123