2010-07-21 5 views
4

Je transforme des données XML pour tenir dans le document qui est dans un format « XML tableur Excel 2003 »XML - XSLT Transformation - production balise spéciale « <? ... ?> »

Tout fonctionne bien, mais j'ai un problème avec la génération de l'en-tête approprié du fichier résultat. Il devrait essentiellement être sous une forme de:

<?xml version="1.0"?> 
<?mso-application progid="Excel.Sheet"?> 
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
xmlns:o="urn:schemas-microsoft-com:office:office" 
xmlns:x="urn:schemas-microsoft-com:office:excel" 
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
xmlns:html="http://www.w3.org/TR/REC-html40"> 

<!-- end of header here and the transformation data goes below --> 

<Workbook> 

le fichier XSLT est

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" media-type="text/xml"/> 
    <xsl:template match="/"> 
<?mso-application progid="Excel.Sheet"?> 
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
xmlns:o="urn:schemas-microsoft-com:office:office" 
xmlns:x="urn:schemas-microsoft-com:office:excel" 
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
xmlns:html="http://www.w3.org/TR/REC-html40"> 

mais dans le résultat fichier la ligne <?mso-application progid="Excel.Sheet"?> est manquante.

Je comprends que <? ...?> est une balise spéciale - donc peut remettre en question est comment peut-il être produit par le XSLT

Merci

+0

Quel langage de programmation utilisez-vous? Si c'est php, essayez de désactiver les short_tags de php.ini – Sarfraz

+0

@sAc - merci pour le commentaire, je n'étais pas php, je cherchais approche générale xsl et Alejandro fourni la réponse que je cherchais – kristof

Répondre

12

Avec une entrée, cette feuille de style:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" media-type="text/xml"/> 
    <xsl:template match="/"> 
     <xsl:processing-instruction name="mso-application">progid="Excel.Sheet"</xsl:processing-instruction> 
     <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
        xmlns:o="urn:schemas-microsoft-com:office:office" 
        xmlns:x="urn:schemas-microsoft-com:office:excel" 
        xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
        xmlns:html="http://www.w3.org/TR/REC-html40"/> 
    </xsl:template> 
</xsl:stylesheet> 

Résultat:

<?xml version="1.0" encoding="utf-8"?> 
<?mso-application progid="Excel.Sheet"?> 
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" /> 
+0

merci Alejandro, je n'avais pas idée de ce que xsl: nom de l'étiquette à rechercher – kristof

+0

@kristof: Vous êtes bienvenu! C'est aussi une bonne chose d'étudier les spécifications XSLT sur http://www.w3.org/TR/xslt –

Questions connexes