- // Fichier XML : "FichierXML.xml"
- <AddressBook>
- <Pepole nom="NOM1" prenom="Prénom1" email="email1@email1.com"/>
- <Pepole nom="NOM2" prenom="Prénom2" email="email2@email2.com"/>
- <Pepole nom="NOM2" prenom="Prénom2" email="email1@email2.com"/>
- </AddressBook>
-
- // Fichier XSLT : "FichierXSLT.xslt"
-
- <?xml version="1.0" encoding="UTF-8" ?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:template match="AddressBook">
- <html>
- <body>
- <table>
- <tr>
- <td>NOM</td>
- <td>Prénom</td>
- <td>e-Mail</td>
- </tr>
- <xsl:apply-templates/>
- </table>
- </body>
- </html>
- </xsl:template>
- <xsl:template match="Pepole">
- <tr>
- <td><xsl:value-of select="@nom" /></td>
- <td><xsl:value-of select="@prenom" /></td>
- <td><a href="mailto:<xsl:value-of select="@email" />"><xsl:value-of select="@email" /></a></td>
- </tr>
- </xsl:template>
- </xsl:stylesheet>
-
- // Code Source :
-
- ///ajouter
- using System.Xml;
- using System.Xml.Xsl;
- using System.Xml.XPath;
-
- ///Fonction :
- public static bool Transform(string XMLFile, string XSLTFile, string OUTPUTFile)
- {
- try
- {
- XmlDocument XDoc = new XmlDocument();
- XDoc.Load(XMLFile);
- XslTransform XTrans = new XslTransform();
- XTrans.Load(XSLTFile);
-
- XmlTextWriter WR = new XmlTextWriter(OUTPUTFile,System.Text.Encoding.ASCII);
- XTrans.Transform(XDoc,null,WR);
- WR.Close();
- return true;
- }
- catch (Exception Ex){ Console.WriteLine(Ex.ToString()); return false;}
- }
// Fichier XML : "FichierXML.xml"
<AddressBook>
<Pepole nom="NOM1" prenom="Prénom1" email="email1@email1.com"/>
<Pepole nom="NOM2" prenom="Prénom2" email="email2@email2.com"/>
<Pepole nom="NOM2" prenom="Prénom2" email="email1@email2.com"/>
</AddressBook>
// Fichier XSLT : "FichierXSLT.xslt"
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="AddressBook">
<html>
<body>
<table>
<tr>
<td>NOM</td>
<td>Prénom</td>
<td>e-Mail</td>
</tr>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="Pepole">
<tr>
<td><xsl:value-of select="@nom" /></td>
<td><xsl:value-of select="@prenom" /></td>
<td><a href="mailto:<xsl:value-of select="@email" />"><xsl:value-of select="@email" /></a></td>
</tr>
</xsl:template>
</xsl:stylesheet>
// Code Source :
///ajouter
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
///Fonction :
public static bool Transform(string XMLFile, string XSLTFile, string OUTPUTFile)
{
try
{
XmlDocument XDoc = new XmlDocument();
XDoc.Load(XMLFile);
XslTransform XTrans = new XslTransform();
XTrans.Load(XSLTFile);
XmlTextWriter WR = new XmlTextWriter(OUTPUTFile,System.Text.Encoding.ASCII);
XTrans.Transform(XDoc,null,WR);
WR.Close();
return true;
}
catch (Exception Ex){ Console.WriteLine(Ex.ToString()); return false;}
}