1

xslt を使用して xml を変換しているときに結果が得られます。

xsl:value-of select=" //*[price='8.20']/@supplier "

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>1985</year>
    </cd>
        <cd supplier="justin">
        <title>Unchain my heart</title>
        <artist>Joe Cocker</artist>
        <country>USA</country>
        <company>EMI</company>
        <price>8.20</price>
        <year>1987</year>
    </cd>
</catalog>

xslt :

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My Supplier</h2>
    <table border="1">
    <xsl:value-of select="//*[price='8.20']/@supplier"/
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
4

2 に答える 2

0

一般的:

// - Traverse the whole document

//* - Any element in the document

//*[price = '8.20'] - Any element in the document that has a <price> child element
                      with the value 8.20

//*[price = '8.20']/@supplier - The @supplier attribute of any element in the document 
                                that has a <price> child element with the value 8.20

これらの条件に一致するドキュメント内のノードは 1 つだけで、値が「justin」であるため、出力は「justin」になります。

于 2013-02-11T17:42:04.310 に答える
0

*: 任意の要素

//: 任意の階層で (もう 1 つの方法は、特定の XPath を指定することです

*[price='8.20']: 子要素を持つ任意の要素price = '8.20'

//*[price='8.20']: 子要素を持つ任意の階層の任意の要素price = '8.20'

@supplier: 名前の属性supplier

//*/@suppliersupplier:任意の階層の任意の要素の下にある name の属性。

//*[price='8.20']/@suppliersupplier:子要素を持つ任意の階層の任意の要素の下の名前の属性price = '8.20'..

于 2013-02-11T17:46:30.063 に答える