<link href="/assets/64d0ba83aa42c90354ff97799bcfc0c2.css" type="text/css" rel="stylesheet"> <script src="/assets/6fd6663d5303bb7eda3ef7493fc29db6.js"></script> <script> $(document).ready(function() { anchors.options = { visible: 'hover', placement: 'right', truncate: 64 }; anchors.add('#body h2, #body h3, #body h4, #body h5'); }); </script> <script> hljs.initHighlightingOnLoad(); </script>

<h3>Exemple de transformation XSLT</h3> <p><strong>le fichier XML</strong></p> <pre><code class="language-xml">&lt;?xml version="1.0" encoding="utf-8"&gt; &lt;cours&gt; &lt;explication&gt;Une &lt;important&gt;feuille de style &lt;super_important&gt;XSLT&lt;/super_important&gt;&lt;/important&gt; permet de &lt;super_important&gt;transformer&lt;/super_important&gt; un &lt;important&gt;document XML&lt;/important&gt; (donc une structure arborescente) en &lt;important&gt;un autre document&lt;/important&gt; arborescent.&lt;/explication&gt; &lt;explication&gt;Le &lt;important&gt;document de sortie&lt;/important&gt; peut être du &lt;super_important&gt;XML&lt;/super_important&gt;, du &lt;super_important&gt;texte&lt;/super_important&gt; ou du &lt;super_important&gt;HTML&lt;/super_important&gt;.&lt;/explication&gt; &lt;/cours&gt;</code></pre> <p><strong>La feuille de style XSLT</strong></p> <pre><code class="language-xml">&lt;?xml version="1.0" encoding="utf-8"&gt; &lt;xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0"&gt; &lt;xsl:output method = "xml"&gt;&lt;/xsl:output&gt; &lt;xsl:template match = "/cours"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv = "Content-Type" content = "text/html; charset=utf-8"&gt;&lt;/meta&gt; &lt;title&gt;Feuille de style XSLT&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;xsl:apply-templates select = "explication"&gt;&lt;/xsl:apply-templates&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;xsl:template match = "explication"&gt; &lt;div&gt; &lt;xsl:apply-templates select = "*|text()"&gt;&lt;/xsl:apply-templates&gt; &lt;/div&gt; &lt;/xsl:template&gt; &lt;xsl:template match = "important"&gt; &lt;i&gt; &lt;xsl:apply-templates select = "*|text()"&gt;&lt;/xsl:apply-templates&gt; &lt;/i&gt; &lt;/xsl:template&gt; &lt;xsl:template match = "super_important"&gt; &lt;b&gt; &lt;xsl:apply-templates select = "*|text()"&gt;&lt;/xsl:apply-templates&gt; &lt;/b&gt; &lt;/xsl:template&gt; &lt;xsl:template match = "text()"&gt; &lt;xsl:value-of select = "."&gt;&lt;/xsl:value-of&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt;</code></pre> <p><strong>Le résultat</strong></p> <pre><code class="language-xml">&lt;?xml version="1.0" encoding="utf-8"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv = "Content-Type" content = "text/html; charset=utf-8"&gt;&lt;/meta&gt; &lt;title&gt;Feuille de style XSLT&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt;Une &lt;i&gt;feuille de style &lt;b&gt;XSLT&lt;/b&gt;&lt;/i&gt; permet de &lt;b&gt;transformer&lt;/b&gt; un &lt;i&gt;document XML&lt;/i&gt; (donc une structure arborescente) en &lt;i&gt;un autre document&lt;/i&gt; arborescent.&lt;/div&gt; &lt;div&gt;Le &lt;i&gt;document de sortie&lt;/i&gt; peut être du &lt;b&gt;XML&lt;/b&gt;, du &lt;b&gt;texte&lt;/b&gt; ou du &lt;b&gt;HTML&lt;/b&gt;.&lt;/div&gt; &lt;/body&gt; &lt;/html&gt;</code></pre>