XML - duda de xforms

 
Vista:

duda de xforms

Publicado por rodrigo (2 intervenciones) el 01/03/2005 10:25:39
Hola mi duda es, como puedo conseguir que se vea un formulario xforms en un navegador??mediantes un xsl??y en caso de que así fuese como se haría para que saliese por pantalla este sencillo codigo en el que se pide al usuario que introduzca el primer nombre y el apellido:

<html xmlns:xf="http://www.w3.org/2002/xforms"><head>
<xf:model>
<xf:instance>
<person>
<fname/>
<lname/>
</person>
</xf:instance>
<xf:submission id="prueba1" method="get" action="submit.asp"/>
</xf:model>
</head>

<body>
<xf:input ref="fname">
<xf:label>First Name</xf:label></xf:input>
<br />
<xf:input ref="lname">
<xf:label>Last Name</xf:label></xf:input>
<br />
<br />
<xf:submit submission="prueba1">
<xf:label>Submit</xf:label></xf:submit>
</body>
</html>

MUCHAS GRACIAS
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro

Cómo mostrar un formulario XForms en un navegador y enviar datos a través de XSL

Publicado por Alejandro (258 intervenciones) el 11/07/2023 22:07:21
Para mostrar un formulario XForms en un navegador y enviar los datos introducidos por el usuario, puedes utilizar una combinación de XML, XSLT y HTML. Aquí tienes un ejemplo de cómo hacerlo:

1. Crea un archivo XML con el siguiente contenido y guárdalo con el nombre "formulario.xml":

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:xf="http://www.w3.org/2002/xforms">
<head>
    <xf:model>
        <xf:instance>
            <person>
                <fname/>
                <lname/>
            </person>
        </xf:instance>
        <xf:submission id="prueba1" method="get" action="submit.asp"/>
    </xf:model>
</head>
<body>
    <xf:input ref="fname">
        <xf:label>First Name</xf:label>
    </xf:input>
    <br/>
    <xf:input ref="lname">
        <xf:label>Last Name</xf:label>
    </xf:input>
    <br/>
    <br/>
    <xf:submit submission="prueba1">
        <xf:label>Submit</xf:label>
    </xf:submit>
</body>
</html>

2. Crea un archivo XSLT con el siguiente contenido y guárdalo con el nombre "formulario.xslt":

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xf="http://www.w3.org/2002/xforms">
    <xsl:output method="html" indent="yes"/>
 
    <xsl:template match="/">
        <html>
            <head>
                <title>Formulario XForms</title>
            </head>
            <body>
                <h1>Formulario XForms</h1>
                <xsl:apply-templates select="//xf:input"/>
            </body>
        </html>
    </xsl:template>
 
    <xsl:template match="xf:input">
        <p>
            <label>
                <xsl:value-of select="xf:label"/>
            </label>
            <br/>
            <input type="text" name="{@ref}" value="{//xf:instance//*[name() = current()/@ref]}"/>
        </p>
    </xsl:template>
</xsl:stylesheet>

3. Crea un archivo HTML con el siguiente contenido y guárdalo con el nombre "formulario.html":

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html>
<head>
    <title>Formulario XForms</title>
    <script>
        function loadXMLDoc() {
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    document.getElementById("formulario").innerHTML = this.responseText;
                }
            };
            xhttp.open("GET", "formulario.xml", true);
            xhttp.send();
        }
    </script>
</head>
<body onload="loadXMLDoc()">
    <div id="formulario"></div>
</body>
</html>

4. Coloca los archivos "formulario.xml", "formulario.xslt" y "formulario.html" en el mismo directorio.

5. Abre el archivo "formulario.html" en tu navegador y deberías ver el formulario XForms con los campos "First Name" y "Last Name".

Cuando el usuario complete el formulario y haga clic en "Submit", los datos serán enviados al archivo "submit.asp" usando el método "get". Puedes ajustar la acción del formulario y el método de envío según tus necesidades.

Ten en cuenta que para que esto funcione correctamente, el navegador debe admitir XForms. No todos los navegadores tienen soporte nativo para XForms, por lo que es posible que debas utilizar un motor de renderizado específico o una extensión para habilitar el soporte de XForms en tu navegador.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar