transformation xslt en c# (resultat dans un string)

transformation xslt en c# (resultat dans un string) - C#/.NET managed - Programmation

Marsh Posté le 28-03-2006 à 16:56:58    

Bonjour je voudrais faire une transformation xslt en c#. J'arrive à effectuer cette transformation lorsque
le resultat est un fichier, mais lorsque je souhaite que le resultat soit de type string ca ne marche pas. Quelqu'un aurait il une idée?
voici le code

 

   string sauv = string.Empty;
    try
            {
                //Create a new XslTransform object.
                XslTransform xslt = new XslTransform();

 

               //Load the stylesheet.
                xslt.Load(Server.MapPath("../Index/index.xsl" ));
           

 


                //Create a new XPathDocument and load the XML data to be transformed.
                XmlDocument xp = new XmlDocument();
                xp.Load(Server.MapPath("../Index/index.xml" ));

 

               //Create an XmlTextWriter which outputs to the console.
                XmlTextWriter writer = new XmlTextWriter(html, null);
               
               
                //Transform the data and send the output to the console.
                xslt.Transform(xp, null, writer, null);
                writer.Close();//la transformation xslt fonctionne
               
                XmlReader filexml = xslt.Transform(xp, new XsltArgumentList(), new XmlUrlResolver());
               
                int i=0;
                while (!filexml.EOF)    
                {
                    sauv +=  ++i + " " + filexml.ReadOuterXml();
                    filexml.Read();
                }//sauv est vide
            }
            catch(Exception e1)
            {
                toto.InnerHtml =  e1.ToString();
            }

Reply

Marsh Posté le 28-03-2006 à 16:56:58   

Reply

Marsh Posté le 28-03-2006 à 17:00:27    

source xml :
<?xml version="1.0" encoding="utf-8"?>
<FichierXmlCollection xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fichiers>
<fichier>
<Nom>06X001.xml</Nom>
<Etat>redacteur</Etat>
<NomCreateur>CG67cyrille.hurstel</NomCreateur>
<DateCreation>2006/03/02</DateCreation>
</fichier>
<fichier>
<Nom>Copie (2) de 06X001.xml</Nom>
<Etat>redacteur</Etat>
<NomCreateur>CG67cyrille.hurstel</NomCreateur>
<DateCreation>2006/03/02</DateCreation>
</fichier>
<fichier>
<Nom>Copie (2) de PCR00501.xml</Nom>
<Etat>redacteur</Etat>
<NomCreateur>CG67yannick.lang</NomCreateur>
<DateCreation>2006/03/01</DateCreation>
</fichier>
<fichier>
<Nom>PCR00501.xml</Nom>
<Etat>redacteur</Etat>
<NomCreateur>yannick.lang</NomCreateur>
<DateCreation>2006/04/01</DateCreation>
</fichier>
<fichier>
<Nom>PCR00501.xml</Nom>
<Etat>redacteur</Etat>
<NomCreateur>CG67yannick.lang</NomCreateur>
<DateCreation>2006/03/01</DateCreation>
</fichier>
 
</fichiers>
</FichierXmlCollection>
 
source xsl :
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" version="4.0" encoding="ISO-8859-1"/>
<xsl:template match="fichiers">
<xsl:apply-templates select="fichier">
<xsl:sort select="DateCreation"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="fichier">
&lt;div&gt;
&lt;span class="text"&gt;<xsl:value-of select="Nom"/>&lt;/span&gt;
&lt;span class="text"&gt;<xsl:value-of select="Etat"/>&lt;/span&gt;
&lt;span class="text"&gt;<xsl:value-of select="NomCreateur"/>&lt;/span&gt;
&lt;span class="text"&gt;<xsl:value-of select="DateCreation"/>&lt;/span&gt;
&lt;/div&gt;
</xsl:template>
</xsl:stylesheet>

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed