使用xml和可重用的xslt动态生成HTML表单
发布时间:2020-12-16 23:02:39 所属栏目:百科 来源:网络整理
导读:我有大量的xml文件: 第一: xmldata1 record property11abc/property11 property12def/property12 property13xyz/property13 ............ /record ......../xmldata1 第二: xmldata2 record property21abc/property21 property22def/property22 property2
我有大量的xml文件:
第一: <xmldata1> <record> <property11>abc</property11> <property12>def</property12> <property13>xyz</property13> ............ </record> ........ </xmldata1> 第二: <xmldata2> <record> <property21>abc</property21> <property22>def</property22> <property23>xyz</property23> ............ </record> ........ </xmldata2> 等等. 将不再有嵌套标签. 所以我想使用XSLT动态生成一个HTML表单,用于读取每个xml的数据.应使用简单的文本框来读取每个属性.我们可以将第一条记录作为属性数量和名称的参考. 所需的输出 <form name ="xmldata1"> <table> <tr> <td>property11 :</td> <td><input type="text" name="property11"></td> </tr> ....... and so on </table> </form> 我怎样才能做到这一点.我在哪里可以找到这样的示例. 解决方法<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="yes" /> <!--Template match for the document element,no matter what the name --> <xsl:template match="/*"> <form name="{local-name()}"> <table> <!--Apply-templates for all of the record/property elements --> <xsl:apply-templates select="*/*"/> </table> </form> </xsl:template> <!--Match on all of the property elements and create a new row for each --> <xsl:template match="/*/*/*"> <tr> <td><xsl:value-of select="local-name()"/> :</td> <td><input type="text" name="{local-name()}"/></td> </tr> </xsl:template> </xsl:stylesheet> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |