Xml xsl:未按预期工作的价值

Xml xsl:未按预期工作的价值,xml,xslt,Xml,Xslt,嘿,我是xml新手,正在尝试检索下面显示的电话号码的值 原始数据- <aboutus> <title>The about us page!</title><br/> <description>GameChat started in 1934 and was founded by Mr. Gary Cashew who established the business. </description>

嘿,我是xml新手,正在尝试检索下面显示的电话号码的值

原始数据-

 <aboutus>
    <title>The about us page!</title><br/>
    <description>GameChat started in 1934 and was founded by Mr. Gary Cashew who established the business.  
    </description><br/>
    <contact>
        <phone>07642345537</phone><br/>
        <email>GameChat@queries.co.uk </email><br/>
        <post>12 Foxtrot Road, FI23 632</post><br/>
    </contact>
</aboutus>
试图将数据转换为表的模板

<table border="1">
    <tr bgcolor="#9acd32">
      <th>Contact</th>
      <th>Information</th>
    </tr>
    <tr>
      <td>Phone</td>
      <td><xsl:value-of select="phone"/></td>
    </tr>
  </table>
使用时,会创建my table,但不会输入phone的值。我可能犯了一个业余错误,所以任何帮助都将是巨大的,谢谢

我所有的xlst代码都是这样的-

<?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>

        <table border="1">
          <tr bgcolor="#9acd32">
            <th>Contact</th>
            <th>Information</th>
          </tr>
          <tr>
            <td>Phone</td>
            <td>
              <xsl:value-of select="phone"/>
            </td>
          </tr>

        </table>
      </body>
    </html>

  </xsl:template>

</xsl:stylesheet>
试一试

由于您的模板与根节点匹配,上下文定位在该节点上,因此您需要根据层次结构获取要更正的路径,这是假设所有XML都是根节点

不关心层次结构,只想选择它假设只有一次尝试的标记

<xsl:value-of select="//phone" />

你能发布你的输入XML并完成XSLT吗?@LingamurthyCS,它只是没有正确格式化。如果不知道“当前节点”在此上下文中是什么,我们就无法知道select=phone是否正确。例如,若它是“是的,强盗”的一部分,它将是有效的。我也在寻找完整的XSLT。仅通过一个代码片段,无法知道它正在处理的当前节点..尝试了这两种方法,但不幸的是没有成功。谢谢,虽然我刚刚编辑了第一个不太正确。但鉴于您的示例XML和XSLT,我已经测试了这两种方法,并且这两种方法都很有效,所以您的问题肯定还有很多。你是如何确定它不符合兴趣的?我当时不知道:@lc535-为了便于查看,请单击“使用XSL转换XML”按钮,奇怪的是,我使用的是一个类似的网站,但结果却相反。非常感谢你的帮助!
<xsl:value-of select="//phone" />