Modifica.xml
codice:
<?xml-stylesheet type="text/xsl" href="Form.xsl"?>
<form nome="frmModifica" azione="ModificaElimina.jsp" metodoInvio="GET" tornaGestione="si">
<riga>
<titolo>Modifica utente</titolo>
</riga>
Form.xsl
codice:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="form">
<html>
<head>
<title>Form.xsl</title>
<link href="stile1.css" rel="stylesheet" type="text/css"/>
</head>
<form>
<xsl:attribute name="name">
<xsl:value-of select="@nome"/>
</xsl:attribute>
<xsl:attribute name="action">
<xsl:value-of select="@azione"/>
</xsl:attribute>
<xsl:attribute name="method">
<xsl:value-of select="@metodoInvio"/>
</xsl:attribute>
<h1 align="center"><xsl:value-of select="riga/titolo"/></h1>
<xsl:for-each select="riga">
<p align="center">
<xsl:value-of select="etichetta"/>
<xsl:for-each select="elemento">
<input>
<xsl:attribute name="type">
<xsl:value-of select="@tipo"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="@nome"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="@valore"/>
</xsl:attribute>
<xsl:value-of select="@val"/>
</input>
</xsl:for-each>
<xsl:for-each select="elemento1">
<select>
<xsl:attribute name="name">
<xsl:value-of select="@nome"/>
</xsl:attribute>
<xsl:for-each select="opzione">
<option>
<xsl:attribute name="value">
<xsl:value-of select="@valore"/>
</xsl:attribute>
<xsl:value-of select="."/>
</option>
</xsl:for-each>
</select>
</xsl:for-each>
<xsl:for-each select="collegamento">
<a>
<xsl:attribute name="href">
<xsl:value-of select="@ind"/>
</xsl:attribute>
<xsl:value-of select="@valore"/>
</a>
</xsl:for-each>
</p>
</xsl:for-each>
<xsl:if test="@tornaGestione='si'">
<p align="center"><input type="button" value="Torna a gestione" onclick="location.href ='GestioneUtenti.xml'"/></p>
</xsl:if>
</form>
</html>
</xsl:template>
</xsl:stylesheet>
elencoUtentiModificaElimina.xsl(dove mi viene segnalato l'errore)[editato]
codice:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="dati">
<form name="modificaElimina" action="ModificaElimina.jsp" method="GET">
<head>
<title>UtentiModificaElimina.xsl</title>
<link href="stile1.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<h1 align="center"><xsl:value-of select="titolo"/></h1>
<table border="1" align="center">
<thead>
<xsl:for-each select="intestazioni/intestazione">
<th>
<xsl:value-of select="."/>
</th>
</xsl:for-each>
<th>
Selezione
</th>
</thead>
<xsl:for-each select="utenti/utente">
<tr>
<td><xsl:value-of select="username"/></td>
<td><xsl:value-of select="nome"/></td>
<td><xsl:value-of select="cognome"/></td>
<td><xsl:value-of select="email"/></td>
<td><xsl:value-of select="tel"/></td>
<td><xsl:value-of select="sesso"/></td>
<td><xsl:value-of select="tipo"/></td>
<td>
<input type="checkBox" name="selezione">
<xsl:attribute name="value">
<xsl:value-of select="username"/>
</xsl:attribute>
</input>
</td>
</tr>
</xsl:for-each>
</table>
<p align="center">
Operazione da effettuare
<select name="operazione">
<option value="modifica">
Modifica
</option>
<option value="elimina">
Elimina
</option>
</select>
  <input type="submit" nome="btnInvia" value="Invia"/>
  <p align="center"><input type="button" value="Torna a gestione" onclick="location.href ='GestioneUtenti.xml'"/></p>
</p>
</body>
</form>
</xsl:template>
</xsl:stylesheet>
ModificaElimina.jsp
codice:
<%@page contentType="text/xml" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<?xml-stylesheet type="text/xsl" href="elencoUtentiModificaElimina.xsl"?>
<%-- 1) connessione al DB --%>
<c:if test="${connDB==null}">
<sql:setDataSource var="connDB"
scope="session"
driver="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/eLearning"
user="postgres"
password="123456"/>
</c:if>
<%-- 2) eseguire la query --%>
<c:if test="${param.operazione=='elimina'}">
<c:forEach items="${paramValues.selezione}" var="prova">
<sql:update dataSource="${connDB}" var="rs1">
delete from utente where username=?
<sql:param value="${prova}"/>
</sql:update>
</c:forEach>
</c:if>
<c:if test="${param.operazione=='modifica'}">
response.sendRedirect("Modifica.xml");
<%--<sql:query dataSource="${connDB}" var="rs">
select * from utente where tipo='u'
</sql:query>--%>
</c:if>
<sql:query dataSource="${connDB}" var="rs">
select * from utente
</sql:query>
<%-- 3) "costruzione" xml delle informazioni risultato della query --%>
<form nome="modificaElimina" azione="ModificaElimina.jsp" metodo="GET">
<dati>
<titolo>Elenco degli utenti</titolo>
<intestazioni>
<intestazione>Username</intestazione>
<intestazione>Nome</intestazione>
<intestazione>Cognome</intestazione>
<intestazione>Email</intestazione>
<intestazione>Telefono</intestazione>
<intestazione>Sesso</intestazione>
<intestazione>Tipo</intestazione>
</intestazioni>
<utenti>
<c:forEach items="${rs.rows}" var="riga">
<utente>
<username><c:out value="${riga.username}"/></username>
<nome><c:out value="${riga.nome}"/></nome>
<cognome><c:out value="${riga.cognome}"/></cognome>
<email><c:out value="${riga.email}"/></email>
<tel><c:out value="${riga.tel}"/></tel>
<sesso><c:out value="${riga.sesso}"/></sesso>
<tipo><c:out value="${riga.tipo}"/></tipo>
</utente>
</c:forEach>
</utenti>
<riga>
<elemento tipo="hidden" nome="provenienza" valore="${param.operazione}"/>
</riga>
</dati>
</form>