0

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.

4
  • I think you are missing the top part of your XSLT (which could contain important information about why nothing is being output!). Also, is that an accurate representation of your XML, as your XSLT contains an xsl:for-each on the Statistics element, suggesting you expect more than one, but in your XML Statistics is the root element, so there will only ever be one. Thanks! Commented Jul 16, 2014 at 8:01
  • You don't need XForms to visualize XML. Transforming it to (X)HTML using XSLT is sufficient. Transforming XML to HTML is covered by stackoverflow.com/q/15956220/342546 and stackoverflow.com/q/4724700/342546. Commented Jul 16, 2014 at 8:13
  • Please add information how you tried to execute the code. Commented Jul 16, 2014 at 8:20
  • thanks, I tried it using eXide editor. a built in editor which comes with eXist-db. for visualising, I need xForms because I have a library that works fine with XForms. Commented Jul 16, 2014 at 13:36

2 Answers 2

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

With very simple xml input, use direct Xforms as Bill showed you. But if you got complex input, keep on going with XSLT to produce instances fitting your xforms. We're doing that and it's quite powerful, imho.
0

Try the following xslt code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
    <xsl:template match="/">
        <html>
            <head>
                <title>List output</title>
            </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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.