2012-05-21 59 views
2

XML路徑我有如下XML:與條件

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE inventory SYSTEM "books.dtd"> 
<inventory> 
    <book num="b1"> 
     <title>Snow Crash</title> 
     <author>Neal Stephenson</author> 
     <publisher>Spectra</publisher> 
     <price>14.95</price> 
     <chapter> 
      <title>Snow Crash - Chapter A</title> 
      <paragraph> 
       This is the <emph>first</emph> paragraph. 
       <image file="firstParagraphImage.gif"/> 
       afetr image... 
      </paragraph> 
      <paragraph> 
       This is the <emph>second</emph> paragraph. 
       <image file="secondParagraphImage.gif"/> 
       afetr image... 
      </paragraph> 
     </chapter> 
     <chapter> 
      <title>Snow Crash - Chapter B</title> 
      <section> 
       <title>Chapter B - section 1</title> 
       <paragraph> 
        This is the <emph>first</emph> paragraph of section 1 in chapter B. 
        <image file="Chapter_B_firstParagraphImage.gif"/> 
        afetr image... 
       </paragraph> 
       <paragraph> 
        This is the <emph>second</emph> paragraph of section 1 in chapter B. 
        <image file="Chapter_B_secondParagraphImage.gif"/> 
        afetr image... 
       </paragraph> 
      </section> 
     </chapter> 
     <chapter> 
      <title>Chapter C</title> 
      <paragraph> 
       This chapter has no images and only one paragraph 
      </paragraph> 
     </chapter> 
    </book> 
    <book num="b2"> 
     <title>Burning Tower</title> 
     <author>Larry Niven</author> 
     <author>Jerry Pournelle</author> 
     <publisher>Pocket</publisher> 
     <price>5.99</price> 
     <chapter> 
      <title>Burning Tower - Chapter A</title> 
     </chapter> 
     <chapter> 
      <title>Burning Tower - Chapter B</title> 
      <paragraph> 
       This is the <emph>second</emph> paragraph of chapter B in the 2nd book. 
       <image file="Burning_Tower_Chapter_B_secondParagraphImage.gif"/> 
       afetr image... 
      </paragraph> 
     </chapter> 
    </book> 
    <book num="b3"> 
     <title>Zodiac</title> 
     <author>Neal Stephenson</author> 
     <publisher>Spectra</publisher> 
     <price>7.50</price> 
     <chapter> 
      <title>Zodiac - Chapter A</title> 
     </chapter> 
    </book> 
    <!-- more books... --> 
</inventory> 

如何編寫遵循xmlpath中1.0:

1)返回提供的所有書籍的所有書的價格不等於14.95?

2)返回所有書籍thier價格是更大然後經過他們的書的價格。

感謝S IN提前。

+1

您正在使用什麼語言?請提供更多背景信息,並添加您嘗試完成目標的內容。不要只問'我該怎麼做'這個問題。 –

+1

沒有語言,我只是想了解xmlpath中1.0與條件 – URL87

回答

2

如何編寫遵循xmlpath中1.0:

1)返回所有提供的所有書籍的書的價格不等於14.95?

/inventory/book[price/text() != 14.95] 

「/ inventory/book」爲您提供名爲「inventory」節點的「books」的所有子元素。和「價格/文()!= 14.95」僅僅意味着對每本書,檢查其命名爲「價格」的子元素是否一個比14.95不同。而不是「/ inventory/book」,您可以使用「// book」來方便您的應用程序。 「// book」從當前節點(在這種情況下爲根元素)請求所有名爲「book」的後代元素

2)返回其價格大於其後的書的價格的所有書籍。

/inventory/book[price > following-sibling::book[position() = 1]/price] 
3

嘗試這些:提供的所有書的價格

1)返回所有的書不等於14.95?

/inventory/book[price != 14.95]/title 

2)返回所有的書,他們的價格比在他們之後的書的價格大。

/inventory/book[price>following-sibling::*[1]/price]/title