Project

Profile

Help

Xslt : generate xml with entities with .NET api

Added by Yann Chauvet almost 9 years ago

Hello , i have made a Xsl stylesheet to transform UTF8 xml files to UTF8 xml files with entities. The stylesheet include character-map. I have made tests with XmlSpy configured to use saxon 9.6 ==> It works fine ;-) I have made other tests using saxon inline command "Transform.exe"

When i try to do the same thing inside a C# programme (.NET), i obtain a well transformed Xml file but with encoded caracters instead of entities.

First, i inject character-map inside my stylesheet (no include, no import) ==> Same result.

My coding follow :


public static XmlDocument xslTransform(XmlDocument xmlinput, string xsltranform)
        {
         var destXml = new DomDestination();
         XmlDocument mydoc = new XmlDocument();
            try
            {
                var xslt = new FileInfo(xsltranform);
                TextReader tr = new StringReader(xmlinput.OuterXml);
                // Compile Stylsheet
                var processor = new Processor();
                DocumentBuilder db = processor.NewDocumentBuilder();
                db.BaseUri = new Uri(xsltranform);
                XdmNode input = db.Build(tr);
                XsltTransformer transformer = processor.NewXsltCompiler().Compile(new Uri(xsltranform)).Load();
                transformer.InitialContextNode = input;
                transformer.Run(destXml);
                mydoc = destXml.XmlDocument;
            }
            catch (....)
            {
            ...
            }
        }

I have tried to set or unset many parameters according to configuration instructions but nothing change.

My stylesheet :




	
	


	
	
	
	
    ...
	
	



...

sample of what i would like to have in final xml :


Art. L. 110
Le territoire français est le patrimoine commun de la nation. Chaque collectivité publique en est le gestionnaire et le garant dans le cadre de ses compétences.

sample of what i have today :


Art. L. 110
Le territoire français est le patrimoine commun de la nation. Chaque collectivité publique en est le gestionnaire et le garant dans le cadre de ses compétences.

is there any one to help me ...

Thank's


Replies (5)

Please register to reply

RE: Xslt : generate xml with entities with .NET api - Added by Michael Kay almost 9 years ago

Character maps (and disable output escaping) affect the way a result tree is serialized. If you are not serializing the result tree (which is the case here, because you are sending the transformation result to a DOM), then these directives have no effect.

RE: Xslt : generate xml with entities with .NET api - Added by Yann Chauvet almost 9 years ago

Michael Kay wrote:

Character maps (and disable output escaping) affect the way a result tree is serialized. If you are not serializing the result tree (which is the case here, because you are sending the transformation result to a DOM), then these directives have no effect.

Hello . So i have changed my code:


           string sourceUri = xmlinput;
            string xsltUri = xsltranform;

            try
            {
          
                        // Create a Processor instance.
                        Processor processor = new Processor();

                        // Load the source document
                        XdmNode input = processor.NewDocumentBuilder().Build(new Uri(xmlinput));

                        // Create a transformer for the stylesheet.
                        XsltTransformer transformer = processor.NewXsltCompiler().Compile(new Uri(xsltranform)).Load();

                        // Set the root node of the source document to be the initial context node
                        transformer.InitialContextNode = input;

                        // Create a serializer, with output to the standard output stream
                        Serializer serializer = new Serializer();
                        serializer.SetOutputFile(@"D:\RepriseDataFM\temp\test.xml");

                        // Transform the source XML and serialize the result document
                        transformer.Run(serializer);
                 }

in my test.xml file i have no entitites also ...


Une distance d’au moins trois mètres peut être imposée entre deux bâtiments non contigus situés sur un terrain appartenant au même propriétaire.(Dispositions issues du décret n° 2007-18 du 5 janvier 2007)

is there any parameter i missed ?

RE: Xslt : generate xml with entities with .NET api - Added by Yann Chauvet over 8 years ago

I come back because i have not found a solution to my trouble except launch a "system command" to execute saxon with a xsl containing only a call to character map ... It is not a great solution for me ...

Any one to help me ?

RE: Xslt : generate xml with entities with .NET api - Added by T Hata over 8 years ago

I tested your stylesheet/input file (with some trivial modification) and the last code (the one with serializer.SetOutputFile()) on a console app with 9.6.0.7N. The character map took effect in the destination file.

RE: Xslt : generate xml with entities with .NET api - Added by Yann Chauvet over 8 years ago

Hello T Hata.

Thank's You . I works fine with 9.6.0.7N.!

    (1-5/5)

    Please register to reply