Salve ragazzi, sono un neofita di XML e vorrei chiedervi di poter aiutarmi a risolvere una domanda che mi è stata fatta. Dovrei in pratica descrivere l’xml risultante alla applicazione all’ XML (1) dell’ XSL(2), o anche descrivere l'output risultante.
Vi posto il codice XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Utente nome="Enrico" cognome="Conti" username="enrico.conti" password="mypassword" role="ADMINISTRATOR"/>
<Ruolo name="ADMINISTRATOR" descrizione="Amministratore"/>
<Ruolo name="NORMALUSER" descrizione="Utente normale"/>
<Node element1="PROVA">
<Contatto nome="Signor franco" cognome="Franchi" id_contatto="1" principale="true"/>
<Contatto nome="Toro" cognome="Seduto" id_contatto="2"/>
</Node>
<Utente nome="Topo" cognome="Gigio" role="NORMALUSER"/>
</root>
Questo è invece l' XSL rappresentante la trasformazione
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" />
<xsl:template name="ShowContatto">
<xsl:param name="position" select="1"/>
<tr>
<xsl:if test="@principale='true' ">
<xsl:attribute name="class">redCss</xsl:attribute>
</xsl:if>
<th>contatto id</th>
<td>
<input type="text" readonly="readonly" name="id_contatto{@id_contatto}" value="{@id_contatto}"/>
</td>
</tr>
<tr>
<xsl:if test="@principale='true' ">
<xsl:attribute name="class">redCss</xsl:attribute>
</xsl:if>
<th>nome</th>
<td>
<input type="text" name="nome{$position}" value="{@nome}"/>
</td>
</tr>
<tr>
<xsl:if test="@principale='true' ">
<xsl:attribute name="class">redCss</xsl:attribute>
</xsl:if>
<th>cognome</th>
<td>
<input type="text" name="cognome{$position}" value="{@cognome}"/>
</td>
</tr>
</xsl:template>
<xsl:template match="/">
<div>
<form action="myform_action" method="post">
<table>
<tbody>
<tr>
<th>username</th>
<td>
<input type="text" name="uid"
value="{/root/Utente[position()=1]/@username}"/>
</td>
<th>password</th>
<td>
<input type="password" name="pwd"
value="{/root/Utente[position()=1]/@password}"/>
</td>
</tr>
<tr>
<th>ruolo</th>
<td>
<select name="role">
<xsl:for-each select="/root/Ruolo">
<xsl:variable name="name" select="@name"/>
<option value="{@name}">
<xsl:if test="count(/root/Utente[position()=1 and
@role=$name]) > 0">
<xsl:attribute
name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="@descrizione"/>
</option>
</xsl:for-each>
</select>
</td>
<th>numero contatti</th>
<td>
<xsl:value-of select="count(/root/Node/Contatto[@principale='true'])"/>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<xsl:for-each select="/root/Node/Contatto">
<xsl:call-template name="ShowContatto">
<xsl:with-param name="position">
<xsl:value-of select="position()"/>
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</tbody>
</table>
<table>
<tbody>
<tr>
<xsl:for-each select="/root/Ruolo">
<th>
<xsl:value-of select="@descrizione"/>
</th>
</xsl:for-each>
</tr>
<tr>
<xsl:for-each select="/root/Ruolo">
<td>
<xsl:variable name="name" select="@name"/>
<xsl:for-each select="/root/Utente[@role=$name]">
<xsl:value-of select="@nome"/><xsl:text disable-outputescaping="
yes"> </xsl:text><xsl:value-of select="@cognome"/>
</xsl:for-each>
</td>
</xsl:for-each>
</tr>
</tbody>
</table>
<input type="submit" value="Salva"/>
</form>
</div>
</xsl:template>
</xsl:stylesheet>
Chi mi aiuta? Grazie