xsl with xml with root element中的属性不起作用
发布时间:2020-12-16 22:59:55  所属栏目:百科  来源:网络整理 
            导读:我使用sw生成一个xml文件,我想在html文件中显示该文件,所以我开始创建一个xsl文件来为我做这个. 问题是我不知道如何解决由于属性导致的错误列表根元素.如果我从xml文件中删除属性,xsl工作正常. 我的xml文件是: errorList xmlns="http://www.klocwork.com/in
                
                
                
            | 
 我使用sw生成一个xml文件,我想在html文件中显示该文件,所以我开始创建一个xsl文件来为我做这个. 
  问题是我不知道如何解决由于属性导致的错误列表根元素.如果我从xml文件中删除属性,xsl工作正常. 我的xml文件是: <errorList xmlns="http://www.klocwork.com/inForce/report/1.0" version="9.1.0"> <problem> <problemID>1</problemID> <file>stdafx.h</file> </problem> <problem> ... </problem> </errorList> 到目前为止,我的xsl是: <?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>Issues</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>ProblemID</th>
        <th>File</th>
      </tr>
       <tr>
    <td><xsl:value-of select="errorList/problem/problemID"/></td>
    <td><xsl:value-of select="errorList/problem/file"/></td>    
        </tr>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>问题是,如果属性出现在’errorList’标记中,则输出是一个没有行的表,但是如果我删除属性它可以正常工作. 解决方法
 向XSLT添加名称空间声明: 
  
  
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:k="http://www.klocwork.com/inForce/report/1.0">然后使用它: <xsl:value-of select="k:errorList/k:problem/k:problemID"/> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! | 
