[英]why data of xml file does not transform to html using xslt
I try to display the data of xml file into html table but when I link the xml file with xsl file the result in the web browser is: 我尝试将xml文件的数据显示到html表中,但是当我将xml文件与xsl文件链接时,Web浏览器中的结果是:
Mohammed 2000 Nasr 2000 Ahamed 2000
Mohammed 2000 Nasr 2000 Ahamed 2000
I read all the related questions in stack but no answer guide me. 我在堆栈中阅读了所有相关问题,但没有答案指导我。 anyone can help and I appreciate any help.
任何人都可以帮助,我感谢任何帮助。
the xml file xml文件
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="xml.xsl" type="text/xsl"?>
<emps>
<emp>
<ename>Mohammed</ename>
<esal>2000</esal>
</emp>
<emp>
<ename>Nasr</ename>
<esal>2000</esal>
</emp>
<emp>
<ename>Ahamed</ename>
<esal>2000</esal>
</emp>
</emps>
the xsl file xsl文件
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<html>
<body>
<xsl:template match="/">
<table>
<xsl:for-each select="emp">
<tr>
<td><xsl:value-of select="emps/ename"/></td>
<td><xsl:value-of select="/esal"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</body>
</html>
</xsl:stylesheet>
Your xslt is not well formed. 你的xslt形成不好。 Have a look at the following, changed XSLT:
看看下面的内容,更改了XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="emps"/>
</body>
</html>
</xsl:template>
<xsl:template match="emps">
<table>
<xsl:for-each select="emp">
<tr>
<td><xsl:value-of select="ename"/></td>
<td><xsl:value-of select="esal"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.