Thanks for your response, I am able to call the named template from the XsltTransformer by setting its InitialTemplate property as follows:

 

transformer.InitialTemplate = new QName("", "", "main");

 

However within the template, I seem to be having a problem using the saxon:stream function:

 

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:saxon="http://saxon.sf.net/">

                <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

 

                <xsl:template name="main">

                                                <xsl:text>Starting main template</xsl:text>

 

                                                                <!--THIS WORKS-->

                                                                <xsl:value-of select="doc('C:\Projects\SaxonXSLT\bin\Debug\input2.xml')"/>

 

                                                                <!--THIS DOESN’T WORK-->

                                                                <!--<xsl:value-of select="saxon:stream(doc('C:\Projects\SaxonXSLT\bin\Debug\input2.xml'))"/>-->

 

                                                <xsl:text>main template finished</xsl:text>

                </xsl:template>

 

</xsl:stylesheet>

 

The first xsl:value-of above works fine, the second one causes no output. I have also tried with various other path expressions:

 

doc('C:\Projects\SaxonXSLT\bin\Debug\input2.xml')/data/row[1]

doc('C:\Projects\SaxonXSLT\bin\Debug\input2.xml')/data

 

 

This is the code I’m using from to call the .Net Client:

 

        public void Transform(string sourcePath, string xsltPath)

        {

            Errors.Clear();

 

            // Create a Processor instance.

            Processor processor = new Processor(true);

 

            // Create a compiler

            XsltCompiler compiler = processor.NewXsltCompiler();

 

            compiler.ErrorList = new ArrayList();

 

            XsltTransformer transformer = null;

 

            try

            {

                XsltExecutable compiledXslt = compiler.Compile(new FileStream(xsltPath, FileMode.Open));

                transformer = compiledXslt.Load();

            }

            catch

            {

                foreach (object i in compiler.ErrorList)

                    Errors.Add(i.ToString());

 

                throw;

            }

 

            transformer.InitialTemplate = new QName("", "", "main");

 

            XmlResolver resolver = new XmlUrlResolver();

 

            transformer.InputXmlResolver = resolver;

 

            // Create a serializer.

            Serializer serializer = new Serializer();

 

            serializer.SetOutputFile("result.xml");

 

            // Transform the source XML to System.out.

            transformer.Run(serializer);       

        }

 

This is input2.xml:

 

<?xml version="1.0" encoding="UTF-8"?>

<data>

                <row>1</row>

                <row>2</row>

                <row>3</row>

</data>

 

From: Michael Kay [mailto:mike@saxonica.com]
Sent: 16 October 2008 10:29
To: James King; 'Mailing list for the SAXON XSLT and XQuery processor'
Subject: RE: [saxon] XSLT Compile error using saxon:stream()

 

Yes, sorry, I didn't spot the deeper error.

 

You can't use saxon:stream() in a match pattern, as the message says. In fact, you can't use the doc() function in a match pattern either.

 

In most cases, if you want to do a streaming transformation, then you probably don't want a primary input document; the streamed document should be a secondary input. So you will usually want something like

 

<xsl:template name="main">

<output>

  <xsl:for-each select="stream(doc('input.xml')//record)">

    ... process one record ...

  </xsl:for-each>

</output>

</xsl:template>

 

and then start the transformation with -it:main and no source document.

 

Michael Kay

http://www.saxonica.com/

 


From: James King [mailto:james.king@m35.net]
Sent: 16 October 2008 10:19
To: Michael Kay; Mailing list for the SAXON XSLT and XQuery processor
Subject: RE: [saxon] XSLT Compile error using saxon:stream()

Hi Mike,

 

Thanks for your assistance. Using the Errors property of the XsltCompiler I can see the following error message:

 

“XSLT Pattern syntax error at char 0 on line 5 in {saxon:stream(doc}: The only functions allowed in a pattern are id() and key()”

 

I’m using the following XSLT:

 

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:saxon="http://saxon.sf.net/">

                <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

 

                <xsl:template match="saxon:stream(doc('input.xml')/)">

                                <xsl:text>Hello from streamed query</xsl:text>

                </xsl:template>

 

</xsl:stylesheet>

 

The compiler seems to be having a problem with the call to the saxon function in the path expression…

 

Apologies about the missing closing bracket in the code I supplied previously.

 

From: Michael Kay [mailto:mike@saxonica.com]
Sent: 15 October 2008 21:29
To: 'Mailing list for the SAXON XSLT and XQuery processor'
Cc: James King
Subject: RE: [saxon] XSLT Compile error using saxon:stream()

 

Your first problem is that you're not seeing the real error messages, only the exception text that says the compilation failed. That's presumably because you're running the compilation within some kind of GUI application, and you haven't redirected the errors to display in one of your windows. You need to fix that.

 

From what you've shown the error looks trivial:

 

<xsl:template match="saxon:stream(doc('input.xml')/">

 

There's a missing closing bracket there.

 

Michael Kay

http://www.saxonica.com/

 


From: James King [mailto:james.king@m35.net]
Sent: 15 October 2008 18:34
To: saxon-help@lists.sourceforge.net
Subject: [saxon] XSLT Compile error using saxon:stream()

Hi,

 

I am currently working with the new XSLT streaming feature in Saxon 9 using the .Net client.

 

I can get a regular transform working fine, but as soon as I add the saxon:stream() call to any XPath in my XSLT I get the following exception when calling the Compile() method on the XSLTCompiler. (I’ve attached my XSLT and .Net code below)

 

“javax.xml.transform.TransformerConfigurationException was unhandled

  Message="Failed to compile stylesheet. 1 error detected."

  Source="saxon9"

  StackTrace:

       at net.sf.saxon.PreparedStylesheet.prepare(Source styleSource)

       at net.sf.saxon.TransformerFactoryImpl.newTemplates(Source source, CompilerInfo info)

       at Saxon.Api.XsltCompiler.Compile(Stream input)

       at SaxonXSLTClient.Transformer.Transform(String sourcePath, String xsltPath) in C:\Projects\InnovationChallenge\SaxonXSLTClient\Transformer.cs:line 26

       at SaxonXSLT.Main.btnTransform_Click(Object sender, EventArgs e) in C:\Projects\InnovationChallenge\SaxonXSLT\Main.cs:line 23

       at System.Windows.Forms.Control.OnClick(EventArgs e)

       at System.Windows.Forms.Button.OnClick(EventArgs e)

       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

       at System.Windows.Forms.Control.WndProc(Message& m)

       at System.Windows.Forms.ButtonBase.WndProc(Message& m)

       at System.Windows.Forms.Button.WndProc(Message& m)

       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)

       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

       at System.Windows.Forms.Application.Run(Form mainForm)

       at SaxonXSLT.Program.Main() in C:\Projects\InnovationChallenge\SaxonXSLT\Program.cs:line 18

       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ThreadHelper.ThreadStart()

  InnerException:”

 

XSLT

 

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:saxon="http://saxon.sf.net/">

                <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

 

                <xsl:template match="saxon:stream(doc('input.xml')/">

                                <xsl:text>Hello from streamed query</xsl:text>

                </xsl:template>

 

</xsl:stylesheet>

 

 

.Net Client Code

 

        public void Transform(string sourcePath, string xsltPath)

        {

            Processor processor = new Processor(true);

 

            DocumentBuilder docBuilder = processor.NewDocumentBuilder();

 

            docBuilder.BaseUri = new Uri("http://test");

 

            XdmNode input = docBuilder.Build((new FileStream(sourcePath, FileMode.Open)));

 

            XsltTransformer transformer = processor.NewXsltCompiler().Compile(new FileStream(xsltPath, FileMode.Open)).Load();

 

            transformer.InitialContextNode = input;

 

            transformer.BaseOutputUri = new Uri("http://test");

 

            Serializer serializer = new Serializer();

 

            serializer.SetOutputFile("result.xml");

 

            transformer.Run(serializer);       

        }

 

Any advice on this would be greatly appreciated.