Search code examples
xmlxsltxforms

Conversion from XML Data to XForms using XSLT


I want to visualise a bulk of data in an XML format, I found that xForms is a good choice for this purpose. while I'm googling it I found that xslt is a tool to transform between xml formats ( xforms among others). My goal is just to view my xml data in xforms.

I wrote the following code to do transformation. but I'm facing a lot of troubles.

        <head>
        <xforms:model id="my model">
        <xforms:instance xmlns="" id="i" src="file.xml">
        </xforms:instance>
        </xforms:model>    
        </head>
            <body>
                <h2>LIST</h2>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>"year"</th>
                        <th>"Count_Student"</th>
                        <th>"a50_60"</th>
                    </tr>
                    <xsl:for-each select="Statistics">
                        <tr>
                            <td>
                                <xsl:value-of select="year"/>
                            </td>
                            <td>
                                <xsl:value-of select="Count_Student"/>
                            </td>
                            <td>
                                <xsl:value-of select="a50_60"/>
                            </td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

where the file "file.xml" contains the following

    <Statistics>
    <year>2005_2006</year>
       <Count_Student>2</Count_Student>
       <a50_60>1</a50_60>
    </Statistics>

When executing that code, nothing is depicted. Thanks in advance.


Solution

  • You can build the table using pure XForms without XSLT:

    <table border="1">
      <tr bgcolor="#9acd32">
        <th>"year"</th>
        <th>"Count_Student"</th>
        <th>"a50_60"</th>
      </tr>
      <xforms:repeat nodeset="Statistics">
        <tr>
          <td>
            <xforms:output ref="year" />
          </td>
          <td>
            <xforms:output ref="Count_Student" />
          </td>
          <td>
            <xforms:output ref="a50_60" />
          </td>
        </tr>
      </xforms:repeat>
    </table>