Create form fields from XML tags

I am trying to figure out a way to use a PHP script that would be:

  • Open the XML document when the link to this document is clicked (with HTML).
  • Scan an XML document for tags.
  • Create an HTML form with an input field based on tags.
  • Send the source data back to XML in tags (when the form is submitted) and print the XML to HTML.

So, if I had an XML file that would look like this:

<profile>
Hello, my name is <name></name>.  I am <age></age> years old.  I live in <place></place>
</profile>

When you click on a link to this file, PHP will generate this form:

<form> 
Name:
Age:
Place:
</form>

Then, after filling out and submitting the form (say, the person Joel, 25 years old, from Boston), the following will be superimposed on the screen:

Hi, my name is Joel. I am 25 years old. I live in Boston.

Any code will be appreciated or indicates good tutorials.

THX

E.

+3
source share
2

XSLT .

:

XML:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<profile>
Hello, my name is <name></name>.  I am <age></age> years old.  I live in <place></place>
</profile>

XSL:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>

    <xsl:template match="profile">
        <form>
            <xsl:for-each select="child::*">
                <label>
                    <xsl:value-of select="name()"/>: 
                    <input name="{name()}" type="text" />
                </label>
                <br />
            </xsl:for-each>
        </form>
    </xsl:template>
</xsl:stylesheet>

:

<form>
    <label>name: <input type="text" name="name"></label><br />
    <label>age: <input type="text" name="age"></label><br />
    <label>place: <input type="text" name="place"></label><br />
</form>

xsl php, .

+2

<tag></tag>, , , / , . , XML, XML .

, %Name% $Name$, XML, , XML.

0

Source: https://habr.com/ru/post/1794588/


All Articles