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">
  <xsl:for-each select="stream(doc('input.xml')//record)">
    ... process one record ...
and then start the transformation with -it:main and no source document.
Michael Kay

From: James King []
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="" version="1.0" xmlns:saxon="">

                <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>





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 []
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


From: James King []
Sent: 15 October 2008 18:34
Subject: [saxon] XSLT Compile error using saxon:stream()



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."



       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()





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

<xsl:stylesheet xmlns:xsl="" version="1.0" xmlns:saxon="">

                <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>






.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();







Any advice on this would be greatly appreciated.