voilà mon soucis:
dans mon fichier xsl lorsque je précise un xmlns dans la balise:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
le code issu de mon objet via transformToXml contient des choses 'en trop':
<br xmlns=""><hr xmlns="">
et des choses 'en moins':
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
remplacé par:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
je vois pas le rapport/la logique du truc..je tourne en rond là...
toute aide est la bienvenue,
merci.
voilà mes sources:
index.php
<?
#phpinfo();
// Nouvelle instance
$xslt = new XSLTProcessor();
// Chargement du fichier XML
$xml = new domDocument();
$xml -> load('index.xml');
// Chargement du fichier XSL
$xsl = new domDocument();
$xsl -> load('xsl.xsl');
// Import de la feuille XSL
$xslt -> importStylesheet($xsl);
// Transformation et affichage du résultat
echo $xslt -> transformToXml($xml);
?>
index.xml
Code : Tout sélectionner
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xsl.xsl"?>
<!DOCTYPE racine PUBLIC "-//XXXX//DTD XML 1.1 Strict//FR" "http://XXXXXX/XML/dtd.dtd">
<racine>
<article toto="1">
<nom_complet><![CDATA[article n°1]]></nom_complet>
<titre><![CDATA[un beau titre]]></titre>
<prix><![CDATA[10]]></prix>
<image>
<adresse><![CDATA[http://www.]]></adresse>
<resume><![CDATA[résumé de l'image 1]]></resume>
</image>
</article>
<article toto="2">
<nom_complet>article n°2</nom_complet>
<titre>un moins beau titre</titre>
<prix>20</prix>
<image>
<adresse><![CDATA[]]></adresse>
<resume><![CDATA[]]></resume>
</image>
</article>
<article toto="3">
<nom_complet>article n°3</nom_complet>
<titre>un moins moins beau titre</titre>
<prix>30</prix>
<image>
<adresse><![CDATA[]]></adresse>
<resume><![CDATA[]]></resume>
</image>
</article>
</racine>Code : Tout sélectionner
<?xml version="1.0" encoding="UTF-8"?>
<!--ENTETES DE MERDE (réduites au strict minimum)-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output
method="html"
encoding="UTF-8"
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/>
<!--FIN ENTETES
doctype-public="-//W3C//DTD HTML 4.01//EN"
doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
-->
<xsl:variable name="compteur" select="0"/>
<xsl:variable name="couleur" select="'orange'"/>
<xsl:template match="racine">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
</head>
<body>
<p>on commence:</p>
<xsl:for-each select="article">
<xsl:sort select="prix" data-type="number" order="descending"/>
<xsl:apply-templates select="." />
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="article">
<ul STYLE="background-color:{$couleur};">
<li>
<xsl:value-of select="@toto" />
<xsl:text> ::: </xsl:text>
<xsl:value-of select="titre" />
</li>
<xsl:if test="not(nom_complet='')"><li><xsl:value-of select="nom_complet" /></li></xsl:if>
<xsl:if test="not(prix='')"><li><xsl:value-of select="prix" /></li></xsl:if>
<xsl:if test="not(image/adresse='')"><li><xsl:value-of select="image/adresse" /></li></xsl:if>
<xsl:if test="not(image/resume='')"><li><xsl:value-of select="image/resume" /></li></xsl:if>
</ul>
<br/>
<hr/>
<xsl:choose>
<xsl:when test="$compteur='0'">
<xsl:variable name="compteur" select="1"/>
<xsl:variable name="couleur" select="'blue'"/>
</xsl:when>
<xsl:when test="$compteur='1'">
<xsl:variable name="compteur" select="0"/>
<xsl:variable name="couleur" select="'white'"/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>Code : Tout sélectionner
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT racine ANY>
<!ELEMENT article (nom_complet, titre, prix, image)>
<!ATTLIST article toto CDATA #IMPLIED>
<!ELEMENT nom_complet (#PCDATA)>
<!ELEMENT titre (#PCDATA)>
<!ELEMENT prix (#PCDATA)>
<!ELEMENT image (adresse, resume)>
<!ELEMENT adresse (#PCDATA)>
<!ELEMENT resume (#PCDATA)>