public override void TreeToTreeTransform() { if (sourceDocument != null) { XdmNavigator contextItem = sourceDocument.CreateNavigator(); var documentSet = new DocumentSet(nameTable, stylesheet.InputSettings, schemaAware ? documentResolverSchemaAware : documentResolver, null, resourceResolver); DynamicContextSettings settings = new DynamicContextSettings(); settings.ContextItem = contextItem; settings.DocumentSet = documentSet; //DynamicContextSettings settings = new DynamicContextSettings { ContextItem = contextItem }; using (XdmDocumentWriter writer = XdmDocumentWriter.Create()) { stylesheet.ApplyTemplates(settings, writer); resultDocument = writer.Document; } } else { var documentSet = new DocumentSet(nameTable, stylesheet.InputSettings, documentResolver, null, resourceResolver); DynamicContextSettings settings = new DynamicContextSettings { DocumentSet = documentSet }; XmlQualifiedName qname = new XmlQualifiedName("main"); using (XdmDocumentWriter writer = XdmDocumentWriter.Create()) { stylesheet.CallTemplate(qname, settings, writer); resultDocument = writer.Document; } } }