Voici donc la première template entièrement fonctionnelle :
Son but est simple, envoyés en sortie les nœuds entrés (nb : noeud=ensemble de balises et d'attributs). Par exemple pour interpréter le html d'un fichier xml.
En fait l'intérêt en lui-même est limité car un xsl:copy-of fait la même chose. par contre xparse-tag s'avère utile pour la création de nouvelles balises à interpréter (pas implémentées dans mon exemple de base ^^).
xparse-tag.xsl
<?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"
standalone="yes"
indent="yes"
encoding="UTF-8"/>
<xsl:template name="xparse-tag">
<xsl:param name="root"/>
<xsl:choose>
<xsl:when test="name($root)">
<xsl:for-each select="$root">
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:for-each select="node()">
<xsl:call-template name="xparse-tag">
<xsl:with-param name="root" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="xparse-tag">
<xsl:call-template name="xparse-tag">
<xsl:with-param name="root" select="./*"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="/">
<html>
<head>
<title>xparse-tag</title>
</head>
<body>
<p>Utilisation de xparse-tag :</p>
<xsl:for-each select="page/xparse-tag">
apply-templates : <xsl:apply-templates select="."/>
</xsl:for-each>
<hr />
<p>Utilisation de xsl:copy-of :</p>
<xsl:for-each select="page/xparse-tag">
copy-of : <xsl:copy-of select="./*"/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
xparse-tag.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xparse-tag.xsl"?>
<page>
<xparse-tag>
<p>Je suis un <strong>paragraphe </strong> ! <em style="color:red;">:)</em></p>
<h1 style="background-color:yellow;">Je suis un h1 !</h1>
</xparse-tag>
<xparse-tag><![CDATA[
<p>Je suis un <strong>CDATA </strong> ! <em style="color:red;">:)</em></p>
<h1 style="background-color:yellow;">Je suis un h1 !</h1>
]]></xparse-tag>
</page>
Et voilà, plus qu'à ouvrir xparse-tag.xml et rester ébahi devant tant de génie :D.