以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 XML工具及XML开发环境 』 (http://bbs.xml.org.cn/list.asp?boardid=7) ---- 如何编写下面的xsl,将xml转化为html,本人好急啊!! (http://bbs.xml.org.cn/dispbbs.asp?boardid=7&rootid=&id=12209) |
-- 作者:highshow -- 发布时间:11/21/2004 7:47:00 PM -- 如何编写下面的xsl,将xml转化为html,本人好急啊!! 问题:如何写出trans.xsl,将下面的student.xml转换为student.html? student.xml的内容如下: <?xml version="1.0" encoding="GB2312" ?> <dsStudent> <StudentInfo> <StudentName>吴大帅</StudentName> <StudentAge>22</StudentAge> <StudentSex>男</StudentSex> <StudentEMail>213@sina.com</StudentEMail> </StudentInfo> <Lesson> <Name>Math</Name> </Lesson> <Lesson> <Name>English</Name> </Lesson> <Lesson> <Name>Primary</Name> </Lesson> </dsStudent> 要求转换成的student.html如下: <html> <head> <title>New Page 1</title> </head> <body> <table border="1" width="37%"> <tr> <td width="18%">姓名:</td> <td width="25%">吴大帅</td> <td width="22%">年龄:</td> <td width="37%">22</td> </tr> <tr> <td width="18%">性别:</td> <td width="25%">男</td> <td width="22%">EMAIL:</td> <td width="37%">213@sina.com</td> </tr> </table> <table border="1" width="38%" height="65"> <tr> <td width="100%" height="16">该学生所学课程如下:</td> </tr> <tr> <td width="100%" height="15">Math</td> </tr> <tr> <td width="100%" height="16">English</td> </tr> <tr> <td width="100%" height="16">Primary</td> </tr> </table> </body> </html> 本人写了一个,可就是不行,如下: <?xml version='1.0' encoding="GB2312"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="dsStudent"> <html> <head> <title>New Page 1</title> </head> <body> <xsl:for-each select="StudentInfo"> <table border="1" width="37%"> <tr> <td width="18%">姓名:</td> <td width="25%"><xsl:value-of select="StudentName"/></td> <td width="22%">年龄:</td> <td width="37%"><xsl:value-of select="StudentAge"/></td> </tr> <tr> <td width="18%">性别:</td> <td width="25%"><xsl:value-of select="StudentSex"/></td> <td width="22%">EMAIL:</td> <td width="37%"><xsl:value-of select="StudentEMail"/></td> </tr> </table> <table border="1" width="38%" height="65"> <tr> <td width="100%" height="16">该学生所学课程如下:</td> </tr> <xsl:for-each select="Lesson"> </table> |
-- 作者:alpacino -- 发布时间:12/5/2004 2:48:00 PM -- 加我是QQ:357071581,注明xml,我有你正确的答案,错误在你的循环嵌套里节点无效。 |
-- 作者:alpacino -- 发布时间:12/5/2004 2:49:00 PM -- 正确答案: <?xml version="1.0" encoding="GB2312"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="dsStudent"> <html> <head> <title>New Page 1</title> </head> <body> <xsl:for-each select="StudentInfo"> <table border="1" width="40%"> <tr> <td width="18%">姓名:</td> <td width="25%"> <xsl:value-of select="StudentName"/> </td> <td width="22%">年龄:</td> <td width="37%"> <xsl:value-of select="StudentAge"/> </td> </tr> <tr> <td width="18%">性别:</td> <td width="25%"> <xsl:value-of select="StudentSex"/> </td> <td width="22%">EMAIL:</td> <td width="37%"> <xsl:value-of select="StudentEMail"/> </td> </tr> </table> </xsl:for-each> <table border="1" width="40%" height="65"> <tr> <td width="100%" height="16">该学生所学课程如下:</td> </tr> <xsl:for-each select="Lesson"> <tr> <td width="100%" height="15"> <xsl:value-of select="Name"/> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
46.875ms |