繁体   English   中英

xsl:value-of无法正常工作

[英]xsl:value-of not working as intended

嗨,我是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>

使用时,将创建我的表,但未输入电话的值。 我可能是犯了一个业余错误,所以任何帮助都将非常有用,谢谢

我所有的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>

尝试

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

当您的模板与根节点匹配时,上下文位于<aboutus>节点上,因此您需要按照层次结构正确获取<phone>的路径(这假设所有XML和<aboutus>是根节点)

要么

不在乎层次结构,只想选择<phone>标记(假设只有一个)就可以尝试

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM