Xsl vers html via java

Contenu du snippet

Voila le dernier fichier pour les transformation xml to html via java

ce fichier xsl permet de creer un fichier html via le fichier java que vous trouverez dans mes sources.

J'espere que tous ces fichiers vous aideront pour la transformation vers du html ou pdf par le biais de xsl et xsl:fo et les parser java.

Source / Exemple :


<?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" encoding="UTF-8" />

  <xsl:template match="document">

		<html lang="fr">
			<head>
				<title>
					<xsl:value-of select="//@type"/>
					<xsl:value-of select="//code"/>
				</title>
				<script type="text/javascript" src="../../include/menu_scripts.js"></script>
				
			</head>
			<body >

<!--========================== ========================entete===========================-->
<form name="form_devis1" method="post">
 <xsl:attribute name="action">../document/enreg_doc.jsp?index=entete&amp;type=<xsl:value-of select="//@type"/>
	</xsl:attribute>
		<table width="100%" align="center">
				<tr>
					<td align="center">
						<img src="../../images/solinux/solinux_logo.png"></img>
					</td>
					<td align="center">
					<h3><b>
						<xsl:if test="//@type = 'devis'">
							Devis
						</xsl:if>
						<xsl:if test="//@type = 'facture'">
							Facture
						</xsl:if>
						<xsl:if test="//@type = 'bl'">
							Bon de livraison
						</xsl:if>
					</b></h3><br/>
					Date :<xsl:if test="//@type != 'bl'">
						<xsl:value-of select="date_creation"/><br/>
						<xsl:if test="//@type = 'facture'">
							Echeance :<input type="text" name="date_valid">
  							<xsl:attribute name="value">
    								<xsl:value-of select="date_validite"/>
  							</xsl:attribute>
							</input>

						</xsl:if>
						<xsl:if test="//@type = 'devis'">
					Valable jusqu au : <input type="text" name="date_valid">
  							<xsl:attribute name="value">
    								<xsl:value-of select="date_validite"/>
  							</xsl:attribute>
						</input>
						</xsl:if>
						</xsl:if>
						<xsl:if test="//@type = 'bl'">
						<input type="text" name="date_valid">
  							<xsl:attribute name="value">
    								<xsl:value-of select="date_validite"/>
  							</xsl:attribute>
						</input>
						</xsl:if>
					</td>
				</tr>
			</table>
			<table border="1" width="100%" align="center">
				<tr>
					<td bgcolor="#84b6e0" align="center" width="48%"><font color="white" >Nos references</font></td>
					<td bgcolor="#84b6e0" align="center" width="48%"><font color="white" >Vos coordonnees</font></td>
				</tr>
				<tr>
					<td>  Client : <xsl:value-of select="client"/>

						<br/>
						  Code : <xsl:value-of select="code"/>

					<input type="hidden" name="id" >
  							<xsl:attribute name="value">
    								<xsl:value-of select="//@id"/>
  							</xsl:attribute>
						</input>
					</td>
					<td align="center">
						<table border="0" align="center">
							<tr>
								<td colspan="2">
				 				</td>
							</tr>
							<tr>
								<td align="center" colspan="2">
			 						<input type="hidden"  name="cont_societe" >
										<xsl:attribute name="value">
    											<xsl:value-of select="societe/@id"/>
  										</xsl:attribute>
									</input>
									<b><font size="4"><xsl:value-of select="societe"/></font></b>
								</td>

							</tr>
							<tr>
								<td align="center" colspan="2">
									<select name="cont_pers" >
										<xsl:attribute name="onChange">javascript:document.form_devis1.submit();</xsl:attribute>
										<option value="">Choisir un contact</option>
										<xsl:apply-templates select="liste"/>

                							</select>
								</td>
							</tr>
							<tr>
								<td  colspan="2" align="center"> <input type="hidden"  name="cont_adresse">
  							<xsl:attribute name="value">
								<xsl:value-of select="adresse"/>
  							</xsl:attribute>
     							 </input><xsl:value-of select="adresse"/>
								</td>
							</tr>
							<tr>
								<td align="center"> <input type="hidden" name="cont_cp">
  							<xsl:attribute name="value">
								<xsl:value-of select="cp"/>
  							</xsl:attribute>
						</input>
						<xsl:value-of select="cp"/>
						</td>
								<td align="center"> <input type="hidden" name="cont_ville">
  							<xsl:attribute name="value">
								<xsl:value-of select="ville"/>
  							</xsl:attribute>
						</input>
						<xsl:value-of select="ville"/>
						</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center">
						<xsl:if test="status != 'valide'">
							<input type="submit" value="Valider l entete"/>

						</xsl:if>
					</td>
				</tr>
			</table>
		</form>
<!-- ====================fin de l entete            debut du corps==================================-->
			<table  width="100%" align="center">
	<tr>
		<td width="4%"  align="center">
			<xsl:if test="status != 'valide'">
			<xsl:element name="a" >
				<xsl:attribute name="href">../document/ajout_ligne.jsp?id=<xsl:value-of select="//@id"/>&amp;index=ajout&amp;type=<xsl:value-of select="//@type"/>
				</xsl:attribute>
				<img src="../../images/ajout.gif" width="10" height="10" border="0" />
			</xsl:element>
			</xsl:if>
		</td>

		<td width="96%">
			<table border="1" width="100%" align="center">
				<tr>
				<xsl:if test="//@type != 'bl'">
					<td bgcolor="#84b6e0" align="center" width="15%"><font color="white" >Reference</font></td>
					<td bgcolor="#84b6e0" align="center" width="40%"><font color="white" >Designation</font></td>
					<td bgcolor="#84b6e0" align="center" width="6%"><font color="white" >Q</font></td>
					<td bgcolor="#84b6e0" align="center" width="15%"><font color="white" >PU HT</font></td>
					<td bgcolor="#84b6e0" align="center" width="15%"><font color="white" >Total HT</font></td>
					<td bgcolor="#84b6e0" align="center" width="7%"><font color="white" >TVA</font></td>
				</xsl:if>
				<xsl:if test="//@type = 'bl'">
					<td bgcolor="#84b6e0" align="center" width="25%"><font color="white" >Reference</font></td>
					<td bgcolor="#84b6e0" align="center" width="65%"><font color="white" >Designation</font></td>
					<td bgcolor="#84b6e0" align="center" width="10%"><font color="white" >Quantite</font></td>
				</xsl:if>
				</tr>
			</table>
		</td>
	</tr>

		<xsl:apply-templates select="ligne"/>

	<tr>
		<td> </td>
	</tr>
</table>

<!-- ===========================fin du corps    pied de page===================================-->

<form name="form_devis2" method="post" action="enreg_devis.jsp">
<xsl:if test="//@type != 'bl'">
<table border='1' width="100%" align="center">

	<tr>
		<td bgcolor="#84b6e0" width='25%'><font color="white" >Paiement</font></td>
		<td width='25%'><xsl:if test="@type != 'facture'">
			<input type='text' name="paiement">
						<xsl:attribute name="value">
    								<xsl:value-of select="paiement"/>

  							</xsl:attribute>
						</input>
						</xsl:if>
					<xsl:if test="@type = 'facture'"><xsl:value-of select="paiement"/></xsl:if></td>
		<td bgcolor="#84b6e0" width='25%'><font color="white" >Total HT</font></td>
		<td width='25%'><xsl:value-of select="doc_ht"/></td>
	</tr>
	<tr>
		<td width='25%'></td>
		<td width='25%'></td>
		<td bgcolor="#84b6e0" width='25%'><font color="white" >Total TVA</font></td>
		<td width='25%'><xsl:value-of select="doc_tva"/></td>
	</tr>
	<xsl:if test="//@type = 'facture'">
	<tr>
		<td/>
		<td/>
		<td bgcolor="#84b6e0" width='25%'><font color="white" >Total TTC</font></td>
		<td width='25%'><xsl:value-of select="doc_ttc"/></td>
	</tr>
	</xsl:if>
	<tr>
		<td bgcolor="#84b6e0" width='25%'><font color="white" >Acompte</font></td>
		<td width='25%'>
			<xsl:if test="@type != 'facture'">
			<input type='text' name="accompte">
						<xsl:attribute name="value">
    								<xsl:value-of select="accompte"/>

  							</xsl:attribute>
						</input>
						</xsl:if>
					<xsl:if test="@type = 'facture'"><xsl:value-of select="accompte"/></xsl:if>
		</td>
	<xsl:if test="@type = 'facture'">
		<td bgcolor="#84b6e0" width='25%'><font color="white" >Net a payer</font></td>
		<td width='25%'>
			<xsl:variable name="ttc"><xsl:value-of select="doc_ttc"/></xsl:variable>
			<xsl:variable name="acc"><xsl:value-of select="accompte"/></xsl:variable>
			<xsl:value-of select="$ttc - $acc"/>
		</td>
	</xsl:if>

	<xsl:if test="@type != 'facture'">
		<td bgcolor="#84b6e0" width='25%'><font color="white" >Total TTC</font></td>
		<td width='25%'><xsl:value-of select="doc_ttc"/></td>
	</xsl:if>
	</tr>

</table>
</xsl:if >
<table>
	<tr>
		<td>
		<input type="hidden" name="id">
			<xsl:attribute name="value">
    				<xsl:value-of select="@id"/>
  			</xsl:attribute>
		</input>
		<input type="hidden" name="type">
			<xsl:attribute name="value">
    				<xsl:value-of select="@type"/>
  			</xsl:attribute>
		</input>
		<input type="hidden" name="index">
			<xsl:attribute name="value"></xsl:attribute>
		</input>
		<input type="radio" name="statut" value="courant" >
			<xsl:if test="status = 'courant'">
				<xsl:attribute name="checked">true</xsl:attribute>
			</xsl:if>
		</input>
		En cours de realisation<br/>
		<input type="radio" name="statut" value="attente" >
		<xsl:if test="status = 'attente'">
		<xsl:attribute name="checked">true</xsl:attribute>
		</xsl:if>
		</input>
		En attente<br/>
		<input type="radio" name="statut" value="valide" >
			<xsl:if test="status = 'valide'">
				<xsl:attribute name="checked">true</xsl:attribute>
			</xsl:if>
		</input>
		Valide<br/>
		<input type="radio" name="statut" value="annule" >
			<xsl:if test="status = 'annule'">
				<xsl:attribute name="checked">true</xsl:attribute>
			</xsl:if>
		</input>
		Annule<br/>
		</td>
	</tr>
	<tr>
		<td  align="center">
			<xsl:if test="status != 'valide'">
				<input type="button" value="Enregistrer">
					<xsl:attribute name="onclick">javascript:verif2();</xsl:attribute>
				</input>

			</xsl:if>
		</td>
		<td align="center">
		<xsl:element name="a" >
				<xsl:attribute name="href">../../servlet/ParserXML.Bdd2Pdf?code=<xsl:value-of select="code"/>&amp;id=<xsl:value-of select="@id"/>&amp;type=mail&amp;envoi=null</xsl:attribute>
				<img src="../../images/mail.jpg" width="40" height="40" border="0"/>
			</xsl:element>
			<xsl:element name="a" >
				<xsl:attribute name="href">../../doc/pdf/<xsl:value-of select="substring(code,0,10)"/>.pdf</xsl:attribute>
				<xsl:attribute name="onClick">pdf(<xsl:value-of select="code"/>,<xsl:value-of select="@id"/>)</xsl:attribute>
				<img src="../../images/print.jpg" width="40" height="40" border="0"/>
			</xsl:element>

		</td>
	</tr>
	<tr>

		<td><input type="button" value="Quitter"  onClick="javascript:fermer()"/></td>
	</tr>
</table>
</form>

			</body>
		</html>

	</xsl:template>

<!-- =====================ligne==================================-->
<xsl:template match="ligne">
<tr>
<td width="4%" align="center">
	<xsl:if test="//status != 'valide'">
	<table>

		<tr>

			<td colspan="2">
				<xsl:element name="a" >
				<xsl:attribute name="href">../document/ajout_ligne.jsp?index=ordre_haut&amp;lig_id=<xsl:value-of select="@id"/>&amp;type=<xsl:value-of select="//@type"/>
				</xsl:attribute>
				<img src="../../images/desc.png" width="15" height="15" border="0" />
				</xsl:element>
			</td>
		</tr>
		<tr>

			<td align="center">

				<input type="image"  src="../../images/supp.gif" width="10" height="10" border="0" alt="Supprimer la ligne">
				<xsl:attribute name="onClick">
  					verif(<xsl:value-of select="@id"/>,<xsl:value-of select="//@id"/>,"<xsl:value-of select="//@type"/>")
				</xsl:attribute>
				<xsl:attribute name="align">middle</xsl:attribute>
				<xsl:attribute name="name">image</xsl:attribute>
				</input>

			</td>
			<td  align="center">
			<input type="image" src="../../images/modif.gif" width="10" height="10" border="0" alt="Info sur la ligne"> 					<xsl:attribute name="onClick"></xsl:attribute>
				<xsl:attribute name="align">middle</xsl:attribute>
				<xsl:attribute name="name">image</xsl:attribute>
				</input>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<xsl:element name="a" >
				<xsl:attribute name="href">../document/ajout_ligne.jsp?index=ordre_bas&amp;lig_id=<xsl:value-of select="@id"/>&amp;type=<xsl:value-of select="//@type"/>
				</xsl:attribute>
				<img src="../../images/asc.png" width="15" height="15" border="0" />
				</xsl:element>
			</td>

		</tr>
	</table>
	</xsl:if>
</td>
<td width="96%">
   <form name="form_ligne" method="post">
   	<xsl:attribute name="action">../document/ajout_ligne.jsp?index=update&amp;type=<xsl:value-of select="//@type"/>
	</xsl:attribute>
	<table border="1" width="100%" align="center">
		<tr>
			<td  align="center" width="15%">
				<input type="hidden" name="lig_ordre">
					<xsl:attribute name="value"><xsl:value-of select="@ordre"/></xsl:attribute>
				</input>
				<input type="hidden" name="id">
					<xsl:attribute name="value"><xsl:value-of select="//@id"/></xsl:attribute>
				</input>
				<input type="hidden" name="lig_id">
					<xsl:attribute name="value"><xsl:value-of select="@id"/></xsl:attribute>
				</input>
				<xsl:if test="//@type = 'devis'">
					<input type="text" name="lig_ref"  size="13%">
						<xsl:attribute name="value"><xsl:value-of select="ref"/></xsl:attribute>
					</input>
				</xsl:if>
				<xsl:if test="//@type != 'devis'">
					<xsl:if test="ref != ' '">
				<input type="hidden" name="lig_ref">
						<xsl:attribute name="value"><xsl:value-of select="ref"/></xsl:attribute>
					</input>
					<xsl:value-of select="ref"/>
					</xsl:if>
					<xsl:if test="ref = ' '">
						<input type="text" name="lig_ref">
							<xsl:if test="//@type != 'bl'">
							<xsl:attribute name="size">23% </xsl:attribute>
						</xsl:if>
						<xsl:if test="//@type = 'bl'">
							<xsl:attribute name="size">8% </xsl:attribute>
						</xsl:if>
						</input>
					</xsl:if>
				</xsl:if>
			</td>
			<td  align="center" width="40%">

			<input type="button" value="editer">
				<xsl:attribute name="onClick">javascript:editer(<xsl:value-of select="@id"/>)</xsl:attribute>
			</input><br/>
			<input type="hidden" name="edit">
				<xsl:attribute name="value"><xsl:value-of select="description" disable-output-escaping="no"/>
				</xsl:attribute>
			</input>
			<xsl:value-of select="description" disable-output-escaping="yes"/>

			</td>
			<td  align="center" width="6%">

				<input  type="text" name="lig_quantite" size="4%">
					<xsl:attribute name="value"><xsl:value-of select="quantite"/></xsl:attribute>
					<xsl:attribute name="onChange">maj_total(<xsl:value-of select="@ordre"/>)</xsl:attribute>
				</input>

			</td>
			<xsl:if test="//@type != 'bl'">
			<td  align="center" width="15%" >
				<xsl:if test="//@type = 'devis'">
				<input  type="text" name="lig_pu" size="13%">
					<xsl:attribute name="value"><xsl:value-of select="pu_ht"/></xsl:attribute>
					<xsl:attribute name="onChange">maj_total(<xsl:value-of select="@ordre"/>)</xsl:attribute>
				</input>
				</xsl:if>
				<xsl:if test="//@type != 'devis'">
					<xsl:if test="pu_ht != ' '">
					<input type="hidden" name="lig_pu">
						<xsl:attribute name="value"><xsl:value-of select="pu_ht"/></xsl:attribute>

					</input>
					<xsl:value-of select="pu_ht"/>
				</xsl:if>
				<xsl:if test="pu_ht = ' '">
					<input type="text" name="lig_pu"/>
				</xsl:if>
			</xsl:if>
			</td>
			<td  align="center" width="15%" >
   			<xsl:if test="//@type = 'devis'">
				<input  type="text" name="lig_prix_total"  size="13%">
					<xsl:attribute name="value"><xsl:value-of select="total_ht"/></xsl:attribute>
					<xsl:attribute name="onClick">maj_total(<xsl:value-of select="@ordre"/>)</xsl:attribute>
				</input>
    			</xsl:if>
				<xsl:if test="//@type != 'devis'">
					<xsl:if test="total_ht != ' '">
					<input type="hidden" name="lig_prix_total">
						<xsl:attribute name="value"><xsl:value-of select="total_ht"/></xsl:attribute>
					</input><xsl:value-of select="total_ht"/>
				</xsl:if>
				<xsl:if test="total_ht = ' '">
					<input type="text" name="lig_prix_total"/>
				</xsl:if>
			</xsl:if>
			</td>
			<td  align="center" width="7%" >
			<xsl:if test="//@type = 'devis'">
				<input  type="text" name="lig_tva" size="5%" >
					<xsl:attribute name="value"><xsl:value-of select="tva"/></xsl:attribute>
				</input>
			</xsl:if>
			<xsl:if test="//@type != 'devis'">
				<xsl:if test="tva != ' '">
				<input type="hidden" name="lig_tva">
					<xsl:attribute name="value"><xsl:value-of select="tva"/></xsl:attribute>
				</input>
				<xsl:value-of select="tva"/>
			</xsl:if>
				<xsl:if test="tva = ' '">
					<input type="text" name="lig_tva"/>
				</xsl:if>
			</xsl:if>
			</td>
   			</xsl:if>
		</tr>
		<tr>
			<td colspan="6" align="center">
    				<xsl:if test="//status != 'valide'">
					<input type="submit" value="Valider la ligne" />

				</xsl:if>
			</td>
		</tr>
	</table>
  </form>
</td>
</tr>
</xsl:template>

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

<xsl:template match="contact">
<option>
	<xsl:attribute name="value"><xsl:value-of select="@id"/></xsl:attribute>
	<xsl:if test="@checked='true'">
		<xsl:attribute name="selected">true</xsl:attribute>
	</xsl:if>
	<xsl:value-of select="."/>
</option>

</xsl:template>

</xsl:stylesheet>

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.