无法从根节点获取值

Unable to get value from root node

我正在为我的 xml 编写 xslt,但在尝试从根节点读取 ItemNumber 时卡住了。这是代码片段

XML

 <?xml version="1.0"?>
 <Items>
<Item ItemNumber="1251469">
    <ProductName>Cherub Baby 240ml Single - Light Blue</ProductName>
    <ProviderName>Cherub Baby</ProviderName>
    <Quantity>25</Quantity>
    <Price>7.99</Price>
</Item>
<Item ItemNumber="1148087">
    <ProductName>Dolby Metal-Black-Matte</ProductName>
    <ProviderName>Vestal Watches</ProviderName>
    <Quantity>4</Quantity>
    <Price>67.99</Price>
</Item>
</Items>

XSLT

  <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <xsl:for-each select="Items/Item">
    <table border="2">
      <tr bgcolor="#9acd32">
        <td>Provider: <xsl:value-of select="ProductName"/></td>
      </tr>
     <tr>
        <td>Item Number</td>
        <td>Quantity</td>
        <td>Unit Price</td>
        <td>Total</td>
    </tr>
    <tr>
        <td><xsl:value-of select="ItemNumber"/></td> <-- //unable to get the value
        <td><xsl:value-of select="Quantity"/></td>
        <td><xsl:value-of select="Price"/></td>
        <td><xsl:value-of select="Quantity * Price"/></td>
    </tr>
    <tr>
    <td style="border:none"></td>
    <td style="border:none"></td>
    <td style="border:none">Sub Total</td>
    <td><xsl:value-of select="Quantity * Price"/></td>
    </tr>
    </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

我需要类似 this.I 的输出,但在获取 ItemNumber 时遇到了问题。谁能指导我。我该如何阅读 属性。我们将不胜感激。

谢谢

给定 <Item ItemNumber="1148087">ItemNumber 是一个属性节点,您 select 使用 XPath 作为 @ItemNumber(或 attribute::ItemNumber,如果您想详细).您的尝试 select 是一个子元素,而不是属性。