Aditya Kaushik
Aditya Kaushik

Reputation: 211

Cannot view XML after applying XSL Transform

I have the following code structure :

XML :

<?xml version="1.0"?>
<?xml-stylesheet href="transform.xsl" type="text/xsl"?>
<javancss>
  <date>2013-02-28</date>
  <time>16:59:00</time>
  <packages>
    <package>
      <name>Package 1</name>
      <classes>3</classes>
      <functions>21</functions>
      <ncss>283</ncss>
      <javadocs>20</javadocs>
      <javadoc_lines>111</javadoc_lines>
      <single_comment_lines>11</single_comment_lines>
      <multi_comment_lines>221</multi_comment_lines>
    </package>
    <package>
      <name>Package 2</name>
      <classes>12</classes>
      <functions>411</functions>
      <ncss>8476</ncss>
      <javadocs>380</javadocs>
      <javadoc_lines>2193</javadoc_lines>
      <single_comment_lines>1224</single_comment_lines>
      <multi_comment_lines>6070</multi_comment_lines>
    </package>
    <package>
</packages>

Here is the XSL Transform to be applied to the file , so that each package record is shown in 1 row of the resultant HTML table

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"
            indent="yes"
            encoding="iso-8859-1"
            media-type="text/html"
            doctype-public="-//W3C//DTD HTML 4.0//EN"/>
<xsl:template match="/">
  <html>
  <body>
    <h2>Package List</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Name</th>
        <th>Classes</th>
    <th>Functions</th>
        <th>NCSS</th>
        <th>Javadocs</th>
        <th>Javadoc Lines</th>
    <th>Single Comment Lines</th>
      </tr>
      <xsl:for-each select="/javancss/packages/package">
        <tr>
          <td><xsl:value-of select="name"/></td>
          <td><xsl:value-of select="classes"/></td>
          <td><xsl:value-of select="functions"/></td>
          <td><xsl:value-of select="ncss"/></td>
          <td><xsl:value-of select="javadocs"/></td>
          <td><xsl:value-of select="javadoc_lines"/></td>
          <td><xsl:value-of select="single_comment_lines"/></td>
          <td><xsl:value-of select="multi_comment_lines"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

I am unable to view the output in any browser. I would like to know where I've gone wrong. Thanks.

Upvotes: 0

Views: 478

Answers (1)

Tim C
Tim C

Reputation: 70648

Here are some suggestions why it might not work:

1) Try changing the xsl:output method to 'html' rather than 'xml' as you are actually outputting HTML.

<xsl:output method="html" />

2) Ensure the file transform.xsl is in the same location as your XML file.

3) As JLRishie mentions in his comments, ensure your XML file is well-formed, with all tags correctedly closed.

Upvotes: 1

Related Questions