简体   繁体   中英

xsl with xml with attribute in root element does not work

I use a sw that generates a xml file and i'd like to present that file in an html file, so i begun to create a xsl file to do that for me. The problem is that i don't know how to address the errorlist root element due to the attributes. If i delete the attributes from the xml file the xsl works fine.

My xml file is:

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

My xsl so far is:

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

The problem is that if the attributes are present in the 'errorList' tag the output is a table with no lines but if i remove the attributes it works fine.

Add namespace declaration to 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">

Then use it:

<xsl:value-of select="k:errorList/k:problem/k:problemID"/>
<xsl:stylesheet version="1.0"
    xmlns:k="http://www.klocwork.com/inForce/report/1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

and then reference it as k:errorList .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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