[英]why data of xml file does not transform to html using xslt
我嘗試將xml文件的數據顯示到html表中,但是當我將xml文件與xsl文件鏈接時,Web瀏覽器中的結果是:
Mohammed 2000 Nasr 2000 Ahamed 2000
我在堆棧中閱讀了所有相關問題,但沒有答案指導我。 任何人都可以幫助,我感謝任何幫助。
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>
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>
你的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.