Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用xml和可重用xslt动态生成HTML表单_Html_Xml_Xslt - Fatal编程技术网

使用xml和可重用xslt动态生成HTML表单

使用xml和可重用xslt动态生成HTML表单,html,xml,xslt,Html,Xml,Xslt,我有大量的xml文件: 第一: <xmldata1> <record> <property11>abc</property11> <property12>def</property12> <property13>xyz</property13> ............ </record> ......

我有大量的xml文件:

第一:

<xmldata1>
    <record>
        <property11>abc</property11>
        <property12>def</property12>
        <property13>xyz</property13>
        ............
    </record>
    ........
</xmldata1>
我怎样才能做到这一点。在哪里可以找到此示例。


<?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>
:
你是说这样的事吗

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="html" />

<xsl:template match="/">
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="*[starts-with(name(), 'xmldata')]">
    <xsl:element name="form">
        <xsl:attribute name="name"><xsl:value-of select="name(.)" /></xsl:attribute>
        <table>
            <tr>
                <xsl:apply-templates />
            </tr>
        </table>
    </xsl:element>
</xsl:template>

<xsl:template match="record">
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="*[starts-with(name(), 'property')]">
    <td>
        <xsl:value-of select="name(.)" />
    </td>
    <td>
        <xsl:element name="input">
            <xsl:attribute name="type">text</xsl:attribute>
            <xsl:attribute name="name"><xsl:value-of select="name(.)" /></xsl:attribute>
        </xsl:element>
    </td>
</xsl:template>

文本

最好提供一个示例,说明您的尝试,而不希望社区为您编写此内容,这不是堆栈溢出的目的。
<?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>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="html" />

<xsl:template match="/">
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="*[starts-with(name(), 'xmldata')]">
    <xsl:element name="form">
        <xsl:attribute name="name"><xsl:value-of select="name(.)" /></xsl:attribute>
        <table>
            <tr>
                <xsl:apply-templates />
            </tr>
        </table>
    </xsl:element>
</xsl:template>

<xsl:template match="record">
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="*[starts-with(name(), 'property')]">
    <td>
        <xsl:value-of select="name(.)" />
    </td>
    <td>
        <xsl:element name="input">
            <xsl:attribute name="type">text</xsl:attribute>
            <xsl:attribute name="name"><xsl:value-of select="name(.)" /></xsl:attribute>
        </xsl:element>
    </td>
</xsl:template>