// The output is not guaranteed to be well-formed XML, so the // serialized string is returned. Consideration is being given // to returning a slice of bytes and encoding information. func (style *Stylesheet) Process(doc *xml.XmlDocument, options StylesheetOptions) (out string, err error) { // lookup output method, doctypes, encoding // create output document with appropriate values output := xml.CreateEmptyDocument(doc.InputEncoding(), doc.OutputEncoding()) // init context node/document context := &ExecutionContext{Output: output.Me, OutputNode: output, Style: style, Source: doc} context.Current = doc context.XPathContext = doc.DocXPathCtx() // when evaluating keys/global vars position is always 1 context.XPathContext.SetContextPosition(1, 1) start := doc style.populateKeys(start, context) // eval global params // eval global variables for _, val := range style.Variables { val.Apply(doc, context) } // set xpath context // process nodes style.processNode(start, context, nil) out, err = style.constructOutput(output, options) // reset anything required for re-use return }