使用XSLT从XML数据转换为XForms

时间:2014-07-16 07:49:19

标签: xml xslt xforms

我想以XML格式可视化大量数据,我发现xForms是一个很好的选择。当我在谷歌上搜索它时,我发现xslt是一种在xml格式(xforms等)之间进行转换的工具。 我的目标只是在xforms中查看我的xml数据。

我编写了以下代码来进行转换。但我面临很多麻烦。

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

文件&#34; file.xml&#34;包含以下

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

执行该代码时,没有描述任何内容。 提前谢谢。

2 个答案:

答案 0 :(得分:2)

您可以使用不带XSLT的纯XForms构建表:

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

答案 1 :(得分:0)

尝试以下xslt代码:

<?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>
相关问题