2

私は次の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>

次のXmlPath1.0の書き方:

1)すべての本の価格が14.95に等しくない場合は、すべての本を返却しますか?

2)価格が後の本の価格よりも高いすべての本を返却します。

前もって感謝します 。

4

2 に答える 2

3

これらを試してください:

1)すべての本の価格が14.95に等しくない場合は、すべての本を返却しますか?

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

2)価格が後の本の価格よりも高いすべての本を返却します。

 /inventory/book[price>following-sibling::*[1]/price]/title
于 2012-05-21T16:43:01.603 に答える
2

次のXmlPath1.0の書き方:

1)すべての本の価格が14.95に等しくない場合は、すべての本を返却しますか?

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

「/inventory/ book」は、「inventory」ノードの「books」という名前のすべての子要素を提供します。「price/text()!= 14.95」は、単に各本について、「price」という名前の子要素の1つが14.95と異なるかどうかを確認することを意味します。「/inventory/ book」の代わりに、アプリケーションの便宜のために「//book」を使用することもできます。「//book」は、現在のノード(この場合はルート要素)から「book」という名前のすべての子孫要素を要求します

2)価格が後の本の価格よりも高いすべての本を返却します。

/inventory/book[price >  following-sibling::book[position() = 1]/price]
于 2012-05-21T17:10:29.047 に答える