How do I get the value contained in <xsl:output method=" using Saxon.net api?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I get the value contained in <xsl:output method=" using Saxon.net api?

Wintermann, John (RTIS)

Hi,

 

I've been working with xslt for a while, but I'm new to C# and Java, and I have a question about generating an output file that has a file extension that is specified in the xslt's <xsl:output method=”…  if it is not supplied in <xsl:result-document or by the caller of the method that runs the xslt.

 

I've modified the run() method from the XsltSimple2 subclass in ExamplesEE.cs to accept three arguments that should be supplied by the caller of the run method:

public void run(String sourceUri, String xslUri, String outPath)

 

I've created another method to get the output file extension, which can (but I don't want it to have to) be supplied by the client using SetOutputExtensionType(".html").

 

Inside the class I have:

               

//extensionType field set to null initially              

 string extensionType = null;                     

 

Then the run() method:       

   

run(String sourceUri, String xslUri, String outPath) is executed, before the transformer is run I have the following statements:

               

//inside the run() method

..statements to initialize the processor, compiler, serializer, and transformer

then…

 

                string sourceName = Path.GetFileNameWithoutExtension(sourceUri);

 

                string outfile = null;

 

                switch (GetOutputExtensionType())

                    {

                    case null:

                            {                           

                            //This is where I want to get set the file extension of the output file to whatever has

                            //been set as the output type specified in the method attribute value in the xsl:output element

                            //of my xslt

                            //This is my failing code:

                            //outfile = outPath + "\\" + sourceName + serializer.GetOutputProperties().toString();

                            break;

                            }

 

                    default:

                            {

                            outfile = outPath + "\\" + sourceName + GetOutputExtensionType();

                            break;

                            }

                    }

 

                FileStream fstream = new FileStream(outfile, FileMode.Create, FileAccess.Write);

       serializer.SetOutputStream(fstream);

      

       … finish run() method

 

 

Outside of the run() method:

        public void SetExtensionType(string ext)

            {

            extensionType = ext;

            }

 

        //this method is called in the run() method

        public string GetOutputExtensionType()

            {           

            return extensionType;

            }

.. close out the class

                   

Note that my xslt, does not use <xsl:result-document, and as I'm writing this, I'm realizing that I'll have to modify my code so that:

1. check to see if the extension type has been set by the client

2. check to see that the extension type has not been set in <xsl:result-document (if it has, use that)

3. if neither of those conditions is true, then I want the output file's file extension to be whatever is set by <xsl:output method="... in the xslt.

 

Is serializer.GetOutputProperties() the right way to go about this?

Are there arguments can I supply to the GetOutputProperties() method to get this value?

 

 

Any help will be greatly appreciated.

 


------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: How do I get the value contained in <xsl:output method=" using Saxon.net api?

Michael Kay
If you call

PreparedStylesheet ps = xsltExecutable.getUnderlyingCompiledStylesheet()

then ps.getOutputProperties() gives you the serialization parameters declared on unnamed xsl:output declarations, while  ps.getOutputProperties(name) gives you the properties for a named xsl:output declaration.

If you're using xsl:result-document then the serialization properties can be set dynamically, so it's not possible to discover them statically as a property of the stylesheet itself.

Michael Kay
Saxonica




On 20 Nov 2015, at 22:55, Wintermann, John (RTIS) <[hidden email]> wrote:

Hi,

 

I've been working with xslt for a while, but I'm new to C# and Java, and I have a question about generating an output file that has a file extension that is specified in the xslt's <xsl:output method=”…  if it is not supplied in <xsl:result-document or by the caller of the method that runs the xslt.

 

I've modified the run() method from the XsltSimple2 subclass in ExamplesEE.cs to accept three arguments that should be supplied by the caller of the run method:

public void run(String sourceUri, String xslUri, String outPath)

 

I've created another method to get the output file extension, which can (but I don't want it to have to) be supplied by the client using SetOutputExtensionType(".html").

 

Inside the class I have:

               

//extensionType field set to null initially              

 string extensionType = null;                     

 

Then the run() method:       

   

run(String sourceUri, String xslUri, String outPath) is executed, before the transformer is run I have the following statements:

               

//inside the run() method

..statements to initialize the processor, compiler, serializer, and transformer

then…

 

                string sourceName = Path.GetFileNameWithoutExtension(sourceUri);

 

                string outfile = null;

 

                switch (GetOutputExtensionType())

                    {

                    case null:

                            {                           

                            //This is where I want to get set the file extension of the output file to whatever has

                            //been set as the output type specified in the method attribute value in the xsl:output element

                            //of my xslt

                            //This is my failing code:

                            //outfile = outPath + "\\" + sourceName + serializer.GetOutputProperties().toString();

                            break;

                            }

 

                    default:

                            {

                            outfile = outPath + "\\" + sourceName + GetOutputExtensionType();

                            break;

                            }

                    }

 

                FileStream fstream = new FileStream(outfile, FileMode.Create, FileAccess.Write);

       serializer.SetOutputStream(fstream);

      

       … finish run() method

 

 

Outside of the run() method:

        public void SetExtensionType(string ext)

            {

            extensionType = ext;

            }

 

        //this method is called in the run() method

        public string GetOutputExtensionType()

            {           

            return extensionType;

            }

.. close out the class

                   

Note that my xslt, does not use <xsl:result-document, and as I'm writing this, I'm realizing that I'll have to modify my code so that:

1. check to see if the extension type has been set by the client

2. check to see that the extension type has not been set in <xsl:result-document (if it has, use that)

3. if neither of those conditions is true, then I want the output file's file extension to be whatever is set by <xsl:output method="... in the xslt.

 

Is serializer.GetOutputProperties() the right way to go about this?

Are there arguments can I supply to the GetOutputProperties() method to get this value?

 

 

Any help will be greatly appreciated.

 

------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help